|
|
@ -1,47 +1,21 @@
|
|
|
|
define(['app'], function () {
|
|
|
|
define(['app'], function () {
|
|
|
|
NzbDrone.Quality.QualityProfileModel = Backbone.Model.extend({
|
|
|
|
NzbDrone.Quality.QualityProfileModel = Backbone.Model.extend({
|
|
|
|
initialize: function () {
|
|
|
|
|
|
|
|
this.validators = {};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.validators.name = function (value) {
|
|
|
|
mutators: {
|
|
|
|
return value.length > 0 ? { isValid: true } : { isValid: false, message: 'You must enter a name' };
|
|
|
|
allowed: function() {
|
|
|
|
};
|
|
|
|
return _.where(this.get('qualities'), { allowed: true });
|
|
|
|
|
|
|
|
|
|
|
|
//this.validators.allowed = function (value) {
|
|
|
|
|
|
|
|
// return value.length > 0 ? { isValid: true } : { isValid: false, message: 'You must have allowed qualities' };
|
|
|
|
|
|
|
|
//};
|
|
|
|
|
|
|
|
//Todo: Cutoff should be something that is allowed (double check)
|
|
|
|
|
|
|
|
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.
|
|
|
|
cutoffName: function() {
|
|
|
|
validateAll: function () {
|
|
|
|
return _.findWhere(this.get('qualities'), { id: this.get('cutoff') }).name;
|
|
|
|
|
|
|
|
|
|
|
|
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: {
|
|
|
|
defaults: {
|
|
|
|
Id: null,
|
|
|
|
id: null,
|
|
|
|
Name: '',
|
|
|
|
name: '',
|
|
|
|
//allowed: {},
|
|
|
|
//allowed: {},
|
|
|
|
Cutoff: null
|
|
|
|
cutoff: null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|