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';
|
2021-09-14 21:32:07 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
|
|
|
|
2021-10-04 18:34:13 +03:00
|
|
|
export default class SettingsDesignRoute extends AuthenticatedRoute {
|
2021-09-28 18:12:01 +03:00
|
|
|
@service customThemeSettings;
|
2021-09-14 21:32:07 +03:00
|
|
|
@service feature;
|
|
|
|
@service modals;
|
2021-09-16 22:26:49 +03:00
|
|
|
@service settings;
|
2021-10-11 17:24:46 +03:00
|
|
|
@service ui;
|
2021-09-14 21:32:07 +03:00
|
|
|
|
2021-09-17 20:26:58 +03:00
|
|
|
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');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-04 18:34:13 +03:00
|
|
|
model() {
|
|
|
|
return this.settings.reload();
|
|
|
|
}
|
|
|
|
|
2021-09-14 21:32:07 +03:00
|
|
|
activate() {
|
2021-10-11 17:24:46 +03:00
|
|
|
this.ui.contextualNavMenu = 'design';
|
2021-09-14 21:32:07 +03:00
|
|
|
}
|
|
|
|
|
2021-09-16 22:26:49 +03:00
|
|
|
@action
|
2021-10-05 22:44:27 +03:00
|
|
|
willTransition(transition) {
|
|
|
|
if (this.hasConfirmed) {
|
|
|
|
return true;
|
|
|
|
}
|
2021-09-16 22:26:49 +03:00
|
|
|
|
2021-10-05 22:44:27 +03:00
|
|
|
// always abort when not confirmed because Ember's router doesn't automatically wait on promises
|
|
|
|
transition.abort();
|
2021-09-16 22:26:49 +03:00
|
|
|
|
2021-10-05 22:44:27 +03:00
|
|
|
this.confirmUnsavedChanges().then((shouldLeave) => {
|
2021-09-16 22:26:49 +03:00
|
|
|
if (shouldLeave) {
|
2021-10-05 22:44:27 +03:00
|
|
|
this.hasConfirmed = true;
|
2021-09-16 22:26:49 +03:00
|
|
|
return transition.retry();
|
|
|
|
}
|
2021-10-05 22:44:27 +03:00
|
|
|
});
|
2021-09-16 22:26:49 +03:00
|
|
|
}
|
|
|
|
|
2021-09-14 21:32:07 +03:00
|
|
|
deactivate() {
|
2021-10-11 17:24:46 +03:00
|
|
|
this.ui.contextualNavMenu = null;
|
2021-09-16 22:26:49 +03:00
|
|
|
this.confirmModal = null;
|
2021-09-17 20:26:58 +03:00
|
|
|
this.hasConfirmed = false;
|
2021-09-16 22:26:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
confirmUnsavedChanges() {
|
2021-09-28 18:12:01 +03:00
|
|
|
if (!this.settings.get('hasDirtyAttributes') && !this.customThemeSettings.isDirty) {
|
2021-09-16 22:26:49 +03:00
|
|
|
return Promise.resolve(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.confirmModal) {
|
2021-10-05 13:19:52 +03:00
|
|
|
this.confirmModal = this.modals.open('modals/confirm-unsaved-changes')
|
|
|
|
.then((discardChanges) => {
|
|
|
|
if (discardChanges === true) {
|
|
|
|
this.settings.rollbackAttributes();
|
|
|
|
this.customThemeSettings.rollback();
|
|
|
|
}
|
|
|
|
return discardChanges;
|
|
|
|
}).finally(() => {
|
|
|
|
this.confirmModal = null;
|
|
|
|
});
|
2021-09-16 22:26:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return this.confirmModal;
|
2021-09-14 21:32:07 +03:00
|
|
|
}
|
|
|
|
}
|