2022-01-17 13:05:27 +03:00
|
|
|
import AdminRoute from 'ghost-admin/routes/admin';
|
2022-09-09 17:05:35 +03:00
|
|
|
import ConfirmUnsavedChangesModal from '../components/modals/confirm-unsaved-changes';
|
2020-05-20 16:55:41 +03:00
|
|
|
import {action} from '@ember/object';
|
2019-10-10 15:36:33 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
|
|
|
|
2022-01-17 13:05:27 +03:00
|
|
|
export default class MembersRoute extends AdminRoute {
|
2022-01-26 13:55:05 +03:00
|
|
|
@service feature;
|
2022-09-09 17:05:35 +03:00
|
|
|
@service modals;
|
2020-05-20 16:55:41 +03:00
|
|
|
@service router;
|
2019-10-10 15:36:33 +03:00
|
|
|
|
2023-05-04 12:11:08 +03:00
|
|
|
queryParams = {
|
|
|
|
postAnalytics: {refreshModel: false}
|
|
|
|
};
|
|
|
|
|
2020-05-20 16:55:41 +03:00
|
|
|
_requiresBackgroundRefresh = true;
|
2019-12-12 16:35:52 +03:00
|
|
|
|
2021-08-31 11:37:44 +03:00
|
|
|
constructor() {
|
|
|
|
super(...arguments);
|
2019-10-10 15:36:33 +03:00
|
|
|
this.router.on('routeWillChange', (transition) => {
|
2022-08-03 12:13:16 +03:00
|
|
|
this.closeImpersonateModal(transition);
|
2019-10-10 15:36:33 +03:00
|
|
|
});
|
2020-05-20 16:55:41 +03:00
|
|
|
}
|
2019-10-10 15:36:33 +03:00
|
|
|
|
2019-04-16 18:02:43 +03:00
|
|
|
model(params) {
|
2019-12-12 16:35:52 +03:00
|
|
|
this._requiresBackgroundRefresh = false;
|
|
|
|
|
|
|
|
if (params.member_id) {
|
2022-05-11 20:11:54 +03:00
|
|
|
return this.store.queryRecord('member', {id: params.member_id, include: 'tiers'});
|
2019-12-12 16:35:52 +03:00
|
|
|
} else {
|
|
|
|
return this.store.createRecord('member');
|
|
|
|
}
|
2020-05-20 16:55:41 +03:00
|
|
|
}
|
2019-04-16 18:02:43 +03:00
|
|
|
|
2022-10-25 17:21:10 +03:00
|
|
|
setupController(controller, member, transition) {
|
2020-05-20 16:55:41 +03:00
|
|
|
super.setupController(...arguments);
|
2022-12-05 14:48:29 +03:00
|
|
|
|
|
|
|
controller.setInitialRelationshipValues();
|
|
|
|
|
2019-12-12 16:35:52 +03:00
|
|
|
if (this._requiresBackgroundRefresh) {
|
2022-10-07 19:03:45 +03:00
|
|
|
controller.fetchMemberTask.perform(member.id);
|
2019-04-16 18:02:43 +03:00
|
|
|
}
|
2022-10-25 17:21:10 +03:00
|
|
|
|
2022-10-27 18:24:57 +03:00
|
|
|
controller.directlyFromAnalytics = false;
|
2022-10-26 15:32:31 +03:00
|
|
|
if (transition.from?.name === 'posts.analytics') {
|
2022-10-27 18:24:57 +03:00
|
|
|
controller.directlyFromAnalytics = true;
|
2023-05-04 12:11:08 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resetController(controller, isExiting) {
|
|
|
|
super.resetController(...arguments);
|
|
|
|
|
|
|
|
// Make sure we clear
|
|
|
|
if (isExiting && controller.postAnalytics) {
|
|
|
|
controller.set('postAnalytics', null);
|
|
|
|
controller.set('directlyFromAnalytics', false);
|
2022-10-25 17:21:10 +03:00
|
|
|
}
|
2020-05-20 16:55:41 +03:00
|
|
|
}
|
2019-04-16 18:02:43 +03:00
|
|
|
|
|
|
|
deactivate() {
|
2019-12-12 16:35:52 +03:00
|
|
|
this._requiresBackgroundRefresh = true;
|
2022-09-09 17:05:35 +03:00
|
|
|
|
|
|
|
this.confirmModal = null;
|
|
|
|
this.hasConfirmed = false;
|
2020-05-20 16:55:41 +03:00
|
|
|
}
|
2019-01-24 22:34:32 +03:00
|
|
|
|
2020-05-20 16:55:41 +03:00
|
|
|
@action
|
|
|
|
save() {
|
|
|
|
this.controller.save();
|
|
|
|
}
|
2019-10-10 15:36:33 +03:00
|
|
|
|
2022-09-09 17:05:35 +03:00
|
|
|
@action
|
|
|
|
async willTransition(transition) {
|
2022-10-21 23:05:14 +03:00
|
|
|
let hasDirtyAttributes = this.controller.dirtyAttributes;
|
2019-10-10 15:36:33 +03:00
|
|
|
|
2022-09-09 17:05:35 +03:00
|
|
|
// wait for any existing confirm modal to be closed before allowing transition
|
|
|
|
if (this.confirmModal) {
|
|
|
|
return;
|
|
|
|
}
|
2019-12-12 16:35:52 +03:00
|
|
|
|
2022-10-21 23:05:14 +03:00
|
|
|
if (!this.hasConfirmed && hasDirtyAttributes) {
|
|
|
|
transition.abort();
|
2022-09-09 17:05:35 +03:00
|
|
|
|
2022-10-21 23:05:14 +03:00
|
|
|
if (this.controller.saveTask?.isRunning) {
|
|
|
|
await this.controller.saveTask.last;
|
|
|
|
transition.retry();
|
|
|
|
}
|
2022-09-09 17:05:35 +03:00
|
|
|
|
2022-10-21 23:05:14 +03:00
|
|
|
const shouldLeave = await this.confirmUnsavedChanges();
|
|
|
|
|
|
|
|
if (shouldLeave) {
|
|
|
|
this.controller.model.rollbackAttributes();
|
|
|
|
this.hasConfirmed = true;
|
|
|
|
return transition.retry();
|
|
|
|
}
|
2022-09-09 17:05:35 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async confirmUnsavedChanges() {
|
2022-10-21 23:05:14 +03:00
|
|
|
this.confirmModal = this.modals
|
|
|
|
.open(ConfirmUnsavedChangesModal)
|
|
|
|
.finally(() => {
|
|
|
|
this.confirmModal = null;
|
|
|
|
});
|
2022-09-09 17:05:35 +03:00
|
|
|
|
2022-10-21 23:05:14 +03:00
|
|
|
return this.confirmModal;
|
2019-01-24 22:34:32 +03:00
|
|
|
}
|
2022-08-03 12:13:16 +03:00
|
|
|
|
|
|
|
closeImpersonateModal(transition) {
|
2022-09-09 17:05:35 +03:00
|
|
|
// If user navigates away with forward or back button, ensure returning to page
|
2022-08-03 12:13:16 +03:00
|
|
|
// hides modal
|
|
|
|
if (transition.from && transition.from.name === this.routeName && transition.targetName) {
|
|
|
|
let {controller} = this;
|
|
|
|
|
|
|
|
controller.closeImpersonateMemberModal(transition);
|
|
|
|
}
|
|
|
|
}
|
2022-09-09 17:05:35 +03:00
|
|
|
|
|
|
|
titleToken() {
|
|
|
|
return this.controller.member.name;
|
|
|
|
}
|
2020-05-20 16:55:41 +03:00
|
|
|
}
|