/*** @jsx React.DOM */ function makeGameSettingName(game_settings) { return game_settings.game + '-' + game_settings.version; } var GameSettings = createReactClass({ getInitialState: function() { var valid_settings = this.props.game_settings.map(function(setting) { return makeGameSettingName(setting); }); var pagenav = new History(valid_settings); return { pagenav: pagenav, settings: this.props.game_settings, current_setting: pagenav.getInitialState(makeGameSettingName(this.props.game_settings[0])), settings_changed: {}, settings_saving: {}, settings_saved: {}, }; }, componentDidMount: function() { this.state.pagenav.onChange(function(setting) { this.setState({current_setting: setting}); }.bind(this)); }, getSettingIndex: function(setting_name) { var real_index = -1; this.state.settings.map(function(game_settings, index) { var current = makeGameSettingName(game_settings); if (current == setting_name) { real_index = index; } }.bind(this)); return real_index; }, setChanged: function(val) { this.state.settings_changed[this.state.current_setting] = val; return this.state.settings_changed; }, setSaving: function(val) { this.state.settings_saving[this.state.current_setting] = val; return this.state.settings_saving; }, setSaved: function(val) { this.state.settings_saved[this.state.current_setting] = val; return this.state.settings_saved; }, saveSettings: function(event) { var index = this.getSettingIndex(this.state.current_setting); this.setState({settings_saving: this.setSaving(true), settings_saved: this.setSaved(false)}); AJAX.post( Link.get('update_settings'), this.state.settings[index], function(response) { this.state.settings[index] = response.game_settings; this.setState({ settings: this.state.settings, settings_saving: this.setSaving(false), settings_saved: this.setSaved(true), settings_changed: this.setChanged(false), }); }.bind(this) ); event.preventDefault(); }, render: function() { return (