/*** @jsx React.DOM */ function count_pcbids(machines) { var count = 0; machines.map(function(machine) { count += (machine.editable ? 1 : 0); }); return count; } 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: '', region: window.arcade.region, editing_region: false, new_region: '', paseli_enabled_saving: false, paseli_infinite_saving: false, mask_services_url_saving: false, editing_machine: null, machines: window.machines, pcbcount: count_pcbids(window.machines), random_pcbid: { description: '', }, users: window.users, balances: window.balances, credits: credits, events: window.events, eventoffset: 0, eventlimit: 5, credit_card: '', credit_amount: '', }; }, componentDidMount: function() { this.refreshArcade(); }, componentDidUpdate: function() { if (this.focus_element && this.focus_element != this.already_focused) { this.focus_element.focus(); this.already_focused = this.focus_element; } }, refreshArcade: function() { AJAX.get( Link.get('refresh'), function(response) { this.setState({ users: response.users, balances: response.balances, machines: response.machines, pcbcount: count_pcbids(response.machines), events: response.events, }); // Refresh every 5 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(); }, saveRegion: function(event) { AJAX.post( Link.get('update_region'), {region: this.state.new_region}, function(response) { this.setState({ region: response.region, new_region: '', editing_region: false, }); }.bind(this) ); event.preventDefault(); }, 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(); }, 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] = ''; }); 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} :
(this.focus_element = c)} value={this.state.new_pin} onChange={function(event) { var intRegex = /^\d*$/; if (event.target.value.length <= 8 && intRegex.test(event.target.value)) { this.setState({new_pin: event.target.value}); } }.bind(this)} name="pin" />
}
); }, renderRegion: function() { return ( { !this.state.editing_region ? { window.regions[this.state.region] } :
}
); }, generateNewMachine: function(event) { AJAX.post( Link.get('generatepcbid'), {machine: this.state.random_pcbid}, function(response) { this.setState({ machines: response.machines, pcbcount: count_pcbids(response.machines), random_pcbid: { description: '', }, }); }.bind(this) ); event.preventDefault(); }, deleteExistingMachine: function(event, pcbid) { $.confirm({ escapeKey: 'Cancel', animation: 'none', closeAnimation: 'none', title: 'Delete PCBID', content: 'Are you sure you want to delete this PCBID from the network?', buttons: { Delete: { btnClass: 'delete', action: function() { AJAX.post( Link.get('removepcbid'), {pcbid: pcbid}, function(response) { this.setState({ machines: response.machines, pcbcount: count_pcbids(response.machines), }); }.bind(this) ); }.bind(this), }, Cancel: function() { }, } }); event.preventDefault(); }, saveMachine: function(event) { machine = this.state.editing_machine; if (machine.port == '') { machine.port = 0; } AJAX.post( Link.get('updatepcbid'), {machine: this.state.editing_machine}, function(response) { this.setState({ machines: response.machines, pcbcount: count_pcbids(response.machines), editing_machine: null, }); }.bind(this) ); event.preventDefault(); }, renderDescription: function(machine) { if (this.state.editing_machine && machine.pcbid == this.state.editing_machine.pcbid) { return (this.focus_element = c)} value={ this.state.editing_machine.description } onChange={function(event) { var machine = this.state.editing_machine; machine.description = event.target.value; this.setState({ editing_machine: machine, }); }.bind(this)} />; } else { return ( { machine.description } ); } }, renderPort: function(machine) { if (this.state.editing_machine && machine.pcbid == this.state.editing_machine.pcbid) { return 0) { machine.port = parseInt(event.target.value); } else { machine.port = ''; } this.setState({ editing_machine: machine, }); } }.bind(this)} />; } else { return ( { machine.port } ); } }, renderEditButton: function(machine) { if (this.state.editing_machine) { if (this.state.editing_machine.pcbid == machine.pcbid) { return ( ); } else { return ; } } else { if (window.max_pcbids > 0 && machine.editable) { return ( ); } else { return ; } } }, render: function() { return (
{ this.state.name } { this.state.description ? { this.state.description } : no description } {this.renderPIN()} {this.renderRegion()} PASELI Enabled { this.state.paseli_enabled_saving ? : null } }> PASELI Infinite { this.state.paseli_infinite_saving ? : null } }> Mask Web Address { this.state.mask_services_url_saving ? : null } }>

PCBIDs Assigned to This Arcade

{ window.enforcing && this.state.pcbcount < window.max_pcbids ?

Generate PCBID

Description
: null }

Game Settings For This Arcade

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') );