From 1c2f6b97c355c83e7f51870be900d852feb956c2 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Tue, 18 Aug 2015 15:15:42 +0800 Subject: [PATCH] Use ajax-error in controller:topic. --- .../discourse/controllers/topic.js.es6 | 26 ++++--------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/app/assets/javascripts/discourse/controllers/topic.js.es6 b/app/assets/javascripts/discourse/controllers/topic.js.es6 index 71b0eabfb9f..e27e8a5e9a0 100644 --- a/app/assets/javascripts/discourse/controllers/topic.js.es6 +++ b/app/assets/javascripts/discourse/controllers/topic.js.es6 @@ -4,6 +4,7 @@ import { spinnerHTML } from 'discourse/helpers/loading-spinner'; import Topic from 'discourse/models/topic'; import Quote from 'discourse/lib/quote'; import { setting } from 'discourse/lib/computed'; +import { popupAjaxError } from 'discourse/lib/ajax-error'; import computed from 'ember-addons/ember-computed-decorators'; export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, { @@ -201,14 +202,9 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, { } ]); } else { - post.destroy(user).then(null, function(e) { + post.destroy(user).catch(function(error) { + popupAjaxError(error); post.undoDeleteState(); - const response = $.parseJSON(e.responseText); - if (response && response.errors) { - bootbox.alert(response.errors[0]); - } else { - bootbox.alert(I18n.t('generic_error')); - } }); } }, @@ -232,13 +228,7 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, { return; } if (post) { - return post.toggleBookmark().catch(function(error) { - if (error && error.jqXHR && error.jqXHR.responseText) { - bootbox.alert($.parseJSON(error.jqXHR.responseText).errors[0]); - } else { - bootbox.alert(I18n.t('generic_error')); - } - }); + return post.toggleBookmark().catch(popupAjaxError); } else { return this.get("model").toggleBookmark(); } @@ -295,13 +285,7 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, { // the properties to the topic. self.rollbackBuffer(); self.set('editingTopic', false); - }).catch(function(error) { - if (error && error.jqXHR && error.jqXHR.responseText) { - bootbox.alert($.parseJSON(error.jqXHR.responseText).errors[0]); - } else { - bootbox.alert(I18n.t('generic_error')); - } - }); + }).catch(popupAjaxError); }, toggledSelectedPost(post) {