// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. // See License.txt for license information. import * as Utils from '../../utils/utils.jsx'; import * as Client from '../../utils/client.jsx'; import {injectIntl, intlShape, defineMessages, FormattedMessage, FormattedHTMLMessage} from 'mm-intl'; const holders = defineMessages({ removing: { id: 'admin.license.removing', defaultMessage: 'Removing License...' }, uploading: { id: 'admin.license.uploading', defaultMessage: 'Uploading License...' } }); class LicenseSettings extends React.Component { constructor(props) { super(props); this.handleChange = this.handleChange.bind(this); this.handleSubmit = this.handleSubmit.bind(this); this.handleRemove = this.handleRemove.bind(this); this.state = { fileSelected: false, serverError: null }; } handleChange() { const element = $(ReactDOM.findDOMNode(this.refs.fileInput)); if (element.prop('files').length > 0) { this.setState({fileSelected: true}); } } handleSubmit(e) { e.preventDefault(); const element = $(ReactDOM.findDOMNode(this.refs.fileInput)); if (element.prop('files').length === 0) { return; } const file = element.prop('files')[0]; $('#upload-button').button('loading'); const formData = new FormData(); formData.append('license', file, file.name); Client.uploadLicenseFile(formData, () => { Utils.clearFileInput(element[0]); $('#upload-button').button('reset'); this.setState({serverError: null}); window.location.reload(true); }, (error) => { Utils.clearFileInput(element[0]); $('#upload-button').button('reset'); this.setState({serverError: error.message}); } ); } handleRemove(e) { e.preventDefault(); $('#remove-button').button('loading'); Client.removeLicenseFile( () => { $('#remove-button').button('reset'); this.setState({serverError: null}); window.location.reload(true); }, (error) => { $('#remove-button').button('reset'); this.setState({serverError: error.message}); } ); } render() { var serverError = ''; if (this.state.serverError) { serverError =
; } var btnClass = 'btn'; if (this.state.fileSelected) { btnClass = 'btn btn-primary'; } let edition; let licenseType; let licenseKey; if (global.window.mm_license.IsLicensed === 'true') { edition = ( ); licenseType = ( ); licenseKey = (


); } else { edition = ( ); licenseType = ( ); licenseKey = (



{serverError}

); } return (

{edition}
{licenseType}
{licenseKey}
); } } LicenseSettings.propTypes = { intl: intlShape.isRequired, config: React.PropTypes.object }; export default injectIntl(LicenseSettings);