Skip to content
Extraits de code Groupes Projets
Valider 74cdc91b rédigé par danielgrippi's avatar danielgrippi
Parcourir les fichiers

fix likes and comment loading in the stream

parent d80afc64
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -8,8 +8,8 @@ app.models.Post = Backbone.Model.extend({ ...@@ -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({ ...@@ -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({ ...@@ -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({ ...@@ -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({ ...@@ -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(){ ...@@ -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(){ ...@@ -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(){
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter