2022-01-17 13:05:27 +03:00
|
|
|
import AdminRoute from 'ghost-admin/routes/admin';
|
2022-09-09 18:50:05 +03:00
|
|
|
import ConfirmUnsavedChangesModal from '../../components/modals/confirm-unsaved-changes';
|
|
|
|
import {action} from '@ember/object';
|
2017-10-30 12:38:01 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
2015-01-11 22:55:52 +03:00
|
|
|
|
2022-09-09 18:50:05 +03:00
|
|
|
export default class NavigationRoute extends AdminRoute {
|
|
|
|
@service modals;
|
|
|
|
@service settings;
|
2015-01-11 22:55:52 +03:00
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
model() {
|
2022-09-09 18:50:05 +03:00
|
|
|
this.settings.reload();
|
|
|
|
}
|
2015-01-11 22:55:52 +03:00
|
|
|
|
2021-01-22 14:24:45 +03:00
|
|
|
setupController() {
|
2022-09-09 18:50:05 +03:00
|
|
|
this.controller.reset();
|
|
|
|
}
|
2016-02-09 20:16:18 +03:00
|
|
|
|
2019-12-13 20:09:06 +03:00
|
|
|
deactivate() {
|
2022-09-09 18:50:05 +03:00
|
|
|
this.confirmModal = null;
|
|
|
|
this.hasConfirmed = false;
|
|
|
|
this.controller.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
async willTransition(transition) {
|
|
|
|
if (this.hasConfirmed) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
transition.abort();
|
|
|
|
|
|
|
|
// wait for any existing confirm modal to be closed before allowing transition
|
|
|
|
if (this.confirmModal) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.controller.saveTask?.isRunning) {
|
|
|
|
await this.controller.saveTask.last;
|
|
|
|
}
|
|
|
|
|
|
|
|
const shouldLeave = await this.confirmUnsavedChanges();
|
|
|
|
|
|
|
|
if (shouldLeave) {
|
|
|
|
this.settings.rollbackAttributes();
|
|
|
|
this.hasConfirmed = true;
|
|
|
|
return transition.retry();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async confirmUnsavedChanges() {
|
|
|
|
if (this.controller.dirtyAttributes) {
|
|
|
|
this.confirmModal = this.modals
|
|
|
|
.open(ConfirmUnsavedChangesModal)
|
|
|
|
.finally(() => {
|
|
|
|
this.confirmModal = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
return this.confirmModal;
|
2015-01-14 17:46:29 +03:00
|
|
|
}
|
2022-09-09 18:50:05 +03:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
save() {
|
|
|
|
this.controller.send('save');
|
|
|
|
}
|
2019-05-20 18:16:19 +03:00
|
|
|
|
|
|
|
buildRouteInfoMetadata() {
|
|
|
|
return {
|
2021-01-28 18:25:21 +03:00
|
|
|
titleToken: 'Settings - Navigation'
|
2019-05-20 18:16:19 +03:00
|
|
|
};
|
2015-01-11 22:55:52 +03:00
|
|
|
}
|
2022-09-09 18:50:05 +03:00
|
|
|
}
|