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', 'metaTitle', 'metaDescription'],
|
|
|
|
|
|
|
|
title: function (model) {
|
|
|
|
var title = model.get('title');
|
2014-06-21 01:36:44 +04:00
|
|
|
|
2015-06-07 06:19:19 +03:00
|
|
|
if (validator.empty(title)) {
|
|
|
|
model.get('errors').add('title', 'You must specify a title for the post.');
|
|
|
|
this.invalidate();
|
2014-09-21 22:56:30 +04:00
|
|
|
}
|
2015-08-29 22:02:06 +03:00
|
|
|
|
|
|
|
if (!validator.isLength(title, 0, 150)) {
|
|
|
|
model.get('errors').add('title', 'Title cannot be longer than 150 characters.');
|
|
|
|
this.invalidate();
|
|
|
|
}
|
2015-06-07 06:19:19 +03:00
|
|
|
},
|
2014-09-21 22:56:30 +04:00
|
|
|
|
2015-06-07 06:19:19 +03:00
|
|
|
metaTitle: function (model) {
|
|
|
|
var metaTitle = model.get('meta_title');
|
|
|
|
|
|
|
|
if (!validator.isLength(metaTitle, 0, 150)) {
|
|
|
|
model.get('errors').add('meta_title', 'Meta Title cannot be longer than 150 characters.');
|
|
|
|
this.invalidate();
|
2014-09-21 22:56:30 +04:00
|
|
|
}
|
2015-06-07 06:19:19 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
metaDescription: function (model) {
|
|
|
|
var metaDescription = model.get('meta_description');
|
2014-09-21 22:56:30 +04:00
|
|
|
|
2015-06-07 06:19:19 +03:00
|
|
|
if (!validator.isLength(metaDescription, 0, 200)) {
|
|
|
|
model.get('errors').add('meta_description', 'Meta Description cannot be longer than 200 characters.');
|
|
|
|
this.invalidate();
|
|
|
|
}
|
2014-06-21 01:36:44 +04:00
|
|
|
}
|
|
|
|
});
|