Ghost/ghost/admin/app/controllers/settings/members-email.js
Peter Zimon 04d9caefed Updated navigation (#1832)
no issue

Updated settings navigation to a completely redesigned flow for Ghost 4.0 🎉

Co-authored-by: Kevin Ansfield <kevin@lookingsideways.co.uk>
Co-authored-by: Fabien O'Carroll <fabien@allou.is>
Co-authored-by: Rish <zrishabhgarg@gmail.com>
2021-02-02 16:08:06 +00:00

79 lines
2.3 KiB
JavaScript

/* eslint-disable ghost/ember/alias-model-in-controller */
import Controller from '@ember/controller';
import {computed} from '@ember/object';
import {inject as service} from '@ember/service';
import {task} from 'ember-concurrency';
export default Controller.extend({
ajax: service(),
config: service(),
feature: service(),
ghostPaths: service(),
notifications: service(),
session: service(),
settings: service(),
queryParams: ['fromAddressUpdate', 'supportAddressUpdate'],
fromAddressUpdate: null,
supportAddressUpdate: null,
importErrors: null,
importSuccessful: false,
showDeleteAllModal: false,
submitting: false,
uploadButtonText: 'Import',
importMimeType: null,
jsonExtension: null,
jsonMimeType: null,
yamlExtension: null,
yamlMimeType: null,
yamlAccept: null,
init() {
this._super(...arguments);
},
fromAddress: computed(function () {
return this.parseEmailAddress(this.settings.get('membersFromAddress'));
}),
supportAddress: computed(function () {
return this.parseEmailAddress(this.settings.get('membersSupportAddress'));
}),
blogDomain: computed('config.blogDomain', function () {
let blogDomain = this.config.blogDomain || '';
const domainExp = blogDomain.replace('https://', '').replace('http://', '').match(new RegExp('^([^/:?#]+)(?:[/:?#]|$)', 'i'));
return (domainExp && domainExp[1]) || '';
}),
actions: {
setEmailAddress(type, emailAddress) {
this.set(type, emailAddress);
}
},
parseEmailAddress(address) {
const emailAddress = address || 'noreply';
// Adds default domain as site domain
if (emailAddress.indexOf('@') < 0 && this.blogDomain) {
return `${emailAddress}@${this.blogDomain}`;
}
return emailAddress;
},
saveSettings: task(function* () {
const response = yield this.settings.save();
// Reset from address value on save
this.set('fromAddress', this.parseEmailAddress(this.settings.get('membersFromAddress')));
this.set('supportAddress', this.parseEmailAddress(this.settings.get('membersSupportAddress')));
return response;
}).drop(),
reset() {
this.set('fromAddressUpdate', null);
this.set('supportAddressUpdate', null);
}
});