mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-24 03:14:03 +03:00
7b340929ef
no issue - simplified query params as they are only used to display a notification - removed all controller knowledge and associated reset behaviour for query params - moved notification display from `setupController` to `beforeModel` so the raw query params can be pulled off of the transition object - removed unused service injections from `<GhMembersEmailSetting>` - removed unused service injections and properties from members-email controller that were left over from a copy/paste - converted members-email controller to a native class - fixed "leave settings" confirmation modal behaviour that wasn't moved across in the the settings screen re-org
76 lines
2.3 KiB
JavaScript
76 lines
2.3 KiB
JavaScript
import Controller from '@ember/controller';
|
|
import {action} from '@ember/object';
|
|
import {inject as service} from '@ember/service';
|
|
import {task} from 'ember-concurrency-decorators';
|
|
import {tracked} from '@glimmer/tracking';
|
|
|
|
export default class MembersEmailController extends Controller {
|
|
@service config;
|
|
@service session;
|
|
@service settings;
|
|
|
|
// from/supportAddress are set here so that they can be reset to saved values on save
|
|
// to avoid it looking like they've been saved when they have a separate update process
|
|
@tracked fromAddress = '';
|
|
@tracked supportAddress = '';
|
|
|
|
@tracked showLeaveSettingsModal = false;
|
|
|
|
@action
|
|
setEmailAddress(property, email) {
|
|
this[property] = email;
|
|
}
|
|
|
|
leaveRoute(transition) {
|
|
if (this.settings.get('hasDirtyAttributes')) {
|
|
transition.abort();
|
|
this.leaveSettingsTransition = transition;
|
|
this.showLeaveSettingsModal = true;
|
|
}
|
|
}
|
|
|
|
@action
|
|
async confirmLeave() {
|
|
this.settings.rollbackAttributes();
|
|
this.showLeaveSettingsModal = false;
|
|
this.leaveSettingsTransition.retry();
|
|
}
|
|
|
|
@action
|
|
cancelLeave() {
|
|
this.showLeaveSettingsModal = false;
|
|
this.leaveSettingsTransition = null;
|
|
}
|
|
|
|
get blogDomain() {
|
|
let blogDomain = this.config.blogDomain || '';
|
|
const domainExp = blogDomain.replace('https://', '').replace('http://', '').match(new RegExp('^([^/:?#]+)(?:[/:?#]|$)', 'i'));
|
|
const domain = (domainExp && domainExp[1]) || '';
|
|
if (domain.startsWith('www.')) {
|
|
return domain.replace(/^(www)\.(?=[^/]*\..{2,5})/, '');
|
|
}
|
|
return domain;
|
|
}
|
|
|
|
parseEmailAddress(address) {
|
|
const emailAddress = address || 'noreply';
|
|
// Adds default domain as site domain
|
|
if (emailAddress.indexOf('@') < 0 && this.blogDomain) {
|
|
return `${emailAddress}@${this.blogDomain}`;
|
|
}
|
|
return emailAddress;
|
|
}
|
|
|
|
resetEmailAddresses() {
|
|
this.fromAddress = this.parseEmailAddress(this.settings.get('membersFromAddress'));
|
|
this.supportAddress = this.parseEmailAddress(this.settings.get('membersSupportAddress'));
|
|
}
|
|
|
|
@task({drop: true})
|
|
*saveSettings() {
|
|
const response = yield this.settings.save();
|
|
this.resetEmailAddresses();
|
|
return response;
|
|
}
|
|
}
|