Skip to content

Commit

Permalink
Fix bug where added/deleted commit comments were not reflected in the…
Browse files Browse the repository at this point in the history
… UI.

Fixes #56.
  • Loading branch information
cespare committed Sep 16, 2011
1 parent 2016f53 commit 6beeb73
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions public/commit.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -164,18 +164,21 @@ window.Commit =

onCommentSubmit: (e) ->
e.preventDefault()
if $(e.currentTarget).find("textarea").val() == ""
target = $(e.currentTarget)
if target.find("textarea").val() == ""
return
#make sure changes to form happen to both tables to maintain height
formId = $(e.currentTarget).attr("form-id")
form = $(e.currentTarget).parents(".file").find(".commentForm[form-id='" + formId + "']")
formId = target.attr("form-id")
file = target.parents(".file")
# file is the parent file for the comment, if the comment is a line-level comment.
form = if file.size() > 0 then file.find(".commentForm[form-id='" + formId + "']") else target
data = {}
$(e.currentTarget).find("input, textarea").each (i,e) -> data[e.name] = e.value if e.name
target.find("input, textarea").each (i,e) -> data[e.name] = e.value if e.name
$.ajax
type: "POST",
data: data,
url: e.currentTarget.action,
success: (html) -> Commit.onCommentSubmitSuccess(html, form)
success: (html) => @onCommentSubmitSuccess(html, form)

onCommentSubmitSuccess: (html, form) ->
$(form).before(html)
Expand All @@ -196,16 +199,20 @@ window.Commit =

onCommentDelete: (e) ->
commentId = $(e.target).parents(".comment").attr("commentId")
$.ajax({
$.ajax
type: "post",
url: "/delete_comment",
data: { comment_id: commentId },
success: ->
#make sure changes to form happen to both tables to maintain height
form = $(e.currentTarget).parents(".file").find(".comment[commentId='" + commentId + "']")
success: =>
# Make sure that changes to forms happen to both tables to maintain height if deleting a line comment.
target = $(e.currentTarget)
file = target.parents(".file")
if file.size() > 0
form = file.find(".comment[commentid='" + commentId + "']")
else
form = target.parents(".comment")
form.remove()
Commit.setSideBySideCommentVisibility()
})
@setSideBySideCommentVisibility()

onApproveClicked: (e) ->
$.ajax({
Expand Down

0 comments on commit 6beeb73

Please sign in to comment.