Skip to content
This repository

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

Merged
merged 1 commit into from almost 2 years ago

3 participants

Dan Hansen Don't Add Me To Your Organization a.k.a The Travis Bot Maxwell Salzberg
Dan Hansen
Collaborator
OhaiBBQ commented May 24, 2012

persist unsaved comment value after expanding comments

bugmash #3
persist unsaved comment value after expanding comments
d334097
Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request passes (merged d334097 into f19f611).

Maxwell Salzberg
Owner
maxwell commented May 24, 2012

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

Dan Hansen
Collaborator
OhaiBBQ commented May 24, 2012

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 Salzberg
Owner
maxwell commented May 24, 2012

cool. done

Maxwell Salzberg maxwell merged commit fb1fd66 into from May 24, 2012
Maxwell Salzberg maxwell closed this May 24, 2012
Hans Fase hfase01 referenced this pull request from a commit September 15, 2012
Commit has since been removed from the repository and is no longer available.
Hans Fase hfase01 referenced this pull request from a commit September 25, 2012
Commit has since been removed from the repository and is no longer available.
Alexander Wenzowski wenzowski referenced this pull request from a commit February 28, 2013
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

May 24, 2012
bugmash #3
persist unsaved comment value after expanding comments
d334097
This page is out of date. Refresh to see the latest.
8  app/assets/javascripts/app/views/comment_stream_view.js
@@ -61,16 +61,20 @@ app.views.CommentStream = app.views.Base.extend({
61 61
   expandComments: function(evt){
62 62
     if(evt){ evt.preventDefault(); }
63 63
 
64  
-    var self = this;
  64
+    var localCommentValue = this.$("textarea").val(),
  65
+      self = this;
  66
+
65 67
     this.model.comments.fetch({
66 68
       success : function(resp){
67 69
         self.model.set({
68 70
           comments : resp.models,
69 71
           all_comments_loaded : true
70 72
         })
  73
+
71 74
         self.model.trigger("commentsExpanded", self)
  75
+
  76
+        self.$("textarea").val(localCommentValue).focus()
72 77
       }
73 78
     });
74 79
   }
75  
-
76 80
 });
16  spec/javascripts/app/views/comment_stream_view_spec.js
@@ -38,4 +38,20 @@ describe("app.views.CommentStream", function(){
38 38
       expect(comment.set).toHaveBeenCalled()
39 39
     })
40 40
   })
  41
+
  42
+  describe("expandComments", function() {
  43
+    it("refills the comment textbox on success", function() {
  44
+      jasmine.Ajax.useMock();
  45
+
  46
+      this.view.render();
  47
+
  48
+      this.view.$("textarea").val("great post!");
  49
+
  50
+      this.view.expandComments();
  51
+
  52
+      mostRecentAjaxRequest().response({ comments : [] });
  53
+
  54
+      expect(this.view.$("textarea").val()).toEqual("great post!");
  55
+    })
  56
+  })
41 57
 })
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.