2019-12-08 22:43:49 +01:00
|
|
|
/*** @jsx React.DOM */
|
|
|
|
|
|
|
|
var valid_versions = Object.keys(window.versions);
|
|
|
|
var pagenav = new History(valid_versions);
|
|
|
|
|
2022-10-08 20:37:38 +02:00
|
|
|
var settings_view = createReactClass({
|
2019-12-08 22:43:49 +01:00
|
|
|
|
|
|
|
getInitialState: function(props) {
|
|
|
|
var profiles = Object.keys(window.player);
|
|
|
|
var version = pagenav.getInitialState(profiles[profiles.length - 1]);
|
|
|
|
return {
|
|
|
|
player: window.player,
|
|
|
|
profiles: profiles,
|
|
|
|
version: version,
|
|
|
|
new_name: window.player[version].name,
|
|
|
|
editing_name: false,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
componentDidMount: function() {
|
|
|
|
pagenav.onChange(function(version) {
|
|
|
|
this.setState({version: version});
|
|
|
|
}.bind(this));
|
|
|
|
},
|
|
|
|
|
2020-05-08 22:07:55 +02:00
|
|
|
componentDidUpdate: function() {
|
|
|
|
if (this.focus_element && this.focus_element != this.already_focused) {
|
|
|
|
this.focus_element.focus();
|
|
|
|
this.already_focused = this.focus_element;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-12-08 22:43:49 +01:00
|
|
|
saveName: function(event) {
|
|
|
|
AJAX.post(
|
|
|
|
Link.get('updatename'),
|
|
|
|
{
|
|
|
|
version: this.state.version,
|
|
|
|
name: this.state.new_name,
|
|
|
|
},
|
|
|
|
function(response) {
|
|
|
|
var player = this.state.player;
|
|
|
|
player[response.version].name = response.name;
|
|
|
|
this.setState({
|
|
|
|
player: player,
|
|
|
|
new_name: this.state.player[response.version].name,
|
|
|
|
editing_name: false,
|
|
|
|
});
|
|
|
|
}.bind(this)
|
|
|
|
);
|
|
|
|
event.preventDefault();
|
|
|
|
},
|
|
|
|
|
|
|
|
renderName: function(player) {
|
|
|
|
return (
|
|
|
|
<LabelledSection vertical={true} label="Name">{
|
|
|
|
!this.state.editing_name ?
|
2022-10-09 00:13:20 +02:00
|
|
|
<>
|
2019-12-08 22:43:49 +01:00
|
|
|
<span>{player.name}</span>
|
|
|
|
<Edit
|
|
|
|
onClick={function(event) {
|
|
|
|
this.setState({editing_name: true});
|
|
|
|
}.bind(this)}
|
|
|
|
/>
|
2022-10-09 00:13:20 +02:00
|
|
|
</> :
|
2019-12-08 22:43:49 +01:00
|
|
|
<form className="inline" onSubmit={this.saveName}>
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
className="inline"
|
|
|
|
maxlength="8"
|
2020-05-08 22:07:55 +02:00
|
|
|
autofocus="true"
|
|
|
|
ref={c => (this.focus_element = c)}
|
2019-12-08 22:43:49 +01:00
|
|
|
size="16"
|
|
|
|
value={this.state.new_name}
|
|
|
|
onChange={function(event) {
|
|
|
|
var value = event.target.value.toUpperCase();
|
|
|
|
var nameRegex = new RegExp(
|
|
|
|
"^[" +
|
|
|
|
"0-9" +
|
|
|
|
"A-Z" +
|
|
|
|
"!?#$&*-. " +
|
|
|
|
"]*$"
|
|
|
|
);
|
|
|
|
if (value.length <= 8 && nameRegex.test(value)) {
|
|
|
|
this.setState({new_name: value});
|
|
|
|
}
|
|
|
|
}.bind(this)}
|
|
|
|
name="name"
|
|
|
|
/>
|
|
|
|
<input
|
|
|
|
type="submit"
|
|
|
|
value="save"
|
|
|
|
/>
|
|
|
|
<input
|
|
|
|
type="button"
|
|
|
|
value="cancel"
|
|
|
|
onClick={function(event) {
|
|
|
|
this.setState({
|
|
|
|
new_name: this.state.player[this.state.version].name,
|
|
|
|
editing_name: false,
|
|
|
|
});
|
|
|
|
}.bind(this)}
|
|
|
|
/>
|
|
|
|
</form>
|
|
|
|
}</LabelledSection>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
|
|
|
if (this.state.player[this.state.version]) {
|
|
|
|
var player = this.state.player[this.state.version];
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<div className="section">
|
|
|
|
{this.state.profiles.map(function(version) {
|
|
|
|
return (
|
|
|
|
<Nav
|
|
|
|
title={window.versions[version]}
|
|
|
|
active={this.state.version == version}
|
|
|
|
onClick={function(event) {
|
|
|
|
if (this.state.editing_name) { return; }
|
|
|
|
if (this.state.version == version) { return; }
|
|
|
|
this.setState({
|
|
|
|
version: version,
|
|
|
|
new_name: this.state.player[version].name,
|
|
|
|
});
|
|
|
|
pagenav.navigate(version);
|
|
|
|
}.bind(this)}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}.bind(this))}
|
|
|
|
</div>
|
|
|
|
<div className="section">
|
|
|
|
<h3>User Profile</h3>
|
|
|
|
{this.renderName(player)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<div className="section">
|
|
|
|
You have no profile for {window.versions[this.state.version]}!
|
|
|
|
</div>
|
|
|
|
<div className="section">
|
|
|
|
{this.state.profiles.map(function(version) {
|
|
|
|
return (
|
|
|
|
<Nav
|
|
|
|
title={window.versions[version]}
|
|
|
|
active={this.state.version == version}
|
|
|
|
onClick={function(event) {
|
|
|
|
if (this.state.version == version) { return; }
|
|
|
|
this.setState({
|
|
|
|
version: version,
|
|
|
|
});
|
|
|
|
pagenav.navigate(version);
|
|
|
|
}.bind(this)}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}.bind(this))}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
ReactDOM.render(
|
|
|
|
React.createElement(settings_view, null),
|
|
|
|
document.getElementById('content')
|
|
|
|
);
|