/* * Copyright 2007-2017 Charles du Jeu - Abstrium SAS * This file is part of Pydio. * * Pydio is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Pydio is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with Pydio. If not, see . * * The latest code can be found at . */ (function(global){ const styles = { chip: { marginRight: 4, marginBottom: 4 }, wrapper: { display: 'flex', flexWrap: 'wrap', }, overlay:{ position: 'absolute', top: 0, right: 0, left: 0, bottom: 0, backgroundColor: 'rgba(0, 0, 0, 0.33)', paddingTop: 77, zIndex: 100 } }; var DestBadge = React.createClass({ propTypes:{ user:React.PropTypes.instanceOf(PydioUsers.User) }, render: function(){ const userObject = this.props.user; return (
{userObject.getExtendedLabel() || userObject.getLabel()}
); } }); var UserEntry = React.createClass({ propTypes:{ user:React.PropTypes.instanceOf(PydioUsers.User), onRemove:React.PropTypes.func }, remove: function(){ this.props.onRemove(this.props.user.getId()); }, toggleRemove:function(){ var current = this.state && this.state.remove; this.setState({remove:!current}); }, render:function(){ var icon, className = 'pydio-mailer-user ' + 'user-type-' + (this.props.user.getTemporary() ? "email" : "user"); var clik = function(){}; if(this.state && this.state.remove){ clik = this.remove; icon = ; className += ' remove'; }else{ icon = ; } return (
{icon} {this.props.user.getLabel()}
); } }); var UserChip = React.createClass({ propTypes:{ user:React.PropTypes.instanceOf(PydioUsers.User), onRemove:React.PropTypes.func }, remove: function(){ this.props.onRemove(this.props.user.getId()); }, render: function(){ const tmp = this.props.user.getTemporary(); const icon = ; const {colors} = MaterialUI.Style; return ( {this.props.user.getLabel()} ) } }); class Email { constructor(subject = null, message = null, link = null){ this._subjects = []; this._messages = []; this._targets = []; this._links = []; if(subject) this._subjects.push(subject); if(message) this._messages.push(message); if(link) this._links.push(link); } addTarget(userOrEmail, subject = null, message = null, link = null){ this._targets.push(userOrEmail); if(subject) this._subjects.push(subject); if(message) this._messages.push(message); if(link) this._links.push(link); } post(callback = null){ if(!this._subjects.length || !this._targets.length || !this._messages.length){ throw new Error('Invalid data'); } let params = { get_action : "send_mail", 'emails[]' : this._targets } if(this._messages.length === 1){ params['message'] = this._messages[0]; }else{ params['messages[]'] = this._messages; } if(this._subjects.length === 1){ params['subject'] = this._subjects[0]; }else{ params['subjects[]'] = this._subjects; } if(this._links.length === 1){ params['link'] = this._links; }else if(this._links.length > 1){ params['links[]'] = this._links; } const client = PydioApi.getClient(); client.request(params, function(transport){ const res = client.parseXmlMessage(transport.responseXML); callback(res); }.bind(this)); } } const Mailer = React.createClass({ propTypes:{ message:React.PropTypes.string.isRequired, subject:React.PropTypes.string.isRequired, link:React.PropTypes.string, onDismiss:React.PropTypes.func, className:React.PropTypes.string, overlay:React.PropTypes.bool, uniqueUserStyle:React.PropTypes.bool, users:React.PropTypes.object, panelTitle:React.PropTypes.string, zDepth:React.PropTypes.number, showAddressBook: React.PropTypes.bool, processPost: React.PropTypes.func, additionalPaneTop: React.PropTypes.instanceOf(React.Component), additionalPaneBottom: React.PropTypes.instanceOf(React.Component) }, getInitialState: function(){ return { users:this.props.users || {}, subject:this.props.subject, message:this.props.message, errorMessage:null }; }, getDefaultProps: function(){ return {showAddressBook: true}; }, updateSubject: function(event){ this.setState({subject:event.currentTarget.value}); }, updateMessage: function(event){ this.setState({message:event.currentTarget.value}); }, addUser: function(userObject){ var users = this.state.users; users[userObject.getId()] = userObject; this.setState({users:users, errorMessage:null}); }, removeUser: function(userId){ delete this.state.users[userId]; this.setState({users:this.state.users}); }, getMessage: function(messageId, nameSpace = undefined){ try{ if(nameSpace === undefined) nameSpace = 'core.mailer'; if(nameSpace) nameSpace += "."; return global.pydio.MessageHash[ nameSpace + messageId ]; }catch(e){ return messageId; } }, postEmail : function(repost=false){ const {users, subject, message} = this.state; if(!repost && this.refs.completer && this.refs.completer.getPendingSearchText && this.refs.completer.getPendingSearchText()){ this.refs.completer.onCompleterRequest(this.refs.completer.getPendingSearchText(), -1); setTimeout(() => this.postEmail(true), 500); return; } if(!Object.keys(users).length){ this.setState({errorMessage:this.getMessage(2)}); return; } const {link} = this.props; const callback = (res) => { if(res) this.props.onDismiss(); }; if(this.props.processPost){ this.props.processPost(Email, users, subject, message, link, callback); return; } let email = new Email(subject, message, link || null); Object.keys(users).forEach((k) => { email.addTarget(k); }) email.post(callback); }, usersLoaderRenderSuggestion(userObject){ return ; }, render: function(){ const className = [this.props.className, "react-mailer", "reset-pydio-forms"].join(" "); const users = Object.keys(this.state.users).map(function(uId){ return ( ); }.bind(this)); let errorDiv; if(this.state.errorMessage){ errorDiv =
{this.state.errorMessage}
} let style = this.props.style || {}; style = { ...style, margin:this.props.uniqueUserStyle ? 0 : 8 } const content = (

{this.props.panelTitle}

{errorDiv} {this.props.additionalPaneTop} {!this.props.uniqueUserStyle &&
{users}
} {!this.props.uniqueUserStyle && }
{this.props.additionalPaneBottom}
this.postEmail()}/>
); if(this.props.overlay){ return (
{content}
); }else{ return content; } } }); const Preferences = React.createClass({ render: function(){ return
Preferences Panel
; } }); let PydioMailer = global.PydioMailer || {}; PydioMailer.Pane = Mailer; PydioMailer.PreferencesPanel = Preferences; global.PydioMailer = PydioMailer; })(window);