You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Lidarr/UI/Commands/CommandController.js

57 lines
1.6 KiB

'use strict';
11 years ago
define(
[
'Commands/CommandModel',
'Commands/CommandCollection',
'underscore',
'jQuery/jquery.spin'
11 years ago
], function (CommandModel, CommandCollection, _) {
11 years ago
return{
11 years ago
Execute: function (name, properties) {
var attr = _.extend({name: name.toLocaleLowerCase()}, properties);
11 years ago
var commandModel = new CommandModel(attr);
return commandModel.save().success(function () {
CommandCollection.add(commandModel);
});
},
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();
11 years ago
}
}
});