2020-10-15 20:03:18 +03:00
|
|
|
import BaseValidator from './base';
|
2020-10-16 21:21:42 +03:00
|
|
|
import validator from 'validator';
|
2020-10-15 20:03:18 +03:00
|
|
|
import {isBlank} from '@ember/utils';
|
|
|
|
|
|
|
|
export default BaseValidator.create({
|
2020-10-16 12:15:07 +03:00
|
|
|
properties: ['name', 'mobiledoc'],
|
2020-10-15 20:03:18 +03:00
|
|
|
|
2020-10-16 12:15:07 +03:00
|
|
|
name(model) {
|
2020-10-16 21:21:42 +03:00
|
|
|
let {name} = model;
|
|
|
|
|
|
|
|
if (!validator.isLength(name || '', 0, 191)) {
|
|
|
|
model.errors.add('name', 'Name cannot be longer than 191 characters');
|
|
|
|
this.invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isBlank(name)) {
|
2020-10-16 12:15:07 +03:00
|
|
|
model.errors.add('name', 'Name cannot be blank');
|
2020-10-15 20:03:18 +03:00
|
|
|
this.invalidate();
|
|
|
|
}
|
2020-10-16 21:21:42 +03:00
|
|
|
|
2020-10-16 12:15:07 +03:00
|
|
|
model.get('hasValidated').addObject('name');
|
2020-10-15 20:03:18 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
mobiledoc(model) {
|
|
|
|
if (isBlank(model.get('mobiledoc'))) {
|
|
|
|
model.errors.add('mobiledoc', 'Content cannot be blank.');
|
|
|
|
this.invalidate();
|
|
|
|
}
|
|
|
|
model.get('hasValidated').addObject('mobiledoc');
|
|
|
|
}
|
|
|
|
});
|