Ghost/ghost/admin/app/validators/setting.js
Kevin Ansfield 5c9a824d53 Standardize on var-less export default across ember app
no issue
- drops the `var Foo = Ember.Thing.extend({}); export default Foo;` syntax in favour of exporting directly, eg: `export default Ember.Thing.extend({})`
- discussion on this change [here](https://github.com/TryGhost/Ghost/pull/5340#issuecomment-105828423) and [here](https://github.com/TryGhost/Ghost/pull/5694#discussion-diff-37511606)
2015-10-06 10:59:50 +01:00

45 lines
1.5 KiB
JavaScript

import BaseValidator from './base';
export default BaseValidator.create({
properties: ['title', 'description', 'password', 'postsPerPage'],
title: function (model) {
var title = model.get('title');
if (!validator.isLength(title, 0, 150)) {
model.get('errors').add('title', 'Title is too long');
this.invalidate();
}
},
description: function (model) {
var desc = model.get('description');
if (!validator.isLength(desc, 0, 200)) {
model.get('errors').add('description', 'Description is too long');
this.invalidate();
}
},
password: function (model) {
var isPrivate = model.get('isPrivate'),
password = model.get('password');
if (isPrivate && password === '') {
model.get('errors').add('password', 'Password must be supplied');
this.invalidate();
}
},
postsPerPage: function (model) {
var postsPerPage = model.get('postsPerPage');
if (!validator.isInt(postsPerPage)) {
model.get('errors').add('postsPerPage', 'Posts per page must be a number');
this.invalidate();
} else if (postsPerPage > 1000) {
model.get('errors').add('postsPerPage', 'The maximum number of posts per page is 1000');
this.invalidate();
} else if (postsPerPage < 1) {
model.get('errors').add('postsPerPage', 'The minimum number of posts per page is 1');
this.invalidate();
}
}
});