Sonarr/NzbDrone.Web/Scripts/backbone/models/qualityProfile.js

50 lines
1.5 KiB
JavaScript
Raw Normal View History

2012-11-09 16:28:59 +00:00
window.QualityProfile = Backbone.Model.extend({
2012-11-07 00:41:34 +00:00
urlRoot: '/api/qualityprofiles',
2012-11-24 08:03:38 +00:00
idAttribute: 'Id',
2012-11-07 00:41:34 +00:00
initialize: function () {
this.validators = {};
this.validators.name = function (value) {
return value.length > 0 ? { isValid: true } : { isValid: false, message: 'You must enter a name' };
};
2012-11-24 08:03:38 +00:00
//this.validators.allowed = function (value) {
// return value.length > 0 ? { isValid: true } : { isValid: false, message: 'You must have allowed qualities' };
//};
2012-12-06 01:19:17 +00:00
//Todo: Cutoff should be something that is allowed (double check)
2012-11-07 00:41:34 +00:00
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: {
2012-11-24 08:03:38 +00:00
Id: null,
Name: '',
//allowed: {},
Cutoff: null
2012-11-07 00:41:34 +00:00
}
});