From 8a98cd4517e599724b3ca3b68e233c3e6038e848 Mon Sep 17 00:00:00 2001 From: Steffen van Bergerem Date: Thu, 23 Mar 2017 01:02:33 +0100 Subject: [PATCH] Refactor destroyModel function in base view closes #7385 --- Changelog.md | 1 + app/assets/javascripts/app/views.js | 17 +++++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Changelog.md b/Changelog.md index 8fb0c37ce..0ce0422ef 100644 --- a/Changelog.md +++ b/Changelog.md @@ -9,6 +9,7 @@ * Don't hide posts when blocking someone from the profile [#7379](https://github.com/diaspora/diaspora/pull/7379) * Disable autocomplete for the conversation form recipient input [#7375](https://github.com/diaspora/diaspora/pull/7375) * Fix sharing indicator on profile page for blocked users [#7382](https://github.com/diaspora/diaspora/pull/7382) +* Remove post only after a successful deletion on the server [#7385](https://github.com/diaspora/diaspora/pull/7385) ## Features * Add links to liked and commented pages [#5502](https://github.com/diaspora/diaspora/pull/5502) diff --git a/app/assets/javascripts/app/views.js b/app/assets/javascripts/app/views.js index d0bede4ea..16a033280 100644 --- a/app/assets/javascripts/app/views.js +++ b/app/assets/javascripts/app/views.js @@ -132,19 +132,20 @@ app.views.Base = Backbone.View.extend({ destroyModel: function(evt) { evt && evt.preventDefault(); - var self = this; var url = this.model.urlRoot + "/" + this.model.id; if( confirm(_.result(this, "destroyConfirmMsg")) ) { this.$el.addClass("deleting"); - this.model.destroy({ url: url }) - .done(function() { - self.remove(); - }) - .fail(function() { - self.$el.removeClass("deleting"); + this.model.destroy({ + url: url, + success: function() { + this.remove(); + }.bind(this), + error: function() { + this.$el.removeClass("deleting"); app.flashMessages.error(Diaspora.I18n.t("failed_to_remove")); - }); + }.bind(this) + }); } },