Ghost/ghost/admin/app/components/modals/delete-post.js
Kevin Ansfield 9d67980a7e Refactor modals
refs #5798, closes #5018
- adds new `gh-fullscreen-modal` component - modals are now specified in-context so that they can have deeper interaction with their surrounding components/controller/route, i.e. a modal component can be a thin confirm/deny wrapper over the underlying controller action keeping all context-sensitive logic in one place
- adds spin-buttons to all modals with async behaviour
- adds/improves behaviour of inline-validation in modals
- improves re-authenticate modal to properly handle validation and authentication errors
2016-01-12 20:53:08 +00:00

52 lines
1.2 KiB
JavaScript

import Ember from 'ember';
import ModalComponent from 'ghost/components/modals/base';
const {computed, inject} = Ember;
const {alias} = computed;
export default ModalComponent.extend({
submitting: false,
post: alias('model'),
notifications: inject.service(),
routing: inject.service('-routing'),
_deletePost() {
let post = this.get('post');
// definitely want to clear the data store and post of any unsaved,
// client-generated tags
post.updateTags();
return post.destroyRecord();
},
_success() {
// clear any previous error messages
this.get('notifications').closeAlerts('post.delete');
// redirect to content screen
this.get('routing').transitionTo('posts');
},
_failure() {
this.get('notifications').showAlert('Your post could not be deleted. Please try again.', {type: 'error', key: 'post.delete.failed'});
},
actions: {
confirm() {
this.set('submitting', true);
this._deletePost().then(() => {
this._success();
}, () => {
this._failure();
}).finally(() => {
this.send('closeModal');
});
}
}
});