sonarr-repo-only/UI/Commands/CommandController.js

57 lines
1.6 KiB
JavaScript
Raw Normal View History

2013-06-22 06:24:24 +00:00
'use strict';
2013-09-11 06:33:47 +00:00
define(
[
'Commands/CommandModel',
'Commands/CommandCollection',
2013-09-12 00:42:15 +00:00
'underscore',
'jQuery/jquery.spin'
2013-09-11 06:33:47 +00:00
], function (CommandModel, CommandCollection, _) {
2013-05-11 23:39:32 +00:00
2013-09-11 06:33:47 +00:00
return{
2013-09-12 00:42:15 +00:00
2013-09-11 06:33:47 +00:00
Execute: function (name, properties) {
var attr = _.extend({name: name.toLocaleLowerCase()}, properties);
2013-06-13 02:55:11 +00:00
2013-09-11 06:33:47 +00:00
var commandModel = new CommandModel(attr);
return commandModel.save().success(function () {
CommandCollection.add(commandModel);
});
2013-09-12 00:42:15 +00:00
},
bindToCommand: function (options) {
var self = this;
var existingCommand = CommandCollection.findCommand(options.command);
if (existingCommand) {
this._bindToCommandModel.call(this, existingCommand, options);
}
CommandCollection.bind('add sync', function (model) {
if (model.isSameCommand(options.command)) {
self._bindToCommandModel.call(self, model, 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();
}
});
options.element.startSpin();
2013-09-11 06:33:47 +00:00
}
2013-06-13 02:55:11 +00:00
}
});