// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. // See License.txt for license information. var Client = require('../utils/client.jsx'); export default class RegisterAppModal extends React.Component { constructor() { super(); this.register = this.register.bind(this); this.onHide = this.onHide.bind(this); this.save = this.save.bind(this); this.state = {clientId: '', clientSecret: '', saved: false}; } componentDidMount() { $(React.findDOMNode(this)).on('hide.bs.modal', this.onHide); } register() { var state = this.state; state.serverError = null; var app = {}; var name = this.refs.name.getDOMNode().value; if (!name || name.length === 0) { state.nameError = 'Application name must be filled in.'; this.setState(state); return; } state.nameError = null; app.name = name; var homepage = this.refs.homepage.getDOMNode().value; if (!homepage || homepage.length === 0) { state.homepageError = 'Homepage must be filled in.'; this.setState(state); return; } state.homepageError = null; app.homepage = homepage; var desc = this.refs.desc.getDOMNode().value; app.description = desc; var rawCallbacks = this.refs.callback.getDOMNode().value.trim(); if (!rawCallbacks || rawCallbacks.length === 0) { state.callbackError = 'At least one callback URL must be filled in.'; this.setState(state); return; } state.callbackError = null; app.callback_urls = rawCallbacks.split('\n'); Client.registerOAuthApp(app, (data) => { state.clientId = data.id; state.clientSecret = data.client_secret; this.setState(state); }, (err) => { state.serverError = err.message; this.setState(state); } ); } onHide(e) { if (!this.state.saved && this.state.clientId !== '') { e.preventDefault(); return; } this.setState({clientId: '', clientSecret: '', saved: false}); } save() { this.setState({saved: this.refs.save.getDOMNode().checked}); } render() { var nameError; if (this.state.nameError) { nameError =
; } var homepageError; if (this.state.homepageError) { homepageError = ; } var callbackError; if (this.state.callbackError) { callbackError = ; } var serverError; if (this.state.serverError) { serverError = ; } var body = ''; if (this.state.clientId === '') { body = (