/*** @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,
},
};
},
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) {
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 Arcade',
content: 'Are you sure you want to delete this arcade 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 ;
} 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 (