2022-04-04 21:26:49 +03:00
|
|
|
import BaseValidator from './base';
|
|
|
|
import validator from 'validator';
|
|
|
|
import {isBlank} from '@ember/utils';
|
|
|
|
|
|
|
|
export default BaseValidator.create({
|
|
|
|
properties: ['name', 'senderName', 'senderEmail', 'senderReplyTo'],
|
|
|
|
|
|
|
|
name(model) {
|
|
|
|
if (isBlank(model.name)) {
|
|
|
|
model.errors.add('name', 'Please enter a name.');
|
|
|
|
this.invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!validator.isLength(model.name || '', 0, 191)) {
|
2022-04-12 16:01:27 +03:00
|
|
|
model.errors.add('name', 'Cannot be longer than 191 characters.');
|
2022-04-04 21:26:49 +03:00
|
|
|
this.invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
model.hasValidated.addObject('name');
|
|
|
|
},
|
|
|
|
|
|
|
|
senderName(model) {
|
|
|
|
if (isBlank(model.senderName)) {
|
|
|
|
model.errors.add('senderName', 'Please enter a sender name.');
|
|
|
|
this.invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!validator.isLength(model.senderName || '', 0, 191)) {
|
2022-04-12 16:01:27 +03:00
|
|
|
model.errors.add('senderName', 'Cannot be longer than 191 characters.');
|
2022-04-04 21:26:49 +03:00
|
|
|
this.invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
model.hasValidated.addObject('senderName');
|
|
|
|
},
|
|
|
|
|
|
|
|
senderEmail(model) {
|
2022-04-12 16:01:27 +03:00
|
|
|
if (model.senderEmail && !validator.isEmail(model.senderEmail)) {
|
2022-04-04 21:26:49 +03:00
|
|
|
model.errors.add('senderEmail', 'Invalid email.');
|
|
|
|
this.invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!validator.isLength(model.senderEmail || '', 0, 191)) {
|
2022-04-12 16:01:27 +03:00
|
|
|
model.errors.add('senderEmail', 'Cannot be longer than 191 characters.');
|
2022-04-04 21:26:49 +03:00
|
|
|
this.invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
model.hasValidated.addObject('senderEmail');
|
|
|
|
},
|
|
|
|
|
|
|
|
senderReplyTo(model) {
|
|
|
|
if (isBlank(model.senderReplyTo)) {
|
|
|
|
model.errors.add('senderReplyTo', 'Please enter a reply-to email address.');
|
|
|
|
this.invalidate();
|
|
|
|
}
|
|
|
|
|
2022-04-12 16:01:27 +03:00
|
|
|
if (!validator.isIn(model.senderReplyTo, ['newsletter', 'support'])) {
|
|
|
|
model.errors.add('senderReplyTo', 'Can only be set to "newsletter" or "support".');
|
2022-04-04 21:26:49 +03:00
|
|
|
this.invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
model.hasValidated.addObject('senderReplyTo');
|
2022-04-14 17:40:04 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
visibility(model) {
|
|
|
|
if (isBlank(model.visibility)) {
|
|
|
|
model.errors.add('visibility', 'Please enter visibility.');
|
|
|
|
this.invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!validator.isIn(model.senderReplyTo, ['members', 'paid'])) {
|
|
|
|
model.errors.add('visibility', 'Can only be set to "members" or "paid".');
|
|
|
|
this.invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
model.hasValidated.addObject('visibility');
|
2022-04-04 21:26:49 +03:00
|
|
|
}
|
|
|
|
});
|