2016-05-06 05:14:39 +08:00
|
|
|
import React from 'react';
|
|
|
|
import Modal from 'react-modal';
|
2016-05-20 21:37:19 +08:00
|
|
|
import Icon from '/imports/ui/components/icon/component';
|
|
|
|
import Button from '/imports/ui/components/button/component';
|
2016-08-25 07:00:38 +08:00
|
|
|
import BaseMenu from '../base/component';
|
2016-05-06 05:14:39 +08:00
|
|
|
import ReactDOM from 'react-dom';
|
2017-01-27 23:41:11 +08:00
|
|
|
import cx from 'classnames';
|
2016-09-01 21:56:41 +08:00
|
|
|
import styles from '../styles.scss';
|
2017-01-27 23:41:11 +08:00
|
|
|
import Toggle from '/imports/ui/components/switch/component';
|
2017-04-11 05:11:48 +08:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
2016-12-14 11:40:32 +08:00
|
|
|
|
2017-02-25 04:19:53 +08:00
|
|
|
const MIN_FONTSIZE = 0;
|
|
|
|
const MAX_FONTSIZE = 4;
|
|
|
|
|
2017-04-11 05:11:48 +08:00
|
|
|
const intlMessages = defineMessages({
|
|
|
|
applicationSectionTitle: {
|
|
|
|
id: 'app.submenu.application.applicationSectionTitle',
|
|
|
|
description: 'Application section title',
|
|
|
|
},
|
|
|
|
audioNotifyLabel: {
|
|
|
|
id: 'app.submenu.application.audioNotifyLabel',
|
2017-04-11 05:21:54 +08:00
|
|
|
description: 'audio notification label',
|
2017-04-11 05:11:48 +08:00
|
|
|
},
|
|
|
|
pushNotifyLabel: {
|
|
|
|
id: 'app.submenu.application.pushNotifyLabel',
|
2017-04-11 05:21:54 +08:00
|
|
|
description: 'push notifiation label',
|
2017-04-11 05:11:48 +08:00
|
|
|
},
|
|
|
|
fontSizeControlLabel: {
|
|
|
|
id: 'app.submenu.application.fontSizeControlLabel',
|
2017-04-11 05:21:54 +08:00
|
|
|
description: 'label for font size ontrol',
|
2017-04-11 05:11:48 +08:00
|
|
|
},
|
|
|
|
increaseFontBtnLabel: {
|
|
|
|
id: 'app.submenu.application.increaseFontBtnLabel',
|
2017-04-11 05:21:54 +08:00
|
|
|
description: 'label for button to increase font size',
|
2017-04-11 05:11:48 +08:00
|
|
|
},
|
|
|
|
increaseFontBtnDesc: {
|
|
|
|
id: 'app.submenu.application.increaseFontBtnDesc',
|
2017-04-11 05:21:54 +08:00
|
|
|
description: 'adds descriptive context to increase font size button',
|
2017-04-11 05:11:48 +08:00
|
|
|
},
|
|
|
|
decreaseFontBtnLabel: {
|
|
|
|
id: 'app.submenu.application.decreaseFontBtnLabel',
|
2017-04-11 05:21:54 +08:00
|
|
|
description: 'label for button to reduce font size',
|
2017-04-11 05:11:48 +08:00
|
|
|
},
|
|
|
|
decreaseFontBtnDesc: {
|
|
|
|
id: 'app.submenu.application.decreaseFontBtnDesc',
|
2017-04-11 05:21:54 +08:00
|
|
|
description: 'adds descriptive context to decrease font size button',
|
2017-04-11 05:11:48 +08:00
|
|
|
},
|
2017-04-22 03:04:46 +08:00
|
|
|
languageLabel: {
|
|
|
|
id: 'app.submenu.application.languageLabel',
|
|
|
|
description: 'displayed label for changing application locale',
|
|
|
|
},
|
|
|
|
ariaLanguageLabel: {
|
|
|
|
id: 'app.submenu.application.ariaLanguageLabel',
|
|
|
|
description: 'aria label for locale change section',
|
|
|
|
},
|
|
|
|
languageOptionLabel: {
|
|
|
|
id: 'app.submenu.application.languageOptionLabel',
|
|
|
|
description: 'default change language option when locales are available',
|
|
|
|
},
|
|
|
|
noLocaleOptionLabel: {
|
|
|
|
id: 'app.submenu.application.noLocaleOptionLabel',
|
|
|
|
description: 'default change language option when no locales available',
|
|
|
|
},
|
2017-04-11 05:11:48 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
class ApplicationMenu extends BaseMenu {
|
2016-05-06 05:14:39 +08:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2017-02-22 04:29:36 +08:00
|
|
|
|
2017-02-25 04:19:53 +08:00
|
|
|
this.state = {
|
|
|
|
settingsName: 'application',
|
|
|
|
settings: props.settings,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
handleUpdateFontSize(size) {
|
|
|
|
let obj = this.state;
|
|
|
|
obj.settings.fontSize = size;
|
|
|
|
this.handleUpdateSettings(this.state.settingsName, obj.settings);
|
|
|
|
}
|
|
|
|
|
|
|
|
setHtmlFontSize(size) {
|
|
|
|
document.getElementsByTagName('html')[0].style.fontSize = size;
|
|
|
|
};
|
|
|
|
|
|
|
|
changeFontSize(size) {
|
|
|
|
let obj = this.state;
|
|
|
|
obj.settings.fontSize = size;
|
|
|
|
this.setState(obj, () => {
|
|
|
|
this.setHtmlFontSize(this.state.settings.fontSize);
|
|
|
|
this.handleUpdateFontSize(this.state.settings.fontSize);
|
|
|
|
});
|
2016-05-06 05:14:39 +08:00
|
|
|
}
|
|
|
|
|
2017-02-25 04:19:53 +08:00
|
|
|
handleIncreaseFontSize() {
|
|
|
|
const currentFontSize = this.state.settings.fontSize;
|
|
|
|
const availableFontSizes = this.props.fontSizes;
|
|
|
|
const canIncreaseFontSize = availableFontSizes.indexOf(currentFontSize) < MAX_FONTSIZE;
|
|
|
|
let fs = (canIncreaseFontSize) ? availableFontSizes.indexOf(currentFontSize) + 1 : MAX_FONTSIZE;
|
|
|
|
this.changeFontSize(availableFontSizes[fs]);
|
|
|
|
};
|
|
|
|
|
|
|
|
handleDecreaseFontSize() {
|
|
|
|
const currentFontSize = this.state.settings.fontSize;
|
|
|
|
const availableFontSizes = this.props.fontSizes;
|
|
|
|
const canDecreaseFontSize = availableFontSizes.indexOf(currentFontSize) > MIN_FONTSIZE;
|
|
|
|
let fs = (canDecreaseFontSize) ? availableFontSizes.indexOf(currentFontSize) - 1 : MIN_FONTSIZE;
|
|
|
|
this.changeFontSize(availableFontSizes[fs]);
|
|
|
|
};
|
|
|
|
|
2017-04-06 20:36:59 +08:00
|
|
|
handleSelectChange(fieldname, options, e) {
|
|
|
|
let obj = this.state;
|
2017-04-19 01:26:27 +08:00
|
|
|
obj.settings[fieldname] = e.target.value.toLowerCase().replace('_', '-');
|
2017-04-06 20:36:59 +08:00
|
|
|
this.handleUpdateSettings('application', obj.settings);
|
|
|
|
}
|
|
|
|
|
2017-01-27 23:41:11 +08:00
|
|
|
render() {
|
2017-04-06 20:36:59 +08:00
|
|
|
const {
|
|
|
|
availableLocales,
|
2017-04-19 03:14:39 +08:00
|
|
|
intl,
|
2017-04-06 20:36:59 +08:00
|
|
|
} = this.props;
|
|
|
|
|
2016-05-06 05:14:39 +08:00
|
|
|
return (
|
2017-01-27 23:41:11 +08:00
|
|
|
<div className={styles.tabContent}>
|
|
|
|
<div className={styles.header}>
|
2017-04-19 03:14:39 +08:00
|
|
|
<h3 className={styles.title}>
|
|
|
|
{intl.formatMessage(intlMessages.applicationSectionTitle)}
|
|
|
|
</h3>
|
2017-01-27 23:41:11 +08:00
|
|
|
</div>
|
|
|
|
<div className={styles.form}>
|
|
|
|
<div className={styles.row}>
|
2017-04-26 22:08:47 +08:00
|
|
|
<div className={styles.col} aria-hidden="true">
|
2017-01-27 23:41:11 +08:00
|
|
|
<div className={styles.formElement}>
|
|
|
|
<label className={styles.label}>
|
2017-04-11 05:11:48 +08:00
|
|
|
{intl.formatMessage(intlMessages.audioNotifyLabel)}
|
2017-01-27 23:41:11 +08:00
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className={styles.col}>
|
2017-04-25 10:27:28 +08:00
|
|
|
<div className={cx(styles.formElement, styles.pullContentRight)}>
|
2017-04-26 22:08:47 +08:00
|
|
|
<Toggle
|
|
|
|
icons={false}
|
|
|
|
defaultChecked={this.state.settings.chatAudioNotifications}
|
|
|
|
onChange={() => this.handleToggle('chatAudioNotifications')}
|
|
|
|
ariaLabelledBy={'audioNotify'}
|
|
|
|
ariaLabel={intl.formatMessage(intlMessages.audioNotifyLabel)} />
|
2017-01-27 23:41:11 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
2016-06-07 03:52:03 +08:00
|
|
|
</div>
|
2017-01-27 23:41:11 +08:00
|
|
|
<div className={styles.row}>
|
|
|
|
<div className={styles.col}>
|
2017-04-22 03:04:46 +08:00
|
|
|
<div className={styles.formElement} >
|
2017-01-27 23:41:11 +08:00
|
|
|
<label className={styles.label}>
|
2017-04-11 05:11:48 +08:00
|
|
|
{intl.formatMessage(intlMessages.pushNotifyLabel)}
|
2017-01-27 23:41:11 +08:00
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className={styles.col}>
|
2017-04-25 10:27:28 +08:00
|
|
|
<div className={cx(styles.formElement, styles.pullContentRight)}>
|
2017-04-26 22:08:47 +08:00
|
|
|
<Toggle
|
|
|
|
icons={false}
|
|
|
|
defaultChecked={this.state.settings.chatPushNotifications}
|
|
|
|
onChange={() => this.handleToggle('chatPushNotifications')}
|
|
|
|
ariaLabelledBy={'pushNotify'}
|
|
|
|
ariaLabel={intl.formatMessage(intlMessages.pushNotifyLabel)}/>
|
2017-01-27 23:41:11 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
2016-06-07 03:52:03 +08:00
|
|
|
</div>
|
2017-04-06 20:36:59 +08:00
|
|
|
<div className={styles.row}>
|
|
|
|
<div className={styles.col}>
|
|
|
|
<div className={styles.formElement}>
|
|
|
|
<label className={styles.label}>
|
2017-04-22 03:04:46 +08:00
|
|
|
{intl.formatMessage(intlMessages.languageLabel)}
|
2017-04-06 20:36:59 +08:00
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className={styles.col}>
|
2017-04-22 03:04:46 +08:00
|
|
|
<div className={cx(styles.formElement, styles.pullContentRight)}
|
|
|
|
aria-labelledby="changeLangLabel">
|
2017-04-06 20:36:59 +08:00
|
|
|
<select
|
|
|
|
defaultValue={this.state.settings.locale}
|
|
|
|
className={styles.select}
|
|
|
|
onChange={this.handleSelectChange.bind(this, 'locale', availableLocales)}>
|
|
|
|
<option>
|
|
|
|
{ availableLocales &&
|
|
|
|
availableLocales.length ?
|
2017-04-22 03:04:46 +08:00
|
|
|
intl.formatMessage(intlMessages.languageOptionLabel) :
|
|
|
|
intl.formatMessage(intlMessages.noLocaleOptionLabel) }
|
2017-04-06 20:36:59 +08:00
|
|
|
</option>
|
|
|
|
{availableLocales ? availableLocales.map((locale, index) =>
|
|
|
|
<option key={index} value={locale.locale}>
|
|
|
|
{locale.name}
|
|
|
|
</option>
|
|
|
|
) : null }
|
|
|
|
</select>
|
|
|
|
</div>
|
2017-04-22 03:04:46 +08:00
|
|
|
<div id="changeLangLabel" aria-label={intl.formatMessage(intlMessages.ariaLanguageLabel)}></div>
|
2017-04-06 20:36:59 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
2017-01-27 23:41:11 +08:00
|
|
|
<hr className={styles.separator}/>
|
|
|
|
<div className={styles.row}>
|
|
|
|
<div className={styles.col}>
|
|
|
|
<div className={styles.formElement}>
|
|
|
|
<label className={styles.label}>
|
2017-04-11 05:11:48 +08:00
|
|
|
{intl.formatMessage(intlMessages.fontSizeControlLabel)}
|
2017-01-27 23:41:11 +08:00
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className={styles.col}>
|
|
|
|
<div className={cx(styles.formElement, styles.pullContentCenter)}>
|
|
|
|
<label className={cx(styles.label, styles.bold)}>
|
2017-03-02 01:37:55 +08:00
|
|
|
{this.state.settings.fontSize}
|
2017-01-27 23:41:11 +08:00
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className={styles.col}>
|
|
|
|
<div className={cx(styles.formElement, styles.pullContentRight)}>
|
2017-03-09 22:34:33 +08:00
|
|
|
<div className={styles.pullContentRight}>
|
|
|
|
<div className={styles.col}>
|
|
|
|
<Button
|
|
|
|
onClick={() => this.handleIncreaseFontSize()}
|
|
|
|
color={'success'}
|
2017-03-10 00:49:28 +08:00
|
|
|
icon={'add'}
|
2017-03-09 22:34:33 +08:00
|
|
|
circle={true}
|
|
|
|
hideLabel={true}
|
2017-04-11 05:11:48 +08:00
|
|
|
label={intl.formatMessage(intlMessages.increaseFontBtnLabel)}
|
2017-03-09 22:34:33 +08:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className={styles.col}>
|
|
|
|
<Button
|
|
|
|
onClick={() => this.handleDecreaseFontSize()}
|
|
|
|
color={'success'}
|
2017-03-10 00:49:28 +08:00
|
|
|
icon={'substract'}
|
2017-03-09 22:34:33 +08:00
|
|
|
circle={true}
|
|
|
|
hideLabel={true}
|
2017-04-11 05:11:48 +08:00
|
|
|
label={intl.formatMessage(intlMessages.decreaseFontBtnLabel)}
|
2017-03-09 22:34:33 +08:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
2017-01-27 23:41:11 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
2016-05-06 05:14:39 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
2017-04-11 05:11:48 +08:00
|
|
|
|
|
|
|
export default injectIntl(ApplicationMenu);
|