/*** @jsx React.DOM */
var valid_versions = Object.keys(window.versions);
var pagenav = new History(valid_versions);
var valid_emblem_options = [
'background',
'main',
'ornament',
'effect',
'speech_bubble',
]
var emblem_option_names = {
'main': 'Main',
'background': 'Background',
'ornament': 'Ornament',
'effect': 'Effect',
'speech_bubble': 'Speech Bubble',
}
var settings_view = createReactClass({
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,
emblem_changed: {},
emblem_saving: {},
emblem_saved: {},
};
},
componentDidMount: function() {
pagenav.onChange(function(version) {
this.setState({version: version});
}.bind(this));
},
componentDidUpdate: function() {
if (this.focus_element && this.focus_element != this.already_focused) {
this.focus_element.focus();
this.already_focused = this.focus_element;
}
},
setEmblemChanged: function(val) {
this.state.emblem_changed[this.state.version] = val;
return this.state.emblem_changed
},
setEmblemSaving: function(val) {
this.state.emblem_saving[this.state.version] = val;
return this.state.emblem_saving
},
setEmblemSaved: function(val) {
this.state.emblem_saved[this.state.version] = val;
return this.state.emblem_saved
},
saveEmblem: function(event) {
this.setState({ emblem_saving: this.setEmblemSaving(true), emblem_saved: this.setEmblemSaved(false) })
AJAX.post(
Link.get('updateemblem'),
{
version: this.state.version,
emblem: this.state.player[this.state.version].emblem,
},
function(response) {
var player = this.state.player
player[response.version].emblem = response.emblem
this.setState({
player: player,
emblem_saving: this.setEmblemSaving(false),
emblem_saved: this.setEmblemSaved(true),
emblem_changed: this.setEmblemChanged(false),
})
}.bind(this)
)
},
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 (