2021-09-14 21:32:07 +03:00
|
|
|
import AuthenticatedRoute from 'ghost-admin/routes/authenticated';
|
2021-09-16 22:26:49 +03:00
|
|
|
import {action} from '@ember/object';
|
|
|
|
import {bind} from '@ember/runloop';
|
2021-09-14 21:32:07 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
|
|
|
|
|
|
|
export default class SettingsDesignCustomizeRoute extends AuthenticatedRoute {
|
|
|
|
@service feature;
|
|
|
|
@service modals;
|
2021-09-16 22:26:49 +03:00
|
|
|
@service settings;
|
2021-09-14 21:32:07 +03:00
|
|
|
|
2021-09-17 20:26:58 +03:00
|
|
|
customizeModal = null;
|
|
|
|
confirmModal = null;
|
|
|
|
hasConfirmed = false;
|
|
|
|
|
2021-09-14 21:32:07 +03:00
|
|
|
beforeModel() {
|
|
|
|
super.beforeModel(...arguments);
|
|
|
|
|
|
|
|
if (!this.session.user.isAdmin) {
|
|
|
|
return this.transitionTo('site');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.feature.customThemeSettings) {
|
|
|
|
return this.transitionTo('settings');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
activate() {
|
2021-09-17 12:27:43 +03:00
|
|
|
this.customizeModal = this.modals.open('modals/design/customize', {
|
|
|
|
saveTask: this.controllerFor('settings.design.customize').saveTask
|
|
|
|
}, {
|
2021-09-16 22:26:49 +03:00
|
|
|
className: 'fullscreen-modal-full-overlay fullscreen-modal-branding-modal',
|
|
|
|
beforeClose: bind(this, this.beforeModalClose)
|
2021-09-14 21:32:07 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-09-16 22:26:49 +03:00
|
|
|
@action
|
|
|
|
async willTransition(transition) {
|
|
|
|
if (this.settings.get('hasDirtyAttributes')) {
|
|
|
|
transition.abort();
|
|
|
|
|
|
|
|
const shouldLeave = await this.confirmUnsavedChanges();
|
2021-09-17 20:26:58 +03:00
|
|
|
this.hasConfirmed = true;
|
2021-09-16 22:26:49 +03:00
|
|
|
|
|
|
|
if (shouldLeave) {
|
|
|
|
return transition.retry();
|
|
|
|
}
|
|
|
|
} else {
|
2021-09-17 20:26:58 +03:00
|
|
|
this.hasConfirmed = true;
|
2021-09-16 22:26:49 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-14 21:32:07 +03:00
|
|
|
deactivate() {
|
2021-09-16 22:26:49 +03:00
|
|
|
this.customizeModal?.close();
|
|
|
|
this.customizeModal = null;
|
|
|
|
this.confirmModal = null;
|
2021-09-17 20:26:58 +03:00
|
|
|
this.hasConfirmed = false;
|
2021-09-16 22:26:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
async beforeModalClose() {
|
2021-09-17 20:26:58 +03:00
|
|
|
if (this.hasConfirmed) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-09-16 22:26:49 +03:00
|
|
|
const shouldLeave = await this.confirmUnsavedChanges();
|
|
|
|
|
|
|
|
if (shouldLeave === true) {
|
|
|
|
this.transitionTo('settings.design');
|
|
|
|
} else {
|
|
|
|
// prevent modal from closing
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
confirmUnsavedChanges() {
|
|
|
|
if (!this.settings.get('hasDirtyAttributes')) {
|
|
|
|
return Promise.resolve(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.confirmModal) {
|
|
|
|
this.confirmModal = this.modals.open('modals/confirm-unsaved-changes', {}, {
|
|
|
|
className: 'fullscreen-modal-action fullscreen-modal-wide'
|
|
|
|
}).then((discardChanges) => {
|
|
|
|
if (discardChanges === true) {
|
|
|
|
this.settings.rollbackAttributes();
|
|
|
|
}
|
|
|
|
return discardChanges;
|
|
|
|
}).finally(() => {
|
|
|
|
this.confirmModal = null;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.confirmModal;
|
2021-09-14 21:32:07 +03:00
|
|
|
}
|
|
|
|
}
|