mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-23 19:02:29 +03:00
d10da5a02b
refs https://github.com/TryGhost/Team/issues/1513 - `sender_name` is now nullable with a fallback to the site title - updated new-newsletter route - removed default setting of site title in `senderName` of the new newsletter instance - removed extra checks when showing unsaved changes modal as we no longer need to compare the `senderName` attribute against the site title - updated newsletter preview so the sender name falls back to the site title - updated sender name input placeholder to show the site title - removed not-empty validation - fixed the switch to "multiple newsletter" state in the background of the new-newsletter modal - problem was `displayingDefault` getter was looking at all active newsletters rather than just the filtered ones so it was counting the new-but-unsaved newsletter even though it wasn't displayed in the list - fixes layout glitch when the new-newsletter modal animates out after cancelling creation
73 lines
2.2 KiB
JavaScript
73 lines
2.2 KiB
JavaScript
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)) {
|
|
model.errors.add('name', 'Cannot be longer than 191 characters.');
|
|
this.invalidate();
|
|
}
|
|
|
|
model.hasValidated.addObject('name');
|
|
},
|
|
|
|
senderName(model) {
|
|
if (!validator.isLength(model.senderName || '', 0, 191)) {
|
|
model.errors.add('senderName', 'Cannot be longer than 191 characters.');
|
|
this.invalidate();
|
|
}
|
|
|
|
model.hasValidated.addObject('senderName');
|
|
},
|
|
|
|
senderEmail(model) {
|
|
if (model.senderEmail && !validator.isEmail(model.senderEmail)) {
|
|
model.errors.add('senderEmail', 'Invalid email.');
|
|
this.invalidate();
|
|
}
|
|
|
|
if (!validator.isLength(model.senderEmail || '', 0, 191)) {
|
|
model.errors.add('senderEmail', 'Cannot be longer than 191 characters.');
|
|
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();
|
|
}
|
|
|
|
if (!validator.isIn(model.senderReplyTo, ['newsletter', 'support'])) {
|
|
model.errors.add('senderReplyTo', 'Can only be set to "newsletter" or "support".');
|
|
this.invalidate();
|
|
}
|
|
|
|
model.hasValidated.addObject('senderReplyTo');
|
|
},
|
|
|
|
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');
|
|
}
|
|
});
|