2022-01-17 13:05:27 +03:00
|
|
|
import AdminRoute from 'ghost-admin/routes/admin';
|
2022-09-09 19:13:07 +03:00
|
|
|
import ConfirmUnsavedChangesModal from '../../../components/modals/confirm-unsaved-changes';
|
|
|
|
import {action} from '@ember/object';
|
2021-10-18 15:46:29 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
|
|
|
|
2022-09-09 19:13:07 +03:00
|
|
|
export default class UnsplashIntegrationRoute extends AdminRoute {
|
|
|
|
@service modals;
|
|
|
|
@service settings;
|
2021-10-18 15:46:29 +03:00
|
|
|
|
2022-09-09 19:13:07 +03:00
|
|
|
model() {
|
|
|
|
this.settings.reload();
|
|
|
|
}
|
|
|
|
|
|
|
|
deactivate() {
|
|
|
|
this.confirmModal = null;
|
|
|
|
this.hasConfirmed = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@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;
|
|
|
|
}
|
2021-10-18 15:46:29 +03:00
|
|
|
|
2022-09-09 19:13:07 +03:00
|
|
|
if (this.controller.saveTask?.isRunning) {
|
|
|
|
await this.controller.saveTask.last;
|
|
|
|
}
|
|
|
|
|
|
|
|
const shouldLeave = await this.confirmUnsavedChanges();
|
2021-10-18 15:46:29 +03:00
|
|
|
|
2022-09-09 19:13:07 +03:00
|
|
|
if (shouldLeave) {
|
|
|
|
this.settings.rollbackAttributes();
|
|
|
|
this.hasConfirmed = true;
|
|
|
|
return transition.retry();
|
|
|
|
}
|
|
|
|
}
|
2021-10-18 15:46:29 +03:00
|
|
|
|
2022-09-09 19:13:07 +03:00
|
|
|
async confirmUnsavedChanges() {
|
2022-10-07 16:23:21 +03:00
|
|
|
if (this.settings.hasDirtyAttributes) {
|
2022-09-09 19:13:07 +03:00
|
|
|
this.confirmModal = this.modals
|
|
|
|
.open(ConfirmUnsavedChangesModal)
|
|
|
|
.finally(() => {
|
|
|
|
this.confirmModal = null;
|
|
|
|
});
|
2021-10-18 15:46:29 +03:00
|
|
|
|
2022-09-09 19:13:07 +03:00
|
|
|
return this.confirmModal;
|
2021-10-18 15:46:29 +03:00
|
|
|
}
|
2022-09-09 19:13:07 +03:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
save() {
|
|
|
|
this.controller.send('save');
|
|
|
|
}
|
2021-10-18 15:46:29 +03:00
|
|
|
|
|
|
|
buildRouteInfoMetadata() {
|
|
|
|
return {
|
|
|
|
titleToken: 'Unsplash'
|
|
|
|
};
|
|
|
|
}
|
2022-09-09 19:13:07 +03:00
|
|
|
}
|