diff --git a/public/javascripts/app/models/post.js b/public/javascripts/app/models/post.js index ff4a79a8d..24abb9c2e 100644 --- a/public/javascripts/app/models/post.js +++ b/public/javascripts/app/models/post.js @@ -41,6 +41,7 @@ app.models.Post = Backbone.Model.extend({ var self = this; this.participations.create({}, {success : function(resp){ self.set(resp.attributes.post) + self.trigger('feedback', self) }}); }, @@ -50,6 +51,8 @@ app.models.Post = Backbone.Model.extend({ participationModel.destroy(); this.set({ user_participation : null }); + + this.trigger('feedback', this) }, toggleLike : function() { @@ -65,6 +68,7 @@ app.models.Post = Backbone.Model.extend({ var self = this; this.likes.create({}, {success : function(resp){ self.set(resp.attributes.post) + self.trigger('feedback', self) }}); }, @@ -74,5 +78,6 @@ app.models.Post = Backbone.Model.extend({ likeModel.destroy(); this.set({ user_like : null }); + this.trigger('feedback', this) } }); diff --git a/public/javascripts/app/pages/post-viewer.js b/public/javascripts/app/pages/post-viewer.js index bb868f4e9..128eb99b9 100644 --- a/public/javascripts/app/pages/post-viewer.js +++ b/public/javascripts/app/pages/post-viewer.js @@ -12,7 +12,7 @@ app.pages.PostViewer = app.views.Base.extend({ postView : function(){ return new app.views.Post({ model : this.model, - className : "dd", + className : "loaded", templateName : "post-viewer/content/" + this.options.postTemplateName }) }, diff --git a/public/javascripts/app/views.js b/public/javascripts/app/views.js index 7d2a5ac77..194a2ef25 100644 --- a/public/javascripts/app/views.js +++ b/public/javascripts/app/views.js @@ -10,7 +10,11 @@ app.views.Base = Backbone.View.extend({ setupRenderEvents : function(){ this.model.bind('remove', this.remove, this); - this.model.bind('change', this.render, this); + + // this line is too generic. we usually only want to re-render on + // feedback changes as the post content, author, and time do not change. + // + // this.model.bind('change', this.render, this); }, defaultPresenter : function(){ diff --git a/public/javascripts/app/views/feedback_view.js b/public/javascripts/app/views/feedback_view.js index 7b5cfd56f..b01afe673 100644 --- a/public/javascripts/app/views/feedback_view.js +++ b/public/javascripts/app/views/feedback_view.js @@ -10,6 +10,14 @@ app.views.Feedback = app.views.Base.extend({ "click .reshare_action": "resharePost" }, + initialize : function() { + this.model.bind('feedback', this.render, this); + }, + + postRenderTemplate : function(){ + console.log('fuck') + }, + presenter : function() { return _.extend(this.defaultPresenter(), { userCanReshare : this.userCanReshare() diff --git a/spec/javascripts/app/views/feedback_view_spec.js b/spec/javascripts/app/views/feedback_view_spec.js index c270e6384..57988cf75 100644 --- a/spec/javascripts/app/views/feedback_view_spec.js +++ b/spec/javascripts/app/views/feedback_view_spec.js @@ -16,6 +16,14 @@ describe("app.views.Feedback", function(){ }); + describe("triggers", function() { + it('re-renders when the model triggers feedback', function(){ + spyOn(this.view, "postRenderTemplate") + this.view.model.trigger("feedback") + expect(this.view.postRenderTemplate).toHaveBeenCalled() + }) + }) + describe(".render", function(){ beforeEach(function(){ this.link = function(){ return this.view.$(".like_action"); }