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.
Sonarr/src/UI/Commands/CommandModel.js

50 lines
1.3 KiB

10 years ago
var _ = require('underscore');
var Backbone = require('backbone');
module.exports = Backbone.Model.extend({
url : window.NzbDrone.ApiRoot + '/command',
parse : function(response) {
10 years ago
response.name = response.name.toLocaleLowerCase();
response.body.name = response.body.name.toLocaleLowerCase();
for (var key in response.body) {
response[key] = response.body[key];
}
delete response.body;
10 years ago
return response;
},
isSameCommand : function(command) {
if (command.name.toLocaleLowerCase() !== this.get('name').toLocaleLowerCase()) {
10 years ago
return false;
}
10 years ago
for (var key in command) {
if (key !== 'name') {
if (Array.isArray(command[key])) {
if (_.difference(command[key], this.get(key)).length > 0) {
10 years ago
return false;
12 years ago
}
}
else if (command[key] !== this.get(key)) {
10 years ago
return false;
}
12 years ago
}
10 years ago
}
10 years ago
return true;
},
isActive : function() {
return this.get('status') !== 'completed' && this.get('status') !== 'failed';
10 years ago
},
isComplete : function() {
return this.get('status') === 'completed';
10 years ago
}
});