Skip to content

Loading…

BMM #3, “Show x more comments” deletes text in comment box when clicked #3313

Merged
merged 1 commit into from

3 participants

@OhaiBBQ
diaspora* social network member

persist unsaved comment value after expanding comments

Dan Hansen bugmash #3
persist unsaved comment value after expanding comments
d334097
@travisbot

This pull request passes (merged d334097 into f19f611).

@maxwell
diaspora* social network member

I think comments.fetch would be async, since the success callback. wouldn't this still get blown away when the collection finishes?

@OhaiBBQ
diaspora* social network member

No, we render the view after the model has been populated with comments. After the view is re-rendered we set the textbox's value to what the comment used to be.

@maxwell
diaspora* social network member

cool. done

@maxwell maxwell merged commit fb1fd66 into diaspora:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 25, 2012
  1. bugmash #3

    Dan Hansen committed
    persist unsaved comment value after expanding comments
View
8 app/assets/javascripts/app/views/comment_stream_view.js
@@ -61,16 +61,20 @@ app.views.CommentStream = app.views.Base.extend({
expandComments: function(evt){
if(evt){ evt.preventDefault(); }
- var self = this;
+ var localCommentValue = this.$("textarea").val(),
+ self = this;
+
this.model.comments.fetch({
success : function(resp){
self.model.set({
comments : resp.models,
all_comments_loaded : true
})
+
self.model.trigger("commentsExpanded", self)
+
+ self.$("textarea").val(localCommentValue).focus()
}
});
}
-
});
View
16 spec/javascripts/app/views/comment_stream_view_spec.js
@@ -38,4 +38,20 @@ describe("app.views.CommentStream", function(){
expect(comment.set).toHaveBeenCalled()
})
})
+
+ describe("expandComments", function() {
+ it("refills the comment textbox on success", function() {
+ jasmine.Ajax.useMock();
+
+ this.view.render();
+
+ this.view.$("textarea").val("great post!");
+
+ this.view.expandComments();
+
+ mostRecentAjaxRequest().response({ comments : [] });
+
+ expect(this.view.$("textarea").val()).toEqual("great post!");
+ })
+ })
})
Something went wrong with that request. Please try again.