From 1b058cf908d7ec0d7d1fb90853b5c5fbefb3d265 Mon Sep 17 00:00:00 2001 From: Joe Bivins Date: Sun, 12 Feb 2012 04:08:36 -0500 Subject: [PATCH] Fix #2354 (attempt 3). Sends the user to the application root (redirecting to /explore) after they remove post from the post page with one post on it. --- public/javascripts/app/views/post_view.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/public/javascripts/app/views/post_view.js b/public/javascripts/app/views/post_view.js index 62aaccda9..0cf5de3a3 100644 --- a/public/javascripts/app/views/post_view.js +++ b/public/javascripts/app/views/post_view.js @@ -27,6 +27,7 @@ app.views.Post = app.views.StreamObject.extend({ $(this.el).attr("id", this.model.get("guid")); this.model.bind('remove', this.remove, this); + this.model.bind('destroy', this.destroy, this); //subviews this.commentStreamView = new app.views.CommentStream({ model : this.model}); @@ -116,5 +117,13 @@ app.views.Post = app.views.StreamObject.extend({ authorIsNotCurrentUser : function() { return this.model.get("author").id != (!!app.user() && app.user().id) + }, + + destroy : function() { + var posts_uri = new RegExp(this.model.collection.url + '\/[0-9]+$'); + + if ((this.model.collection.length == 1) && (posts_uri.test(document.location.pathname))) { + document.location.replace(Backbone.history.options.root); + } } });