mirror of
https://github.com/TryGhost/Ghost-Admin.git
synced 2023-12-14 02:33:04 +01:00
37a23122c2
no issue - minor reduction in build size. Before/after: - `vendor.min.js 3.32 MB (710.66 KB gzipped)` - `vendor.min.js 3.29 MB (706 KB gzipped)`
59 lines
1.9 KiB
JavaScript
59 lines
1.9 KiB
JavaScript
import BaseValidator from './base';
|
|
import validator from 'validator';
|
|
import {isBlank} from '@ember/utils';
|
|
|
|
export default BaseValidator.create({
|
|
properties: ['name', 'slug', 'description', 'metaTitle', 'metaDescription'],
|
|
|
|
name(model) {
|
|
let name = model.get('name');
|
|
|
|
if (isBlank(name)) {
|
|
model.get('errors').add('name', 'You must specify a name for the tag.');
|
|
this.invalidate();
|
|
} else if (name.match(/^,/)) {
|
|
model.get('errors').add('name', 'Tag names can\'t start with commas.');
|
|
this.invalidate();
|
|
} else if (!validator.isLength(name, 0, 191)) {
|
|
model.get('errors').add('name', 'Tag names cannot be longer than 191 characters.');
|
|
this.invalidate();
|
|
}
|
|
},
|
|
|
|
slug(model) {
|
|
let slug = model.get('slug');
|
|
|
|
if (!validator.isLength(slug || '', 0, 191)) {
|
|
model.get('errors').add('slug', 'URL cannot be longer than 191 characters.');
|
|
this.invalidate();
|
|
}
|
|
},
|
|
|
|
description(model) {
|
|
let description = model.get('description');
|
|
|
|
if (!validator.isLength(description || '', 0, 500)) {
|
|
model.get('errors').add('description', 'Description cannot be longer than 500 characters.');
|
|
this.invalidate();
|
|
}
|
|
},
|
|
|
|
metaTitle(model) {
|
|
let metaTitle = model.get('metaTitle');
|
|
|
|
if (!validator.isLength(metaTitle || '', 0, 300)) {
|
|
model.get('errors').add('metaTitle', 'Meta Title cannot be longer than 300 characters.');
|
|
this.invalidate();
|
|
}
|
|
},
|
|
|
|
metaDescription(model) {
|
|
let metaDescription = model.get('metaDescription');
|
|
|
|
if (!validator.isLength(metaDescription || '', 0, 500)) {
|
|
model.get('errors').add('metaDescription', 'Meta Description cannot be longer than 500 characters.');
|
|
this.invalidate();
|
|
}
|
|
}
|
|
});
|