diff options
author | =Corey Hulen <corey@hulen.com> | 2015-06-14 23:53:32 -0800 |
---|---|---|
committer | =Corey Hulen <corey@hulen.com> | 2015-06-14 23:53:32 -0800 |
commit | cf7a05f80f68b5b1c8bcc0089679dd497cec2506 (patch) | |
tree | 70007378570a6962d7c175ca96af732b71aeb6da /web/react/components/rename_team_modal.jsx | |
download | chat-cf7a05f80f68b5b1c8bcc0089679dd497cec2506.tar.gz chat-cf7a05f80f68b5b1c8bcc0089679dd497cec2506.tar.bz2 chat-cf7a05f80f68b5b1c8bcc0089679dd497cec2506.zip |
first commit
Diffstat (limited to 'web/react/components/rename_team_modal.jsx')
-rw-r--r-- | web/react/components/rename_team_modal.jsx | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/web/react/components/rename_team_modal.jsx b/web/react/components/rename_team_modal.jsx new file mode 100644 index 000000000..67a150b9d --- /dev/null +++ b/web/react/components/rename_team_modal.jsx @@ -0,0 +1,92 @@ +// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved. +// See License.txt for license information. + +var Client = require('../utils/client.jsx'); +var utils = require('../utils/utils.jsx'); + +module.exports = React.createClass({ + handleSubmit: function(e) { + e.preventDefault(); + + var state = { server_error: "" }; + var valid = true; + + var name = this.state.name.trim(); + if (!name) { + state.name_error = "This field is required"; + valid = false; + } else { + state.name_error = ""; + } + + this.setState(state); + + if (!valid) + return; + + if (this.props.teamName === name) + return; + + var data = {}; + data["new_name"] = name; + + Client.updateTeamName(data, + function(data) { + $('#rename_team_link').modal('hide'); + window.location.reload(); + }.bind(this), + function(err) { + state.server_error = err.message; + this.setState(state); + }.bind(this) + ); + }, + onNameChange: function() { + this.setState({ name: this.refs.name.getDOMNode().value }) + }, + componentDidMount: function() { + var self = this; + $(this.refs.modal.getDOMNode()).on('hidden.bs.modal', function(e) { + self.setState({ name: self.props.teamName }); + }); + }, + getInitialState: function() { + return { name: this.props.teamName }; + }, + render: function() { + + var name_error = this.state.name_error ? <label className='control-label'>{ this.state.name_error }</label> : null; + var server_error = this.state.server_error ? <div className='form-group has-error'><label className='control-label'>{ this.state.server_error }</label></div> : null; + + return ( + <div className="modal fade" ref="modal" id="rename_team_link" tabIndex="-1" role="dialog" aria-hidden="true"> + <div className="modal-dialog"> + <div className="modal-content"> + <div className="modal-header"> + <button type="button" className="close" data-dismiss="modal"> + <span aria-hidden="true">×</span> + <span className="sr-only">Close</span> + </button> + <h4 className="modal-title">{"Rename " + utils.toTitleCase(strings.Team)}</h4> + </div> + <div className="modal-body"> + <form role="form" onSubmit={this.handleSubmit}> + <div className={ this.state.name_error ? "form-group has-error" : "form-group" }> + <label className='control-label'>Name</label> + <input onChange={this.onNameChange} type="text" ref="name" className="form-control" placeholder={"Enter "+strings.Team+" name"} value={this.state.name} maxLength="64" /> + { name_error } + </div> + { server_error } + </form> + </div> + <div className="modal-footer"> + <button type="button" className="btn btn-default" data-dismiss="modal">Close</button> + <button onClick={this.handleSubmit} type="button" className="btn btn-primary">Save</button> + </div> + </div> + </div> + </div> + ); + } +}); + |