mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-19 08:31:43 +03:00
c85690fb12
refs https://github.com/TryGhost/Team/issues/1734 refs https://github.com/TryGhost/Team/issues/559 refs https://github.com/TryGhost/Ghost/issues/14101 - switches to newer modal patterns ready for later Ember upgrades
85 lines
2.3 KiB
JavaScript
85 lines
2.3 KiB
JavaScript
import AdminRoute from 'ghost-admin/routes/admin';
|
|
import ConfirmUnsavedChangesModal from '../../components/modals/confirm-unsaved-changes';
|
|
import {action} from '@ember/object';
|
|
import {inject as service} from '@ember/service';
|
|
|
|
export default class IntegrationRoute extends AdminRoute {
|
|
@service modals;
|
|
@service router;
|
|
|
|
constructor() {
|
|
super(...arguments);
|
|
this.router.on('routeWillChange', () => {
|
|
if (this.controller) {
|
|
this.controller.set('selectedApiKey', null);
|
|
this.controller.set('isApiKeyRegenerated', false);
|
|
}
|
|
});
|
|
}
|
|
|
|
model(params, transition) {
|
|
// use the integrations controller to fetch all integrations and pick
|
|
// out the one we want. Allows navigation back to integrations screen
|
|
// without a loading state
|
|
return this
|
|
.controllerFor('settings.integrations')
|
|
.integrationModelHook('id', params.integration_id, this, transition);
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
if (this.controller.saveTask?.isRunning) {
|
|
await this.controller.saveTask.last;
|
|
}
|
|
|
|
const shouldLeave = await this.confirmUnsavedChanges();
|
|
|
|
if (shouldLeave) {
|
|
this.controller.model.rollbackAttributes();
|
|
this.hasConfirmed = true;
|
|
return transition.retry();
|
|
}
|
|
}
|
|
|
|
async confirmUnsavedChanges() {
|
|
if (this.controller.model?.hasDirtyAttributes) {
|
|
this.confirmModal = this.modals
|
|
.open(ConfirmUnsavedChangesModal)
|
|
.finally(() => {
|
|
this.confirmModal = null;
|
|
});
|
|
|
|
return this.confirmModal;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
@action
|
|
save() {
|
|
this.controller.send('save');
|
|
}
|
|
|
|
buildRouteInfoMetadata() {
|
|
return {
|
|
titleToken: 'Settings - Integrations'
|
|
};
|
|
}
|
|
}
|