2015-02-13 07:22:32 +03:00
|
|
|
import Ember from 'ember';
|
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'),
|
2015-05-11 18:35:55 +03:00
|
|
|
postsPerPage = model.get('postsPerPage'),
|
|
|
|
isPrivate = model.get('isPrivate'),
|
|
|
|
password = model.get('password');
|
2014-06-24 10:33:24 +04:00
|
|
|
|
|
|
|
if (!validator.isLength(title, 0, 150)) {
|
2014-10-25 01:09:50 +04:00
|
|
|
validationErrors.push({message: 'Title is too long'});
|
2014-06-24 10:33:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!validator.isLength(description, 0, 200)) {
|
2014-10-25 01:09:50 +04:00
|
|
|
validationErrors.push({message: 'Description is too long'});
|
2014-06-24 10:33:24 +04:00
|
|
|
}
|
|
|
|
|
2015-05-11 18:35:55 +03:00
|
|
|
if (isPrivate && password === '') {
|
|
|
|
validationErrors.push({message: 'Password must be supplied'});
|
|
|
|
}
|
|
|
|
|
2014-08-08 06:58:25 +04:00
|
|
|
if (postsPerPage > 1000) {
|
2014-10-25 01:09:50 +04:00
|
|
|
validationErrors.push({message: 'The maximum number of posts per page is 1000'});
|
2014-06-24 10:33:24 +04:00
|
|
|
}
|
|
|
|
|
2014-08-08 06:58:25 +04:00
|
|
|
if (postsPerPage < 1) {
|
2014-10-25 01:09:50 +04:00
|
|
|
validationErrors.push({message: 'The minimum number of posts per page is 1'});
|
2014-08-08 06:58:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!validator.isInt(postsPerPage)) {
|
2014-10-25 01:09:50 +04:00
|
|
|
validationErrors.push({message: 'Posts per page must be a number'});
|
2014-06-24 10:33:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return validationErrors;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default SettingValidator;
|