2015-06-07 06:19:19 +03:00
|
|
|
import BaseValidator from './base';
|
|
|
|
|
2015-08-19 14:55:40 +03:00
|
|
|
export default BaseValidator.create({
|
2015-06-07 06:19:19 +03:00
|
|
|
properties: ['title', 'description', 'password', 'postsPerPage'],
|
2015-10-28 14:36:45 +03:00
|
|
|
title(model) {
|
|
|
|
let 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
|
|
|
},
|
2015-10-28 14:36:45 +03:00
|
|
|
|
|
|
|
description(model) {
|
|
|
|
let 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
|
|
|
},
|
2015-10-28 14:36:45 +03:00
|
|
|
|
|
|
|
password(model) {
|
|
|
|
let isPrivate = model.get('isPrivate');
|
|
|
|
let 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
|
|
|
},
|
2015-10-28 14:36:45 +03:00
|
|
|
|
|
|
|
postsPerPage(model) {
|
|
|
|
let 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
|
|
|
}
|
|
|
|
});
|