diff --git a/app/assets/javascripts/app/views/feedback_view.js b/app/assets/javascripts/app/views/feedback_view.js index 70bf4ca6d166191c9e98de3e7b22a02373624ccd..81d8d03e8534a7d4619a5048f014798740d922c6 100644 --- a/app/assets/javascripts/app/views/feedback_view.js +++ b/app/assets/javascripts/app/views/feedback_view.js @@ -8,10 +8,6 @@ app.views.Feedback = app.views.Base.extend({ events: { "click .like" : "toggleLike", "click .reshare" : "resharePost", - - "click .post_report" : "report", - "click .block_user" : "blockUser", - "click .hide_post" : "hidePost" }, tooltipSelector : ".label", @@ -43,39 +39,6 @@ app.views.Feedback = app.views.Base.extend({ if(evt) { evt.preventDefault(); } if(!window.confirm(Diaspora.I18n.t("reshares.post", {name: this.model.reshareAuthor().name}))) { return } this.model.interactions.reshare(); - }, - - blockUser: function(evt) { - if(evt) { evt.preventDefault(); } - if(!confirm(Diaspora.I18n.t("ignore_user"))) { return; } - - this.model.blockAuthor() - .done(function() { - // return to stream - document.location.href = "/stream"; - }) - .fail(function() { - app.flashMessages.error(Diaspora.I18n.t("hide_post_failed")); - }); - }, - - hidePost : function(evt) { - if(evt) { evt.preventDefault(); } - if(!confirm(Diaspora.I18n.t("hide_post"))) { return; } - - $.ajax({ - url : "/share_visibilities/42", - type : "PUT", - data : { - post_id : this.model.id - } - }).done(function() { - // return to stream - document.location.href = "/stream"; - }) - .fail(function() { - app.flashMessages.error(Diaspora.I18n.t("ignore_post_failed")); - }); } }); // @license-end diff --git a/app/assets/javascripts/app/views/post_controls_view.js b/app/assets/javascripts/app/views/post_controls_view.js index 796e8565a43483f8caa9b3d4940eee1456d92d40..78c0ee3df73d94a7ef68f1be5124da77c42dd184 100644 --- a/app/assets/javascripts/app/views/post_controls_view.js +++ b/app/assets/javascripts/app/views/post_controls_view.js @@ -34,7 +34,9 @@ app.views.PostControls = app.views.Base.extend({ if (evt) { evt.preventDefault(); } if (!confirm(Diaspora.I18n.t("ignore_user"))) { return; } - this.model.blockAuthor().fail(function() { + this.model.blockAuthor().done(function() { + if (this.singlePost) { app._changeLocation(Routes.stream()); } + }.bind(this)).fail(function() { app.flashMessages.error(Diaspora.I18n.t("ignore_failed")); }); }, @@ -43,7 +45,6 @@ app.views.PostControls = app.views.Base.extend({ if (evt) { evt.preventDefault(); } if (!confirm(Diaspora.I18n.t("confirm_dialog"))) { return; } - var self = this; $.ajax({ url: Routes.shareVisibility(42), type: "PUT", @@ -53,26 +54,28 @@ app.views.PostControls = app.views.Base.extend({ /* eslint-enable camelcase */ } }).done(function() { - self.post.remove(); - }).fail(function() { + if (this.singlePost) { + app._changeLocation(Routes.stream()); + } else { + this.post.remove(); + } + }.bind(this)).fail(function() { app.flashMessages.error(Diaspora.I18n.t("hide_post_failed")); }); }, createParticipation: function(evt) { if (evt) { evt.preventDefault(); } - var that = this; $.post(Routes.postParticipation(this.model.get("id")), {}, function() { - that.model.set({participation: true}); - }); + this.model.set({participation: true}); + }.bind(this)); }, destroyParticipation: function(evt) { if (evt) { evt.preventDefault(); } - var that = this; $.post(Routes.postParticipation(this.model.get("id")), {_method: "delete"}, function() { - that.model.set({participation: false}); - }); + this.model.set({participation: false}); + }.bind(this)); } }); // @license-end diff --git a/app/assets/javascripts/app/views/single-post-viewer/single_post_moderation.js b/app/assets/javascripts/app/views/single-post-viewer/single_post_moderation.js index 823783da3d59ea965fc98ebb774cbf0a506cf90c..3599da357b1d3c5ff7e49f2fe627863eb0f60d78 100644 --- a/app/assets/javascripts/app/views/single-post-viewer/single_post_moderation.js +++ b/app/assets/javascripts/app/views/single-post-viewer/single_post_moderation.js @@ -1,31 +1,12 @@ -app.views.SinglePostModeration = app.views.Feedback.extend({ +app.views.SinglePostModeration = app.views.PostControls.extend({ templateName: "single-post-viewer/single-post-moderation", - - className: "control-icons", - - events: function() { - return _.defaults({ - "click .remove_post": "destroyModel", - "click .create_participation": "createParticipation", - "click .destroy_participation": "destroyParticipation" - }, app.views.Feedback.prototype.events); - }, - - presenter: function() { - return _.extend(this.defaultPresenter(), { - authorIsCurrentUser : this.authorIsCurrentUser() - }); - }, + singlePost: true, renderPluginWidgets : function() { app.views.Base.prototype.renderPluginWidgets.apply(this); this.$("a").tooltip({placement: "bottom"}); }, - authorIsCurrentUser: function() { - return app.currentUser.authenticated() && this.model.get("author").id === app.user().id; - }, - destroyModel: function(evt) { if(evt) { evt.preventDefault(); } var url = this.model.urlRoot + "/" + this.model.id; @@ -41,24 +22,4 @@ app.views.SinglePostModeration = app.views.Feedback.extend({ }); } }, - - createParticipation: function (evt) { - if(evt) { evt.preventDefault(); } - var self = this; - $.post(Routes.postParticipation(this.model.get("id")), {}, function () { - self.model.set({participation: true}); - self.render(); - }); - }, - - destroyParticipation: function (evt) { - if(evt) { evt.preventDefault(); } - var self = this; - $.post(Routes.postParticipation(this.model.get("id")), { _method: "delete" }, function () { - self.model.set({participation: false}); - self.render(); - }); - }, - - participation: function(){ return this.model.get("participation"); } }); diff --git a/spec/javascripts/app/views/post_controls_view_spec.js b/spec/javascripts/app/views/post_controls_view_spec.js index 01a5385cd39a15e356755d0c0ff12ac20ee3e198..e85cf571f15033148a4e526466ff1d2d6c697dc3 100644 --- a/spec/javascripts/app/views/post_controls_view_spec.js +++ b/spec/javascripts/app/views/post_controls_view_spec.js @@ -154,6 +154,21 @@ describe("app.views.PostControls", function() { expect(this.model.blockAuthor).toHaveBeenCalled(); }); + it("doesn't redirect to the stream page on success", function() { + spyOn(app, "_changeLocation"); + this.view.blockUser(); + jasmine.Ajax.requests.mostRecent().respondWith({status: 204}); + expect(app._changeLocation).not.toHaveBeenCalled(); + }); + + it("redirects to the stream page on success from the single post view", function() { + spyOn(app, "_changeLocation"); + this.view.singlePost = true; + this.view.blockUser(); + jasmine.Ajax.requests.mostRecent().respondWith({status: 204}); + expect(app._changeLocation).toHaveBeenCalledWith(Routes.stream()); + }); + it("shows a flash message when errors occur", function() { spyOn(app.flashMessages, "error"); this.view.blockUser(); @@ -185,9 +200,21 @@ describe("app.views.PostControls", function() { it("removes the post on success", function() { spyOn(this.view.post, "remove"); + spyOn(app, "_changeLocation"); this.view.hidePost(); jasmine.Ajax.requests.mostRecent().respondWith({status: 204}); expect(this.view.post.remove).toHaveBeenCalled(); + expect(app._changeLocation).not.toHaveBeenCalled(); + }); + + it("redirects to the stream page on success from the single post view", function() { + spyOn(this.view.post, "remove"); + spyOn(app, "_changeLocation"); + this.view.singlePost = true; + this.view.hidePost(); + jasmine.Ajax.requests.mostRecent().respondWith({status: 204}); + expect(this.view.post.remove).not.toHaveBeenCalled(); + expect(app._changeLocation).toHaveBeenCalledWith(Routes.stream()); }); it("shows a flash message when errors occur", function() {