Ghost/ghost/admin/app/controllers/settings/members-email-labs.js
Kevin Ansfield d6487d3630 Created labs versions of members-email settings code
refs https://github.com/TryGhost/Team/issues/1441

- duplicated route/controller/template and component to `-labs` versions so larger changes and refactors can be made without affecting the GA code
- added redirect for `/settings/members-email -> /settings/members-email-labs` when `multipleNewsletters` flag is enabled
- cleaned up multiple-newsletters related code from the non-labs component
2022-03-31 11:06:21 +01:00

75 lines
2.2 KiB
JavaScript

import Controller from '@ember/controller';
import {action} from '@ember/object';
import {inject as service} from '@ember/service';
import {task} from 'ember-concurrency';
import {tracked} from '@glimmer/tracking';
export default class MembersEmailLabsController extends Controller {
@service config;
@service session;
@service settings;
queryParams = ['showEmailDesignSettings'];
// 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 showEmailDesignSettings = false;
@tracked showLeaveSettingsModal = false;
@action
setEmailAddress(property, email) {
this[property] = email;
}
@action
toggleEmailDesignSettings() {
this.showEmailDesignSettings = !this.showEmailDesignSettings;
}
leaveRoute(transition) {
if (this.settings.get('hasDirtyAttributes')) {
transition.abort();
this.leaveSettingsTransition = transition;
this.showLeaveSettingsModal = true;
}
this.showEmailDesignSettings = false;
}
@action
async confirmLeave() {
this.settings.rollbackAttributes();
this.showLeaveSettingsModal = false;
this.leaveSettingsTransition.retry();
}
@action
cancelLeave() {
this.showLeaveSettingsModal = false;
this.leaveSettingsTransition = null;
}
parseEmailAddress(address) {
const emailAddress = address || 'noreply';
// Adds default domain as site domain
if (emailAddress.indexOf('@') < 0 && this.config.emailDomain) {
return `${emailAddress}@${this.config.emailDomain}`;
}
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;
}
}