// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. // See License.txt for license information. import * as Client from '../../utils/client.jsx'; import * as AsyncClient from '../../utils/async_client.jsx'; import {injectIntl, intlShape, defineMessages, FormattedMessage} from 'mm-intl'; const holders = defineMessages({ locationPlaceholder: { id: 'admin.log.locationPlaceholder', defaultMessage: 'Enter your file location' }, formatPlaceholder: { id: 'admin.log.formatPlaceholder', defaultMessage: 'Enter your file format' }, saving: { id: 'admin.log.saving', defaultMessage: 'Saving Config...' } }); class LogSettings extends React.Component { constructor(props) { super(props); this.handleChange = this.handleChange.bind(this); this.handleSubmit = this.handleSubmit.bind(this); this.state = { consoleEnable: this.props.config.LogSettings.EnableConsole, fileEnable: this.props.config.LogSettings.EnableFile, saveNeeded: false, serverError: null }; } handleChange(action) { var s = {saveNeeded: true, serverError: this.state.serverError}; if (action === 'console_true') { s.consoleEnable = true; } if (action === 'console_false') { s.consoleEnable = false; } if (action === 'file_true') { s.fileEnable = true; } if (action === 'file_false') { s.fileEnable = false; } this.setState(s); } handleSubmit(e) { e.preventDefault(); $('#save-button').button('loading'); var config = this.props.config; config.LogSettings.EnableConsole = ReactDOM.findDOMNode(this.refs.consoleEnable).checked; config.LogSettings.ConsoleLevel = ReactDOM.findDOMNode(this.refs.consoleLevel).value; config.LogSettings.EnableFile = ReactDOM.findDOMNode(this.refs.fileEnable).checked; config.LogSettings.FileLevel = ReactDOM.findDOMNode(this.refs.fileLevel).value; config.LogSettings.FileLocation = ReactDOM.findDOMNode(this.refs.fileLocation).value.trim(); config.LogSettings.FileFormat = ReactDOM.findDOMNode(this.refs.fileFormat).value.trim(); Client.saveConfig( config, () => { AsyncClient.getConfig(); this.setState({ consoleEnable: config.LogSettings.EnableConsole, fileEnable: config.LogSettings.EnableFile, serverError: null, saveNeeded: false }); $('#save-button').button('reset'); }, (err) => { this.setState({ consoleEnable: config.LogSettings.EnableConsole, fileEnable: config.LogSettings.EnableFile, serverError: err.message, saveNeeded: true }); $('#save-button').button('reset'); } ); } render() { const {formatMessage} = this.props.intl; var serverError = ''; if (this.state.serverError) { serverError =
; } var saveClass = 'btn'; if (this.state.saveNeeded) { saveClass = 'btn btn-primary'; } return (