mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-15 03:12:54 +03:00
34e15f0619
closes TryGhost/Ghost#9119, refs TryGhost/Ghost#8483 - Apps - AMP - Added `leave-settings-modal` component to Settings - Apps - AMP - Apps - Slack - Added `leave-settings-modal` component to Settings - Apps - Slack - Added a `triggerDirtyState` action that will uses a new Array with the input data to trigger the dirty state on the parent settings model - Apps - Unsplash - Added `leave-settings-modal` component to Settings - Apps - Unsplash - Used manual tracking of changes with using a custom `dirtyAttributes` property and a `rollbackValue` to manually rollback the `isActive` attribute on the model - Code injection - Added `leave-settings-modal` component to Settings - Code injection - Design - Added `leave-settings-modal` component to Settings - Design (only for navigation model) - Used manual tracking of changes with using a custom `dirtyAttributes` - Added an additional `updateLabel` action to underlying `gh-navitem` component which gets fired on the `focusOut` event, to detect changes on the label - Team - User - Added `leave-settings-modal` component to Team - User - Used manual tracking of changes with using a custom `dirtyAttributes` to track changes in slug and role properties
65 lines
2.0 KiB
JavaScript
65 lines
2.0 KiB
JavaScript
import Controller from '@ember/controller';
|
|
import {inject as service} from '@ember/service';
|
|
import {task} from 'ember-concurrency';
|
|
|
|
export default Controller.extend({
|
|
notifications: service(),
|
|
|
|
save: task(function* () {
|
|
let notifications = this.get('notifications');
|
|
|
|
try {
|
|
return yield this.get('model').save();
|
|
} catch (error) {
|
|
notifications.showAPIError(error, {key: 'code-injection.save'});
|
|
throw error;
|
|
}
|
|
}),
|
|
|
|
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('model');
|
|
|
|
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 model props
|
|
settings.rollbackAttributes();
|
|
|
|
return transition.retry();
|
|
}
|
|
|
|
}
|
|
});
|