blob: 67a150b9d374b062c51e2376c10a4cbcee6431b1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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>
);
}
});
|