2022-02-01 12:34:03 +03:00
|
|
|
import classic from 'ember-classic-decorator';
|
|
|
|
import {action} from '@ember/object';
|
|
|
|
import {inject as service} from '@ember/service';
|
2018-01-11 01:57:43 +03:00
|
|
|
/* eslint-disable ghost/ember/alias-model-in-controller */
|
2017-08-22 10:53:26 +03:00
|
|
|
import Controller from '@ember/controller';
|
2020-05-11 13:37:35 +03:00
|
|
|
import {task} from 'ember-concurrency';
|
2015-05-26 05:10:50 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@classic
|
|
|
|
export default class CodeInjectionController extends Controller {
|
2022-02-01 20:03:45 +03:00
|
|
|
@service notifications;
|
|
|
|
@service settings;
|
2017-10-31 18:27:25 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@action
|
|
|
|
save() {
|
|
|
|
this.saveTask.perform();
|
|
|
|
}
|
2017-10-31 18:27:25 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@action
|
|
|
|
toggleLeaveSettingsModal(transition) {
|
|
|
|
let leaveTransition = this.leaveSettingsTransition;
|
2017-10-31 18:27:25 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
if (!transition && this.showLeaveSettingsModal) {
|
|
|
|
this.set('leaveSettingsTransition', null);
|
|
|
|
this.set('showLeaveSettingsModal', false);
|
|
|
|
return;
|
|
|
|
}
|
2017-10-31 18:27:25 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
if (!leaveTransition || transition.targetName === leaveTransition.targetName) {
|
|
|
|
this.set('leaveSettingsTransition', transition);
|
2017-10-31 18:27:25 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
// if a save is running, wait for it to finish then transition
|
|
|
|
if (this.saveTask.isRunning) {
|
|
|
|
return this.saveTask.last.then(() => {
|
|
|
|
transition.retry();
|
|
|
|
});
|
2017-10-31 18:27:25 +03:00
|
|
|
}
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
// we genuinely have unsaved data, show the modal
|
|
|
|
this.set('showLeaveSettingsModal', true);
|
|
|
|
}
|
|
|
|
}
|
2017-10-31 18:27:25 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@action
|
|
|
|
leaveSettings() {
|
|
|
|
let transition = this.leaveSettingsTransition;
|
|
|
|
let settings = this.settings;
|
2017-10-31 18:27:25 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
if (!transition) {
|
|
|
|
this.notifications.showAlert('Sorry, there was an error in the application. Please let the Ghost team know what happened.', {type: 'error'});
|
|
|
|
return;
|
2017-05-18 13:48:37 +03:00
|
|
|
}
|
2017-10-31 18:27:25 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
// roll back changes on settings props
|
|
|
|
settings.rollbackAttributes();
|
|
|
|
|
|
|
|
return transition.retry();
|
|
|
|
}
|
2018-01-11 20:43:23 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@task(function* () {
|
2019-03-06 16:53:54 +03:00
|
|
|
let notifications = this.notifications;
|
2018-01-11 20:43:23 +03:00
|
|
|
|
|
|
|
try {
|
2019-03-06 16:53:54 +03:00
|
|
|
return yield this.settings.save();
|
2018-01-11 20:43:23 +03:00
|
|
|
} catch (error) {
|
|
|
|
notifications.showAPIError(error, {key: 'code-injection.save'});
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
})
|
2022-02-10 13:41:36 +03:00
|
|
|
saveTask;
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|