/*** @jsx React.DOM */ var machine_management = React.createClass({ getInitialState: function(props) { return { machines: window.machines, arcades: window.arcades, editing_machine: null, add_machine: { pcbid: '', name: '', description: '', arcade: null, }, random_pcbid: { name: '', description: '', arcade: null, }, }; }, componentDidMount: function() { this.refreshMachines(); }, componentDidUpdate: function() { if (this.focus_element && this.focus_element != this.already_focused) { this.focus_element.focus(); this.already_focused = this.focus_element; } }, refreshMachines: function() { AJAX.get( Link.get('refresh'), function(response) { this.setState({ machines: response.machines, arcade: response.arcades, }); // Refresh every 5 seconds setTimeout(this.refreshMachines, 5000); }.bind(this) ); }, generateNewMachine: function(event) { AJAX.post( Link.get('generatepcbid'), {machine: this.state.random_pcbid}, function(response) { this.setState({ machines: response.machines, random_pcbid: { name: '', description: '', arcade: null, }, }); }.bind(this) ); event.preventDefault(); }, addNewMachine: function(event) { AJAX.post( Link.get('addpcbid'), {machine: this.state.add_machine}, function(response) { this.setState({ machines: response.machines, add_machine: { pcbid: '', name: '', description: '', arcade: null, }, }); }.bind(this) ); 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, editing_machine: null, }); }.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, }); }.bind(this) ); }.bind(this), }, Cancel: function() { }, } }); event.preventDefault(); }, renderPCBID: function(machine) { return ( { machine.pcbid } ); }, sortPCBID: function(a, b) { return a.pcbid.localeCompare(b.pcbid); }, renderName: function(machine) { return ( { machine.name } ); }, sortName: function(a, b) { return a.name.localeCompare(b.name); }, 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 } ); } }, sortDescription: function(a, b) { return a.description.localeCompare(b.description); }, renderSeriesList: function(machine) { return ( ); }, renderGameList: function(machine, negate) { return ( ); }, renderGame: function(machine) { if (this.state.editing_machine && machine.pcbid == this.state.editing_machine.pcbid) { var value; var extra; if (this.state.editing_machine.game == 'any') { value = 'any'; extra = null; } else if(!this.state.editing_machine.version) { value = 'series'; extra = this.renderSeriesList(machine); } else if(this.state.editing_machine.version > 0) { value = 'exact'; extra = this.renderGameList(machine, false); } else if(this.state.editing_machine.version < 0) { value = 'atmost'; extra = this.renderGameList(machine, true); }; return ( {extra} ); } else { if (machine.game == 'any') { return ( any game ); } else if(!machine.version) { return ( { window.series[machine.game] } ); } else if(machine.version > 0) { return ( { window.games[machine.game][machine.version] } ); } else if(machine.version < 0) { return ( { window.games[machine.game][-machine.version] } or older ); } } }, sortGame: function(a, b) { var ag = null; var bg = null; if (a.game == 'any') { ag = 'any game'; } else if(!a.version) { ag = window.series[a.game]; } else if(a.version > 0) { ag = window.games[a.game][a.version]; } else if(a.version < 0) { ag = window.games[a.game][-a.version] + ' or older'; } if (b.game == 'any') { bg = 'any game'; } else if(!b.version) { bg = window.series[b.game]; } else if(b.version > 0) { bg = window.games[b.game][b.version]; } else if(b.version < 0) { bg = window.games[b.game][-b.version] + ' or older'; } return ag.localeCompare(bg); }, renderArcade: function(machine) { if (this.state.editing_machine && machine.pcbid == this.state.editing_machine.pcbid) { return ( ); } else { if (machine.arcade) { return ( { this.state.arcades[machine.arcade] } ); } else { return ( no arcade ); } } }, sortArcade: function(a, b) { var aarc = this.state.arcades[a.arcade]; var barc = this.state.arcades[b.arcade]; aarc = aarc ? aarc : ''; barc = barc ? barc : ''; return aarc.localeCompare(barc); }, 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 } ); } }, sortPort: function(a, b) { return a.port - b.port; }, renderEditButton: function(machine) { if (this.state.editing_machine) { if (this.state.editing_machine.pcbid == machine.pcbid) { return ( ); } else { return ; } } else { return ( ); } }, render: function() { return (

Add PCBID

PCBID Description Arcade

Generate Random PCBID

Description Arcade
); }, }); ReactDOM.render( React.createElement(machine_management, null), document.getElementById('content') );