mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-21 14:03:29 -07:00
Added backbone
This commit is contained in:
parent
b366f8fadc
commit
b101758957
28 changed files with 5507 additions and 3 deletions
18
NzbDrone.Web/Scripts/backbone/models/profileCollection.js
Normal file
18
NzbDrone.Web/Scripts/backbone/models/profileCollection.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
window.ProfileCollection = Backbone.Collection.extend({
|
||||
|
||||
model: Profile,
|
||||
|
||||
url: '/api/qualityprofiles',
|
||||
|
||||
search: function (searchTerm, options) {
|
||||
|
||||
var self = this;
|
||||
this.fetch({
|
||||
success: function () {
|
||||
if (options.success) {
|
||||
options.success();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
50
NzbDrone.Web/Scripts/backbone/models/profileModel.js
Normal file
50
NzbDrone.Web/Scripts/backbone/models/profileModel.js
Normal file
|
@ -0,0 +1,50 @@
|
|||
window.Profile = Backbone.Model.extend({
|
||||
|
||||
urlRoot: '/api/qualityprofiles',
|
||||
|
||||
idAttribute: 'id',
|
||||
|
||||
initialize: function () {
|
||||
this.validators = {};
|
||||
|
||||
this.validators.name = function (value) {
|
||||
return value.length > 0 ? { isValid: true } : { isValid: false, message: 'You must enter a name' };
|
||||
};
|
||||
|
||||
this.validators.allowed = function (value) {
|
||||
return value.length > 0 ? { isValid: true } : { isValid: false, message: 'You must have allowed qualities' };
|
||||
};
|
||||
|
||||
this.validators.cutoff = function (value) {
|
||||
return value != null ? { isValid: true } : { isValid: false, message: 'You must have a valid cutoff' };
|
||||
};
|
||||
},
|
||||
|
||||
validateItem: function (key) {
|
||||
return (this.validators[key]) ? this.validators[key](this.get(key)) : { isValid: true };
|
||||
},
|
||||
|
||||
// TODO: Implement Backbone's standard validate() method instead.
|
||||
validateAll: function () {
|
||||
|
||||
var messages = {};
|
||||
|
||||
for (var key in this.validators) {
|
||||
if (this.validators.hasOwnProperty(key)) {
|
||||
var check = this.validators[key](this.get(key));
|
||||
if (check.isValid === false) {
|
||||
messages[key] = check.message;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return _.size(messages) > 0 ? { isValid: false, messages: messages } : { isValid: true };
|
||||
},
|
||||
|
||||
defaults: {
|
||||
id: null,
|
||||
name: '',
|
||||
allowed: {},
|
||||
cutoff: null
|
||||
}
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue