|
|
@ -7,59 +7,78 @@ var moment = require('moment');
|
|
|
|
var Messenger = require('../Shared/Messenger');
|
|
|
|
var Messenger = require('../Shared/Messenger');
|
|
|
|
require('../jQuery/jquery.spin');
|
|
|
|
require('../jQuery/jquery.spin');
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = (function(){
|
|
|
|
CommandMessengerCollectionView.render();
|
|
|
|
CommandMessengerCollectionView.render();
|
|
|
|
|
|
|
|
var singleton = function(){
|
|
|
|
var singleton = function() {
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
|
|
|
|
|
|
|
|
_lastCommand : {},
|
|
|
|
_lastCommand : {},
|
|
|
|
Execute : function(name, properties){
|
|
|
|
|
|
|
|
var attr = _.extend({name : name.toLocaleLowerCase()}, properties);
|
|
|
|
Execute : function(name, properties) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var attr = _.extend({ name : name.toLocaleLowerCase() }, properties);
|
|
|
|
var commandModel = new CommandModel(attr);
|
|
|
|
var commandModel = new CommandModel(attr);
|
|
|
|
if(this._lastCommand.command && this._lastCommand.command.isSameCommand(attr) && moment().add('seconds', -5).isBefore(this._lastCommand.time)) {
|
|
|
|
|
|
|
|
|
|
|
|
if (this._lastCommand.command && this._lastCommand.command.isSameCommand(attr) && moment().add('seconds', -5).isBefore(this._lastCommand.time)) {
|
|
|
|
|
|
|
|
|
|
|
|
Messenger.show({
|
|
|
|
Messenger.show({
|
|
|
|
message : 'Please wait at least 5 seconds before running this command again',
|
|
|
|
message : 'Please wait at least 5 seconds before running this command again',
|
|
|
|
hideAfter : 5,
|
|
|
|
hideAfter : 5,
|
|
|
|
type : 'error'
|
|
|
|
type : 'error'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
return this._lastCommand.promise;
|
|
|
|
return this._lastCommand.promise;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var promise = commandModel.save().success(function(){
|
|
|
|
|
|
|
|
|
|
|
|
var promise = commandModel.save().success(function() {
|
|
|
|
CommandCollection.add(commandModel);
|
|
|
|
CommandCollection.add(commandModel);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
this._lastCommand = {
|
|
|
|
this._lastCommand = {
|
|
|
|
command : commandModel,
|
|
|
|
command : commandModel,
|
|
|
|
promise : promise,
|
|
|
|
promise : promise,
|
|
|
|
time : moment()
|
|
|
|
time : moment()
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return promise;
|
|
|
|
return promise;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
bindToCommand : function(options){
|
|
|
|
|
|
|
|
|
|
|
|
bindToCommand : function(options) {
|
|
|
|
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
var self = this;
|
|
|
|
var existingCommand = CommandCollection.findCommand(options.command);
|
|
|
|
var existingCommand = CommandCollection.findCommand(options.command);
|
|
|
|
if(existingCommand) {
|
|
|
|
|
|
|
|
|
|
|
|
if (existingCommand) {
|
|
|
|
this._bindToCommandModel.call(this, existingCommand, options);
|
|
|
|
this._bindToCommandModel.call(this, existingCommand, options);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CommandCollection.bind('add', function(model){
|
|
|
|
|
|
|
|
if(model.isSameCommand(options.command)) {
|
|
|
|
CommandCollection.bind('add', function(model) {
|
|
|
|
|
|
|
|
if (model.isSameCommand(options.command)) {
|
|
|
|
self._bindToCommandModel.call(self, model, options);
|
|
|
|
self._bindToCommandModel.call(self, model, options);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
CommandCollection.bind('sync', function(){
|
|
|
|
|
|
|
|
|
|
|
|
CommandCollection.bind('sync', function() {
|
|
|
|
var command = CommandCollection.findCommand(options.command);
|
|
|
|
var command = CommandCollection.findCommand(options.command);
|
|
|
|
if(command) {
|
|
|
|
if (command) {
|
|
|
|
self._bindToCommandModel.call(self, command, options);
|
|
|
|
self._bindToCommandModel.call(self, command, options);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
_bindToCommandModel : function bindToCommand (model, options){
|
|
|
|
|
|
|
|
if(!model.isActive()) {
|
|
|
|
_bindToCommandModel : function bindToCommand (model, options) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!model.isActive()) {
|
|
|
|
options.element.stopSpin();
|
|
|
|
options.element.stopSpin();
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
model.bind('change:state', function(model){
|
|
|
|
|
|
|
|
if(!model.isActive()) {
|
|
|
|
model.bind('change:state', function(model) {
|
|
|
|
|
|
|
|
if (!model.isActive()) {
|
|
|
|
options.element.stopSpin();
|
|
|
|
options.element.stopSpin();
|
|
|
|
if(model.isComplete()) {
|
|
|
|
|
|
|
|
|
|
|
|
if (model.isComplete()) {
|
|
|
|
vent.trigger(vent.Events.CommandComplete, {
|
|
|
|
vent.trigger(vent.Events.CommandComplete, {
|
|
|
|
command : model,
|
|
|
|
command : model,
|
|
|
|
model : options.model
|
|
|
|
model : options.model
|
|
|
@ -67,9 +86,9 @@ module.exports = (function(){
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
options.element.startSpin();
|
|
|
|
options.element.startSpin();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
return singleton();
|
|
|
|
module.exports = singleton();
|
|
|
|
}).call(this);
|
|
|
|
|
|
|
|