2015-06-07 06:19:19 +03:00
|
|
|
import BaseValidator from './base';
|
|
|
|
|
|
|
|
var SettingValidator = BaseValidator.create({
|
|
|
|
properties: ['title', 'description', 'password', 'postsPerPage'],
|
|
|
|
title: function (model) {
|
|
|
|
var title = model.get('title');
|
2014-06-24 10:33:24 +04:00
|
|
|
|
|
|
|
if (!validator.isLength(title, 0, 150)) {
|
2015-06-07 06:19:19 +03:00
|
|
|
model.get('errors').add('title', 'Title is too long');
|
|
|
|
this.invalidate();
|
2014-06-24 10:33:24 +04:00
|
|
|
}
|
2015-06-07 06:19:19 +03:00
|
|
|
},
|
|
|
|
description: function (model) {
|
|
|
|
var desc = model.get('description');
|
2014-06-24 10:33:24 +04:00
|
|
|
|
2015-06-07 06:19:19 +03:00
|
|
|
if (!validator.isLength(desc, 0, 200)) {
|
|
|
|
model.get('errors').add('description', 'Description is too long');
|
|
|
|
this.invalidate();
|
2014-06-24 10:33:24 +04:00
|
|
|
}
|
2015-06-07 06:19:19 +03:00
|
|
|
},
|
|
|
|
password: function (model) {
|
|
|
|
var isPrivate = model.get('isPrivate'),
|
2015-07-07 20:14:23 +03:00
|
|
|
password = model.get('password');
|
2014-06-24 10:33:24 +04:00
|
|
|
|
2015-05-11 18:35:55 +03:00
|
|
|
if (isPrivate && password === '') {
|
2015-06-07 06:19:19 +03:00
|
|
|
model.get('errors').add('password', 'Password must be supplied');
|
|
|
|
this.invalidate();
|
2015-05-11 18:35:55 +03:00
|
|
|
}
|
2015-06-07 06:19:19 +03:00
|
|
|
},
|
|
|
|
postsPerPage: function (model) {
|
|
|
|
var postsPerPage = model.get('postsPerPage');
|
2015-05-11 18:35:55 +03:00
|
|
|
|
2015-07-11 20:04:19 +03:00
|
|
|
if (!validator.isInt(postsPerPage)) {
|
|
|
|
model.get('errors').add('postsPerPage', 'Posts per page must be a number');
|
|
|
|
this.invalidate();
|
|
|
|
} else if (postsPerPage > 1000) {
|
2015-06-07 06:19:19 +03:00
|
|
|
model.get('errors').add('postsPerPage', 'The maximum number of posts per page is 1000');
|
|
|
|
this.invalidate();
|
2015-07-11 20:04:19 +03:00
|
|
|
} else if (postsPerPage < 1) {
|
2015-06-07 06:19:19 +03:00
|
|
|
model.get('errors').add('postsPerPage', 'The minimum number of posts per page is 1');
|
|
|
|
this.invalidate();
|
2014-08-08 06:58:25 +04:00
|
|
|
}
|
2014-06-24 10:33:24 +04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default SettingValidator;
|