mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-15 09:33:52 -07:00
Moved source code under src folder - massive change
This commit is contained in:
parent
2fc8123d6b
commit
5bf0e197ec
1499 changed files with 1054 additions and 1444 deletions
66
src/UI/Commands/CommandController.js
Normal file
66
src/UI/Commands/CommandController.js
Normal file
|
@ -0,0 +1,66 @@
|
|||
'use strict';
|
||||
define(
|
||||
[
|
||||
'app',
|
||||
'Commands/CommandModel',
|
||||
'Commands/CommandCollection',
|
||||
'underscore',
|
||||
'jQuery/jquery.spin'
|
||||
], function (App, CommandModel, CommandCollection, _) {
|
||||
|
||||
var singleton = function () {
|
||||
|
||||
return {
|
||||
|
||||
Execute: function (name, properties) {
|
||||
|
||||
var attr = _.extend({name: name.toLocaleLowerCase()}, properties);
|
||||
|
||||
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();
|
||||
|
||||
if (model.isComplete()) {
|
||||
App.vent.trigger(App.Events.CommandComplete, { command: model, model: options.model });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
options.element.startSpin();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
return singleton();
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue