fix likes and comment loading in the stream
This commit is contained in:
parent
d80afc64ec
commit
74cdc91bb1
5 changed files with 29 additions and 5 deletions
|
|
@ -8,8 +8,8 @@ app.models.Post = Backbone.Model.extend({
|
||||||
|
|
||||||
setupCollections: function() {
|
setupCollections: function() {
|
||||||
this.comments = new app.collections.Comments(this.get("comments") || this.get("last_three_comments"), {post : this});
|
this.comments = new app.collections.Comments(this.get("comments") || this.get("last_three_comments"), {post : this});
|
||||||
this.likes = new app.collections.Likes([], {post : this}); // load in the user like initially
|
this.likes = this.likes || new app.collections.Likes([], {post : this}); // load in the user like initially
|
||||||
this.participations = new app.collections.Participations([], {post : this}); // load in the user like initially
|
this.participations = this.participations || new app.collections.Participations([], {post : this}); // load in the user like initially
|
||||||
},
|
},
|
||||||
|
|
||||||
createdAt : function() {
|
createdAt : function() {
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,8 @@ app.views.CommentStream = app.views.Base.extend({
|
||||||
initialize: function(options) {
|
initialize: function(options) {
|
||||||
this.model.comments.bind('add', this.appendComment, this);
|
this.model.comments.bind('add', this.appendComment, this);
|
||||||
this.commentTemplate = options.commentTemplate;
|
this.commentTemplate = options.commentTemplate;
|
||||||
|
|
||||||
|
this.model.bind("commentsExpanded", this.render, this)
|
||||||
},
|
},
|
||||||
|
|
||||||
postRenderTemplate : function() {
|
postRenderTemplate : function() {
|
||||||
|
|
@ -60,9 +62,12 @@ app.views.CommentStream = app.views.Base.extend({
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
this.model.comments.fetch({
|
this.model.comments.fetch({
|
||||||
success : function(){
|
success : function(resp){
|
||||||
self.model.set({all_comments_loaded : true});
|
self.model.set({
|
||||||
self.render();
|
comments : resp.models,
|
||||||
|
all_comments_loaded : true
|
||||||
|
})
|
||||||
|
self.model.trigger("commentsExpanded", self)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,10 @@ app.views.LikesInfo = app.views.StreamObject.extend({
|
||||||
|
|
||||||
tooltipSelector : ".avatar",
|
tooltipSelector : ".avatar",
|
||||||
|
|
||||||
|
initialize : function() {
|
||||||
|
this.model.bind('expandedLikes', this.render, this)
|
||||||
|
},
|
||||||
|
|
||||||
presenter : function() {
|
presenter : function() {
|
||||||
return _.extend(this.defaultPresenter(), {
|
return _.extend(this.defaultPresenter(), {
|
||||||
likes : this.model.likes.models
|
likes : this.model.likes.models
|
||||||
|
|
@ -21,6 +25,7 @@ app.views.LikesInfo = app.views.StreamObject.extend({
|
||||||
.done(function(resp){
|
.done(function(resp){
|
||||||
// set like attribute and like collection
|
// set like attribute and like collection
|
||||||
self.model.set({likes : self.model.likes.reset(resp)})
|
self.model.set({likes : self.model.likes.reset(resp)})
|
||||||
|
self.model.trigger("expandedLikes")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,14 @@ describe("app.views.CommentStream", function(){
|
||||||
loginAs({})
|
loginAs({})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("binds", function() {
|
||||||
|
it("re-renders on a commentsExpanded trigger", function(){
|
||||||
|
spyOn(this.view, "render")
|
||||||
|
this.view.model.trigger("commentsExpanded")
|
||||||
|
expect(this.view.render).toHaveBeenCalled()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe("postRenderTemplate", function(){
|
describe("postRenderTemplate", function(){
|
||||||
it("applies infield labels", function(){
|
it("applies infield labels", function(){
|
||||||
spyOn($.fn, "placeholder")
|
spyOn($.fn, "placeholder")
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,12 @@ describe("app.views.LikesInfo", function(){
|
||||||
|
|
||||||
expect($(this.view.el).html().trim()).toBe("");
|
expect($(this.view.el).html().trim()).toBe("");
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("fires on a model change", function(){
|
||||||
|
spyOn(this.view, "postRenderTemplate")
|
||||||
|
this.view.model.trigger('expandedLikes')
|
||||||
|
expect(this.view.postRenderTemplate).toHaveBeenCalled()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("showAvatars", function(){
|
describe("showAvatars", function(){
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue