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