/*** @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 = React.createClass({ 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 ( { !this.state.editing_name ? {player.name} :
(this.focus_element = c)} size="8" value={this.state.new_name} onChange={function(event) { var value = event.target.value.toUpperCase(); var nameRegex = /^[ -&\\.\\*A-Z0-9]*$/; if (value.length <= 8 && nameRegex.test(value)) { this.setState({new_name: value}); } }.bind(this)} name="name" />
}
); }, renderEmblem: function(player) { return (

Emblem

{ valid_emblem_options.map(function(emblem_option) { var player = this.state.player[this.state.version] var layer = valid_emblem_options.indexOf(emblem_option) + 1 var items = window.emblems[this.state.version].filter(function (emblem) { return emblem.layer == layer }); var results = {}; items .map(function(item) { return { 'index': item.index, 'name': `${item.name} (★${item.rarity})` } }) .forEach (value => results[value.index] = value.name); if (layer != 2) { results[0] = "None" } return( ) }.bind(this)) } { this.state.emblem_saving[this.state.version] ? : null } { this.state.emblem_saved[this.state.version] ? : null }
) }, render: function() { if (this.state.player[this.state.version]) { var player = this.state.player[this.state.version]; return (
{this.state.profiles.map(function(version) { return (

User Profile

{this.renderName(player)}
{ this.state.version > 9 ? this.renderEmblem(player) : null }
); } else { return (
You have no profile for {window.versions[this.state.version]}!
{this.state.profiles.map(function(version) { return (
); } }, }); ReactDOM.render( React.createElement(settings_view, null), document.getElementById('content') );