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
|
|
|
|
2022-10-07 22:13:42 +03:00
|
|
|
model.hasValidated.addObject('name');
|
2020-10-15 20:03:18 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
mobiledoc(model) {
|
2022-10-07 22:13:42 +03:00
|
|
|
if (isBlank(model.mobiledoc)) {
|
2020-10-15 20:03:18 +03:00
|
|
|
model.errors.add('mobiledoc', 'Content cannot be blank.');
|
|
|
|
this.invalidate();
|
|
|
|
}
|
2022-10-07 22:13:42 +03:00
|
|
|
model.hasValidated.addObject('mobiledoc');
|
2020-10-15 20:03:18 +03:00
|
|
|
}
|
|
|
|
});
|