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'],
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
title(model) {
|
|
|
|
let 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-10-28 14:36:45 +03:00
|
|
|
metaTitle(model) {
|
2016-01-23 21:12:22 +03:00
|
|
|
let metaTitle = model.get('metaTitle');
|
2015-06-07 06:19:19 +03:00
|
|
|
|
|
|
|
if (!validator.isLength(metaTitle, 0, 150)) {
|
2016-01-23 21:12:22 +03:00
|
|
|
model.get('errors').add('metaTitle', 'Meta Title cannot be longer than 150 characters.');
|
2015-06-07 06:19:19 +03:00
|
|
|
this.invalidate();
|
2014-09-21 22:56:30 +04:00
|
|
|
}
|
2015-06-07 06:19:19 +03:00
|
|
|
},
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
metaDescription(model) {
|
2016-01-23 21:12:22 +03:00
|
|
|
let metaDescription = model.get('metaDescription');
|
2014-09-21 22:56:30 +04:00
|
|
|
|
2015-06-07 06:19:19 +03:00
|
|
|
if (!validator.isLength(metaDescription, 0, 200)) {
|
2016-01-23 21:12:22 +03:00
|
|
|
model.get('errors').add('metaDescription', 'Meta Description cannot be longer than 200 characters.');
|
2015-06-07 06:19:19 +03:00
|
|
|
this.invalidate();
|
|
|
|
}
|
2014-06-21 01:36:44 +04:00
|
|
|
}
|
|
|
|
});
|