Ghost/core/client/validators/setting.js
Jason Williams b9f9c576ed Enable validation for settings/general screen
Closes #3036 Refs #3012
-Enable validation for settings/general
-Turn on functional tests for the validations
-Move notification closeAll calls so that notifications
 are cleared on attempted saves instead of just on
 successful saves
2014-06-24 13:32:47 +00:00

34 lines
1.1 KiB
JavaScript

var SettingValidator = Ember.Object.create({
validate: function (model) {
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;