2017-09-11 10:41:17 +03:00
|
|
|
import ModalComponent from 'ghost-admin/components/modal-base';
|
2017-08-22 10:53:26 +03:00
|
|
|
import {alias} from '@ember/object/computed';
|
2017-10-30 12:38:01 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
2017-01-19 14:40:31 +03:00
|
|
|
import {task} from 'ember-concurrency';
|
2015-11-18 13:50:48 +03:00
|
|
|
|
|
|
|
export default ModalComponent.extend({
|
2018-01-11 20:43:23 +03:00
|
|
|
notifications: service(),
|
2015-11-18 13:50:48 +03:00
|
|
|
|
2017-02-03 21:35:13 +03:00
|
|
|
post: alias('model.post'),
|
|
|
|
onSuccess: alias('model.onSuccess'),
|
2015-11-18 13:50:48 +03:00
|
|
|
|
2018-01-11 20:43:23 +03:00
|
|
|
actions: {
|
|
|
|
confirm() {
|
2019-03-06 16:53:54 +03:00
|
|
|
this.deletePost.perform();
|
2018-01-11 20:43:23 +03:00
|
|
|
}
|
|
|
|
},
|
2015-11-18 13:50:48 +03:00
|
|
|
|
|
|
|
_deletePost() {
|
2019-03-06 16:53:54 +03:00
|
|
|
let post = this.post;
|
2015-11-18 13:50:48 +03:00
|
|
|
|
|
|
|
// 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
|
2019-03-06 16:53:54 +03:00
|
|
|
this.notifications.closeAlerts('post.delete');
|
2015-11-18 13:50:48 +03:00
|
|
|
|
2017-02-03 21:35:13 +03:00
|
|
|
// trigger the success action
|
2019-03-06 16:53:54 +03:00
|
|
|
if (this.onSuccess) {
|
|
|
|
this.onSuccess();
|
2017-02-03 21:35:13 +03:00
|
|
|
}
|
2015-11-18 13:50:48 +03:00
|
|
|
},
|
|
|
|
|
2016-06-14 14:46:24 +03:00
|
|
|
_failure(error) {
|
2019-03-06 16:53:54 +03:00
|
|
|
this.notifications.showAPIError(error, {key: 'post.delete.failed'});
|
2015-11-18 13:50:48 +03:00
|
|
|
},
|
|
|
|
|
2017-01-19 14:40:31 +03:00
|
|
|
deletePost: task(function* () {
|
|
|
|
try {
|
|
|
|
yield this._deletePost();
|
|
|
|
this._success();
|
|
|
|
} catch (e) {
|
|
|
|
this._failure(e);
|
|
|
|
} finally {
|
|
|
|
this.send('closeModal');
|
|
|
|
}
|
2018-01-11 20:43:23 +03:00
|
|
|
}).drop()
|
2015-11-18 13:50:48 +03:00
|
|
|
});
|