2014-06-24 10:33:24 +04:00
|
|
|
var SettingValidator = Ember.Object.create({
|
2014-06-30 07:43:25 +04:00
|
|
|
check: function (model) {
|
2014-06-24 10:33:24 +04:00
|
|
|
var validationErrors = [],
|
|
|
|
title = model.get('title'),
|
|
|
|
description = model.get('description'),
|
|
|
|
email = model.get('email'),
|
|
|
|
postsPerPage = model.get('postsPerPage');
|
|
|
|
|
|
|
|
if (!validator.isLength(title, 0, 150)) {
|
|
|
|
validationErrors.push({ message: 'Title is too long' });
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!validator.isLength(description, 0, 200)) {
|
|
|
|
validationErrors.push({ message: 'Description is too long' });
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!validator.isEmail(email) || !validator.isLength(email, 0, 254)) {
|
|
|
|
validationErrors.push({ message: 'Please supply a valid email address' });
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!validator.isInt(postsPerPage) || postsPerPage > 1000) {
|
|
|
|
validationErrors.push({ message: 'Please use a number less than 1000' });
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!validator.isInt(postsPerPage) || postsPerPage < 0) {
|
|
|
|
validationErrors.push({ message: 'Please use a number greater than 0' });
|
|
|
|
}
|
|
|
|
|
|
|
|
return validationErrors;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default SettingValidator;
|