mirror of
https://github.com/Radarr/Radarr.git
synced 2026-04-18 21:35:51 -04:00
UI Cleanup - Updated Commands subtree.
This commit is contained in:
@@ -7,69 +7,88 @@ var moment = require('moment');
|
||||
var Messenger = require('../Shared/Messenger');
|
||||
require('../jQuery/jquery.spin');
|
||||
|
||||
module.exports = (function(){
|
||||
CommandMessengerCollectionView.render();
|
||||
var singleton = function(){
|
||||
return {
|
||||
_lastCommand : {},
|
||||
Execute : function(name, properties){
|
||||
var attr = _.extend({name : name.toLocaleLowerCase()}, properties);
|
||||
var commandModel = new CommandModel(attr);
|
||||
if(this._lastCommand.command && this._lastCommand.command.isSameCommand(attr) && moment().add('seconds', -5).isBefore(this._lastCommand.time)) {
|
||||
Messenger.show({
|
||||
message : 'Please wait at least 5 seconds before running this command again',
|
||||
hideAfter : 5,
|
||||
type : 'error'
|
||||
});
|
||||
return this._lastCommand.promise;
|
||||
}
|
||||
var promise = commandModel.save().success(function(){
|
||||
CommandCollection.add(commandModel);
|
||||
CommandMessengerCollectionView.render();
|
||||
|
||||
var singleton = function() {
|
||||
|
||||
return {
|
||||
|
||||
_lastCommand : {},
|
||||
|
||||
Execute : function(name, properties) {
|
||||
|
||||
var attr = _.extend({ name : name.toLocaleLowerCase() }, properties);
|
||||
var commandModel = new CommandModel(attr);
|
||||
|
||||
if (this._lastCommand.command && this._lastCommand.command.isSameCommand(attr) && moment().add('seconds', -5).isBefore(this._lastCommand.time)) {
|
||||
|
||||
Messenger.show({
|
||||
message : 'Please wait at least 5 seconds before running this command again',
|
||||
hideAfter : 5,
|
||||
type : 'error'
|
||||
});
|
||||
this._lastCommand = {
|
||||
command : commandModel,
|
||||
promise : promise,
|
||||
time : moment()
|
||||
};
|
||||
return promise;
|
||||
},
|
||||
bindToCommand : function(options){
|
||||
var self = this;
|
||||
var existingCommand = CommandCollection.findCommand(options.command);
|
||||
if(existingCommand) {
|
||||
this._bindToCommandModel.call(this, existingCommand, options);
|
||||
}
|
||||
CommandCollection.bind('add', function(model){
|
||||
if(model.isSameCommand(options.command)) {
|
||||
self._bindToCommandModel.call(self, model, options);
|
||||
}
|
||||
});
|
||||
CommandCollection.bind('sync', function(){
|
||||
var command = CommandCollection.findCommand(options.command);
|
||||
if(command) {
|
||||
self._bindToCommandModel.call(self, command, options);
|
||||
}
|
||||
});
|
||||
},
|
||||
_bindToCommandModel : function bindToCommand (model, options){
|
||||
if(!model.isActive()) {
|
||||
options.element.stopSpin();
|
||||
return;
|
||||
}
|
||||
model.bind('change:state', function(model){
|
||||
if(!model.isActive()) {
|
||||
options.element.stopSpin();
|
||||
if(model.isComplete()) {
|
||||
vent.trigger(vent.Events.CommandComplete, {
|
||||
command : model,
|
||||
model : options.model
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
options.element.startSpin();
|
||||
|
||||
return this._lastCommand.promise;
|
||||
}
|
||||
};
|
||||
|
||||
var promise = commandModel.save().success(function() {
|
||||
CommandCollection.add(commandModel);
|
||||
});
|
||||
|
||||
this._lastCommand = {
|
||||
command : commandModel,
|
||||
promise : promise,
|
||||
time : moment()
|
||||
};
|
||||
|
||||
return promise;
|
||||
},
|
||||
|
||||
bindToCommand : function(options) {
|
||||
|
||||
var self = this;
|
||||
var existingCommand = CommandCollection.findCommand(options.command);
|
||||
|
||||
if (existingCommand) {
|
||||
this._bindToCommandModel.call(this, existingCommand, options);
|
||||
}
|
||||
|
||||
CommandCollection.bind('add', function(model) {
|
||||
if (model.isSameCommand(options.command)) {
|
||||
self._bindToCommandModel.call(self, model, options);
|
||||
}
|
||||
});
|
||||
|
||||
CommandCollection.bind('sync', function() {
|
||||
var command = CommandCollection.findCommand(options.command);
|
||||
if (command) {
|
||||
self._bindToCommandModel.call(self, command, options);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
_bindToCommandModel : function bindToCommand (model, options) {
|
||||
|
||||
if (!model.isActive()) {
|
||||
options.element.stopSpin();
|
||||
return;
|
||||
}
|
||||
|
||||
model.bind('change:state', function(model) {
|
||||
if (!model.isActive()) {
|
||||
options.element.stopSpin();
|
||||
|
||||
if (model.isComplete()) {
|
||||
vent.trigger(vent.Events.CommandComplete, {
|
||||
command : model,
|
||||
model : options.model
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
options.element.startSpin();
|
||||
}
|
||||
};
|
||||
return singleton();
|
||||
}).call(this);
|
||||
};
|
||||
module.exports = singleton();
|
||||
|
||||
Reference in New Issue
Block a user