2020-10-22 13:39:00 +03:00
|
|
|
import Controller from '@ember/controller';
|
2021-05-05 18:59:18 +03:00
|
|
|
import {action} from '@ember/object';
|
2020-10-22 13:39:00 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
2021-05-05 18:59:18 +03:00
|
|
|
import {task} from 'ember-concurrency-decorators';
|
|
|
|
import {tracked} from '@glimmer/tracking';
|
2020-10-22 13:39:00 +03:00
|
|
|
|
2021-05-05 18:59:18 +03:00
|
|
|
export default class MembersEmailController extends Controller {
|
|
|
|
@service config;
|
|
|
|
@service session;
|
|
|
|
@service settings;
|
2020-10-22 13:39:00 +03:00
|
|
|
|
2021-05-07 12:02:19 +03:00
|
|
|
queryParams = ['emailRecipientsOpen']
|
|
|
|
|
2021-05-05 18:59:18 +03:00
|
|
|
// 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 = '';
|
2020-10-22 13:39:00 +03:00
|
|
|
|
2021-05-07 12:02:19 +03:00
|
|
|
@tracked emailRecipientsOpen = false;
|
2021-05-05 18:59:18 +03:00
|
|
|
@tracked showLeaveSettingsModal = false;
|
2020-10-22 13:39:00 +03:00
|
|
|
|
2021-05-05 18:59:18 +03:00
|
|
|
@action
|
|
|
|
setEmailAddress(property, email) {
|
|
|
|
this[property] = email;
|
|
|
|
}
|
2020-10-22 13:39:00 +03:00
|
|
|
|
2021-05-07 12:02:19 +03:00
|
|
|
@action
|
|
|
|
toggleEmailRecipientsOpen() {
|
|
|
|
this.emailRecipientsOpen = !this.emailRecipientsOpen;
|
|
|
|
}
|
|
|
|
|
2021-05-05 18:59:18 +03:00
|
|
|
leaveRoute(transition) {
|
|
|
|
if (this.settings.get('hasDirtyAttributes')) {
|
|
|
|
transition.abort();
|
|
|
|
this.leaveSettingsTransition = transition;
|
|
|
|
this.showLeaveSettingsModal = true;
|
|
|
|
}
|
|
|
|
}
|
2020-10-22 13:39:00 +03:00
|
|
|
|
2021-05-05 18:59:18 +03:00
|
|
|
@action
|
|
|
|
async confirmLeave() {
|
|
|
|
this.settings.rollbackAttributes();
|
|
|
|
this.showLeaveSettingsModal = false;
|
|
|
|
this.leaveSettingsTransition.retry();
|
|
|
|
}
|
2020-10-22 13:39:00 +03:00
|
|
|
|
2021-05-05 18:59:18 +03:00
|
|
|
@action
|
|
|
|
cancelLeave() {
|
|
|
|
this.showLeaveSettingsModal = false;
|
|
|
|
this.leaveSettingsTransition = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
get blogDomain() {
|
2020-10-22 13:39:00 +03:00
|
|
|
let blogDomain = this.config.blogDomain || '';
|
|
|
|
const domainExp = blogDomain.replace('https://', '').replace('http://', '').match(new RegExp('^([^/:?#]+)(?:[/:?#]|$)', 'i'));
|
2021-03-24 21:15:10 +03:00
|
|
|
const domain = (domainExp && domainExp[1]) || '';
|
|
|
|
if (domain.startsWith('www.')) {
|
|
|
|
return domain.replace(/^(www)\.(?=[^/]*\..{2,5})/, '');
|
|
|
|
}
|
|
|
|
return domain;
|
2021-05-05 18:59:18 +03:00
|
|
|
}
|
2020-10-22 13:39:00 +03:00
|
|
|
|
|
|
|
parseEmailAddress(address) {
|
|
|
|
const emailAddress = address || 'noreply';
|
|
|
|
// Adds default domain as site domain
|
|
|
|
if (emailAddress.indexOf('@') < 0 && this.blogDomain) {
|
|
|
|
return `${emailAddress}@${this.blogDomain}`;
|
|
|
|
}
|
|
|
|
return emailAddress;
|
2021-05-05 18:59:18 +03:00
|
|
|
}
|
2020-10-22 13:39:00 +03:00
|
|
|
|
2021-05-05 18:59:18 +03:00
|
|
|
resetEmailAddresses() {
|
|
|
|
this.fromAddress = this.parseEmailAddress(this.settings.get('membersFromAddress'));
|
|
|
|
this.supportAddress = this.parseEmailAddress(this.settings.get('membersSupportAddress'));
|
|
|
|
}
|
|
|
|
|
|
|
|
@task({drop: true})
|
|
|
|
*saveSettings() {
|
2020-10-22 13:39:00 +03:00
|
|
|
const response = yield this.settings.save();
|
2021-05-05 18:59:18 +03:00
|
|
|
this.resetEmailAddresses();
|
2020-10-22 13:39:00 +03:00
|
|
|
return response;
|
|
|
|
}
|
2021-05-05 18:59:18 +03:00
|
|
|
}
|