// 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'; import * as Utils from '../../utils/utils.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'}); const selectedFont = PreferenceStore.getPreference(Constants.Preferences.CATEGORY_DISPLAY_SETTINGS, 'selected_font', {value: Constants.DEFAULT_FONT}); return { militaryTime: militaryTime.value, nameFormat: nameFormat.value, selectedFont: selectedFont.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.handleFont = this.handleFont.bind(this); this.updateSection = this.updateSection.bind(this); this.state = getDisplayStateFromStores(); this.selectedFont = this.state.selectedFont; } 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); const fontPreference = PreferenceStore.setPreference(Constants.Preferences.CATEGORY_DISPLAY_SETTINGS, 'selected_font', this.state.selectedFont); this.selectedFont = this.state.selectedFont; savePreferences([timePreference, namePreference, fontPreference], () => { PreferenceStore.emitChange(); this.updateSection(''); }, (err) => { this.setState({serverError: err.message}); } ); } handleClockRadio(militaryTime) { this.setState({militaryTime}); } handleNameRadio(nameFormat) { this.setState({nameFormat}); } handleFont(selectedFont) { Utils.applyFont(selectedFont); this.setState({selectedFont}); } updateSection(section) { this.setState(getDisplayStateFromStores()); this.props.updateSection(section); } render() { const serverError = this.state.serverError || null; let clockSection; let nameFormatSection; let fontSection; 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 = [



{'Select how you prefer time displayed.'}
]; clockSection = ( ); } else { let describe = ''; if (this.state.militaryTime === 'true') { describe = '24-hour clock (example: 16:00)'; } else { describe = '12-hour clock (example: 4:00 PM)'; } const handleUpdateClockSection = () => { this.props.updateSection('clock'); }; clockSection = ( ); } if (this.props.activeSection === 'name_format') { const nameFormat = [false, false, false]; if (this.state.nameFormat === 'nickname_full_name') { nameFormat[0] = true; } else if (this.state.nameFormat === 'full_name') { nameFormat[2] = true; } else { nameFormat[1] = true; } const inputs = [




{'Set what name to display in the Direct Messages list.'}
]; nameFormatSection = ( { this.updateSection(''); e.preventDefault(); }} /> ); } else { let describe = ''; if (this.state.nameFormat === 'username') { describe = 'Show username'; } else if (this.state.nameFormat === 'full_name') { describe = 'Show first and last name'; } else { describe = 'Show nickname if one exists, otherwise show first and last name (team default)'; } nameFormatSection = ( { this.props.updateSection('name_format'); }} /> ); } if (this.props.activeSection === 'font') { const options = []; Object.keys(Constants.FONTS).forEach((fontName, idx) => { const className = Constants.FONTS[fontName]; options.push( ); }); const inputs = [

{'Select the font displayed in the Mattermost user interface.'}
]; fontSection = ( { if (this.selectedFont !== this.state.selectedFont) { this.handleFont(this.selectedFont); } this.updateSection(''); e.preventDefault(); }} /> ); } else { fontSection = ( { this.props.updateSection('font'); }} /> ); } return (

{'Display Settings'}

{'Display Settings'}

{fontSection}
{clockSection}
{nameFormatSection}
); } } UserSettingsDisplay.propTypes = { user: React.PropTypes.object, updateSection: React.PropTypes.func, updateTab: React.PropTypes.func, activeSection: React.PropTypes.string, closeModal: React.PropTypes.func.isRequired, collapseModal: React.PropTypes.func.isRequired };