// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. // See License.txt for license information. import {savePreferences} from '../../utils/client.jsx'; import SettingItemMin from '../setting_item_min.jsx'; import SettingItemMax from '../setting_item_max.jsx'; import Constants from '../../utils/constants.jsx'; import PreferenceStore from '../../stores/preference_store.jsx'; function getDisplayStateFromStores() { const militaryTime = PreferenceStore.getPreference(Constants.Preferences.CATEGORY_DISPLAY_SETTINGS, 'use_military_time', {value: 'false'}); const nameFormat = PreferenceStore.getPreference(Constants.Preferences.CATEGORY_DISPLAY_SETTINGS, 'name_format', {value: 'username'}); return { militaryTime: militaryTime.value, nameFormat: nameFormat.value }; } export default class UserSettingsDisplay extends React.Component { constructor(props) { super(props); this.handleSubmit = this.handleSubmit.bind(this); this.handleClockRadio = this.handleClockRadio.bind(this); this.handleNameRadio = this.handleNameRadio.bind(this); this.updateSection = this.updateSection.bind(this); this.state = getDisplayStateFromStores(); } handleSubmit() { const timePreference = PreferenceStore.setPreference(Constants.Preferences.CATEGORY_DISPLAY_SETTINGS, 'use_military_time', this.state.militaryTime); const namePreference = PreferenceStore.setPreference(Constants.Preferences.CATEGORY_DISPLAY_SETTINGS, 'name_format', this.state.nameFormat); savePreferences([timePreference, namePreference], () => { PreferenceStore.emitChange(); this.updateSection(''); }, (err) => { this.setState({serverError: err.message}); } ); } handleClockRadio(militaryTime) { this.setState({militaryTime}); } handleNameRadio(nameFormat) { this.setState({nameFormat}); } updateSection(section) { this.setState(getDisplayStateFromStores()); this.props.updateSection(section); } render() { const serverError = this.state.serverError || null; let clockSection; let nameFormatSection; if (this.props.activeSection === 'clock') { const clockFormat = [false, false]; if (this.state.militaryTime === 'true') { clockFormat[1] = true; } else { clockFormat[0] = true; } const handleUpdateClockSection = (e) => { this.updateSection(''); e.preventDefault(); }; const inputs = [