/* * 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 . */ const {Component, PropTypes} = require('react') const {Toggle, Subheader, MenuItem, SelectField, TextField, TimePicker} = require('material-ui') class EmailPanel extends Component{ onChange(partialValues){ const {values, onChange} = this.props; onChange({...values, ...partialValues}, true); } onFrequencyChange(value){ let partial = {NOTIFICATIONS_EMAIL_FREQUENCY:value}; let newUserValue; switch(value){ case 'M': newUserValue = '5' break; case 'H': newUserValue = '2' break; case 'D1': newUserValue = '03' break; case 'D2': newUserValue = '09,14' break; case 'W1': newUserValue = 'Monday' break; } partial.NOTIFICATIONS_EMAIL_FREQUENCY_USER = newUserValue; this.onChange(partial); } onPickDate(position, event, date){ const {NOTIFICATIONS_EMAIL_FREQUENCY_USER} = this.props.values; const hours = NOTIFICATIONS_EMAIL_FREQUENCY_USER.split(','); let newHours = []; if(position === 'first') newHours = [date.getHours(), hours[1] ? hours[1] : '00']; if(position === 'last') newHours = [hours[0] ? hours[0] : '00', date.getHours()]; this.onChange({NOTIFICATIONS_EMAIL_FREQUENCY_USER:newHours.join(',')}); } render(){ const {definitions, values, pydio} = this.props; const message = (id) => {return pydio.MessageHash['user_dash.' + id]}; const {NOTIFICATIONS_EMAIL_GET, NOTIFICATIONS_EMAIL_FREQUENCY, NOTIFICATIONS_EMAIL_FREQUENCY_USER, NOTIFICATIONS_EMAIL, NOTIFICATIONS_EMAIL_SEND_HTML} = values; const mailActive = (NOTIFICATIONS_EMAIL_GET === 'true'); let frequencyTypes = new Map(); let frequencyMenus = []; definitions[1]['choices'].split(',').map((e)=>{ const d = e.split('|'); frequencyTypes.set(d[0], d[1]); frequencyMenus.push(); }); let userFrequencyComponent; if(mailActive){ switch (NOTIFICATIONS_EMAIL_FREQUENCY){ case 'M': case 'H': userFrequencyComponent = ( {this.onChange({NOTIFICATIONS_EMAIL_FREQUENCY_USER:v})}} /> ); break; case 'D1': let d = new Date(); d.setHours(NOTIFICATIONS_EMAIL_FREQUENCY_USER);d.setMinutes(0); userFrequencyComponent = ( {this.onChange({NOTIFICATIONS_EMAIL_FREQUENCY_USER:date.getHours()})}} autoOk={true} textFieldStyle={{width: '100%'}} /> ) break; case 'D2': let hours = NOTIFICATIONS_EMAIL_FREQUENCY_USER + ''; if(!hours) hours = '09,14'; hours = hours.split(','); let d1 = new Date(); let d2 = new Date(); d2.setMinutes(0); d1.setHours(hours[0]); d1.setMinutes(0); if(hours[1]){ d2.setHours(hours[1]); } userFrequencyComponent = (
) break; case 'W1': userFrequencyComponent = ( {this.onChange({NOTIFICATIONS_EMAIL_FREQUENCY_USER: v})}} > ) break; } } return (
{message(61)}
{this.onChange({NOTIFICATIONS_EMAIL_GET:v?'true':'false'})}} /> {mailActive &&
{this.onChange({NOTIFICATIONS_EMAIL_SEND_HTML:v?'true':'false'})}} />
{this.onFrequencyChange(p)}} >{frequencyMenus} {userFrequencyComponent}
}
); } } EmailPanel.propTypes = { definitions:PropTypes.object, values: PropTypes.object, onChange: PropTypes.func } export {EmailPanel as default}