mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-15 03:12:54 +03:00
48e3bf003d
no issue - https://github.com/ember-cli/eslint-plugin-ember/blob/master/docs/rules/order-in-components.md - https://github.com/ember-cli/eslint-plugin-ember/blob/master/docs/rules/order-in-controllers.md - https://github.com/ember-cli/eslint-plugin-ember/blob/master/docs/rules/order-in-routes.md
67 lines
2.1 KiB
JavaScript
67 lines
2.1 KiB
JavaScript
/* eslint-disable ghost/ember/alias-model-in-controller */
|
|
import Controller from '@ember/controller';
|
|
import {inject as service} from '@ember/service';
|
|
import {task} from 'ember-concurrency';
|
|
|
|
export default Controller.extend({
|
|
notifications: service(),
|
|
settings: service(),
|
|
|
|
actions: {
|
|
save() {
|
|
this.get('save').perform();
|
|
},
|
|
|
|
toggleLeaveSettingsModal(transition) {
|
|
let leaveTransition = this.get('leaveSettingsTransition');
|
|
|
|
if (!transition && this.get('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.get('save.isRunning')) {
|
|
return this.get('save.last').then(() => {
|
|
transition.retry();
|
|
});
|
|
}
|
|
|
|
// we genuinely have unsaved data, show the modal
|
|
this.set('showLeaveSettingsModal', true);
|
|
}
|
|
},
|
|
|
|
leaveSettings() {
|
|
let transition = this.get('leaveSettingsTransition');
|
|
let settings = this.get('settings');
|
|
|
|
if (!transition) {
|
|
this.get('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();
|
|
}
|
|
|
|
},
|
|
|
|
save: task(function* () {
|
|
let notifications = this.get('notifications');
|
|
|
|
try {
|
|
return yield this.get('settings').save();
|
|
} catch (error) {
|
|
notifications.showAPIError(error, {key: 'code-injection.save'});
|
|
throw error;
|
|
}
|
|
})
|
|
});
|