/*** @jsx React.DOM */ function makeSettingName(game_settings) { return game_settings.game + '-' + game_settings.version; } var valid_settings = window.game_settings.map(function(setting) { return makeSettingName(setting); }); var pagenav = new History(valid_settings); var arcade_management = React.createClass({ getInitialState: function(props) { var credits = {}; Object.keys(window.users).map(function(userid) { credits[userid] = ''; }); return { id: window.arcade.id, name: window.arcade.name, description: window.arcade.description, paseli_enabled: window.arcade.paseli_enabled, paseli_infinite: window.arcade.paseli_infinite, mask_services_url: window.arcade.mask_services_url, pin: window.arcade.pin, editing_pin: false, new_pin: '', paseli_enabled_saving: false, paseli_infinite_saving: false, mask_services_url_saving: false, machines: window.machines, settings: window.game_settings, current_setting: pagenav.getInitialState(makeSettingName(window.game_settings[0])), settings_changed: {}, settings_saving: {}, settings_saved: {}, users: window.users, balances: window.balances, credits: credits, events: window.events, eventoffset: 0, eventlimit: 5, credit_card: '', credit_amount: '', }; }, componentDidMount: function() { pagenav.onChange(function(setting) { this.setState({current_setting: setting}); }.bind(this)); this.refreshArcade(); }, refreshArcade: function() { AJAX.get( Link.get('refresh'), function(response) { this.setState({ users: response.users, balances: response.balances, machines: response.machines, events: response.events, }); // Refresh every 15 seconds setTimeout(this.refreshArcade, 5000); }.bind(this) ); }, savePin: function(event) { AJAX.post( Link.get('update_pin'), {pin: this.state.new_pin}, function(response) { this.setState({ pin: response.pin, new_pin: '', editing_pin: false, }); }.bind(this) ); event.preventDefault(); }, getSettingIndex: function(setting_name) { var real_index = -1; this.state.settings.map(function(game_settings, index) { var current = makeSettingName(game_settings); if (current == setting_name) { real_index = index; } }.bind(this)); return real_index; }, togglePaseliEnabled: function(event) { this.setState({paseli_enabled_saving: true}) AJAX.post( Link.get('paseli_enabled'), {value: !this.state.paseli_enabled}, function(response) { this.setState({ paseli_enabled: response.value, paseli_enabled_saving: false, }); }.bind(this) ); event.preventDefault(); }, togglePaseliInfinite: function(event) { this.setState({paseli_infinite_saving: true}) AJAX.post( Link.get('paseli_infinite'), {value: !this.state.paseli_infinite}, function(response) { this.setState({ paseli_infinite: response.value, paseli_infinite_saving: false, }); }.bind(this) ); event.preventDefault(); }, toggleMaskServicesURL: function(event) { this.setState({mask_services_url_saving: true}) AJAX.post( Link.get('mask_services_url'), {value: !this.state.mask_services_url}, function(response) { this.setState({ mask_services_url: response.value, mask_services_url_saving: false, }); }.bind(this) ); event.preventDefault(); }, 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(); }, addBalance: function(event) { var intval = parseInt(this.state.credit_amount); if (isNaN(intval)) { intval = 0; } AJAX.post( Link.get('add_balance'), { credits: intval, card: this.state.credit_card, }, function(response) { var credits = {}; Object.keys(response.users).map(function(userid) { credits[userid] = ''; }); console.log('huh?'); this.setState({ users: response.users, balances: response.balances, credits: credits, events: response.events, credit_card: '', credit_amount: '', }); }.bind(this) ); event.preventDefault(); }, updateBalance: function(event) { var updates = {}; Object.keys(this.state.credits).map(function(userid) { var intval = parseInt(this.state.credits[userid]); if (!isNaN(intval)) { updates[userid] = intval; } }.bind(this)); AJAX.post( Link.get('update_balance'), {credits: updates}, function(response) { var credits = {}; Object.keys(response.users).map(function(userid) { credits[userid] = ''; }); this.setState({ users: response.users, balances: response.balances, credits: credits, events: response.events, }); }.bind(this) ); event.preventDefault(); }, renderPIN: function() { return ( { !this.state.editing_pin ? {this.state.pin} :
}
); }, render: function() { return (
{ this.state.name } { this.state.description ? { this.state.description } : no description } {this.renderPIN()} { this.state.paseli_enabled ? 'yes' : 'no' } { this.state.paseli_enabled_saving ? : null } { this.state.paseli_infinite ? 'yes' : 'no' } { this.state.paseli_infinite_saving ? : null } { this.state.mask_services_url ? 'yes' : 'no' } { this.state.mask_services_url_saving ? : null }

PCBIDs Assigned to This Arcade

Game Settings For This Arcade

{ this.state.settings.map(function(game_settings) { var current = makeSettingName(game_settings); return (
{ this.state.settings[this.getSettingIndex(this.state.current_setting)].ints.map(function(setting, index) { return (
); }.bind(this))} { this.state.settings[this.getSettingIndex(this.state.current_setting)].bools.map(function(setting, index) { return (
); }.bind(this))} { this.state.settings_saving[this.state.current_setting] ? : null } { this.state.settings_saved[this.state.current_setting] ? : null }

User PASELI Balances for This Arcade

{ Object.keys(this.state.balances).length == 0 ?
No users with balances for this arcade!
:
{Object.keys(this.state.balances).map(function(userid) { var user = this.state.users[userid]; return ( ); }.bind(this))}
User Current Balance Credit Amount
{ user ? {user} : anonymous account } {this.state.balances[userid]}
}

Credit PASELI via Card

Card Number Credit Amount

PASELI Transaction History

{ this.state.events.length == 0 ?
No events to display!
: {this.state.events.map(function(event, index) { if (index < this.state.eventoffset || index >= this.state.eventoffset + this.state.eventlimit) { return null; } if(event.type == 'paseli_transaction') { return ; } else { return null; } }.bind(this))}
Timestamp Event Details
{ this.state.eventoffset > 0 ? : null } { (this.state.eventoffset + this.state.eventlimit) < this.state.events.length ? = this.state.events.length) { return } this.setState({eventoffset: page}); }.bind(this)}/> : null }
}
); }, }); ReactDOM.render( React.createElement(arcade_management, null), document.getElementById('content') );