// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. // See License.txt for license information. const Client = require('../../utils/client.jsx'); const SettingItemMin = require('../setting_item_min.jsx'); const SettingItemMax = require('../setting_item_max.jsx'); const Constants = require('../../utils/constants.jsx'); const PreferenceStore = require('../../stores/preference_store.jsx'); export default class AdvancedSettingsDisplay extends React.Component { constructor(props) { super(props); this.updateSection = this.updateSection.bind(this); this.updateSetting = this.updateSetting.bind(this); this.handleClose = this.handleClose.bind(this); this.setupInitialState = this.setupInitialState.bind(this); this.state = this.setupInitialState(); } setupInitialState() { const sendOnCtrlEnter = PreferenceStore.getPreference( Constants.Preferences.CATEGORY_ADVANCED_SETTINGS, 'send_on_ctrl_enter', {value: 'false'} ).value; return { settings: {send_on_ctrl_enter: sendOnCtrlEnter} }; } updateSetting(setting, value) { const settings = this.state.settings; settings[setting] = value; this.setState(settings); } handleSubmit(setting) { const preference = PreferenceStore.setPreference( Constants.Preferences.CATEGORY_ADVANCED_SETTINGS, setting, this.state.settings[setting] ); Client.savePreferences([preference], () => { PreferenceStore.emitChange(); this.updateSection(''); }, (err) => { this.setState({serverError: err.message}); } ); } updateSection(section) { this.props.updateSection(section); } handleClose() { this.updateSection(''); } componentDidMount() { $('#user_settings').on('hidden.bs.modal', this.handleClose); } componentWillUnmount() { $('#user_settings').off('hidden.bs.modal', this.handleClose); } render() { const serverError = this.state.serverError || null; let ctrlSendSection; if (this.props.activeSection === 'advancedCtrlSend') { const ctrlSendActive = [ this.state.settings.send_on_ctrl_enter === 'true', this.state.settings.send_on_ctrl_enter === 'false' ]; const inputs = [