1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-23 02:05:27 +02:00
Sonarr/NzbDrone.Web/Scripts/backbone/models/qualityProfile.js

50 lines
1.5 KiB
JavaScript
Raw Normal View History

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