Ghost/ghost/admin/app/controllers/settings/code-injection.js
Gabriel Csapo d51f2bcf23 [chore] migrate to eslint@8 and run --fix (#2256)
closes https://github.com/TryGhost/Admin/pull/2107

- updated related babel dependencies
- bumped eslint
- ran `yarn lint:js --fix`
- added eslint ignore comments for some required non-camel-case properties
2022-02-10 10:41:36 +00:00

71 lines
2.0 KiB
JavaScript

import classic from 'ember-classic-decorator';
import {action} from '@ember/object';
import {inject as service} from '@ember/service';
/* eslint-disable ghost/ember/alias-model-in-controller */
import Controller from '@ember/controller';
import {task} from 'ember-concurrency';
@classic
export default class CodeInjectionController extends Controller {
@service notifications;
@service settings;
@action
save() {
this.saveTask.perform();
}
@action
toggleLeaveSettingsModal(transition) {
let leaveTransition = this.leaveSettingsTransition;
if (!transition && this.showLeaveSettingsModal) {
this.set('leaveSettingsTransition', null);
this.set('showLeaveSettingsModal', false);
return;
}
if (!leaveTransition || transition.targetName === leaveTransition.targetName) {
this.set('leaveSettingsTransition', transition);
// if a save is running, wait for it to finish then transition
if (this.saveTask.isRunning) {
return this.saveTask.last.then(() => {
transition.retry();
});
}
// we genuinely have unsaved data, show the modal
this.set('showLeaveSettingsModal', true);
}
}
@action
leaveSettings() {
let transition = this.leaveSettingsTransition;
let settings = this.settings;
if (!transition) {
this.notifications.showAlert('Sorry, there was an error in the application. Please let the Ghost team know what happened.', {type: 'error'});
return;
}
// roll back changes on settings props
settings.rollbackAttributes();
return transition.retry();
}
@task(function* () {
let notifications = this.notifications;
try {
return yield this.settings.save();
} catch (error) {
notifications.showAPIError(error, {key: 'code-injection.save'});
throw error;
}
})
saveTask;
}