Render comment replies properly, and update them after receiving a response.
This commit is contained in:
@@ -44,6 +44,7 @@ if Backbone?
|
|||||||
view = new ResponseCommentView(model: comment)
|
view = new ResponseCommentView(model: comment)
|
||||||
view.render()
|
view.render()
|
||||||
@$el.find(".comments li:last").before(view.el)
|
@$el.find(".comments li:last").before(view.el)
|
||||||
|
view
|
||||||
|
|
||||||
toggleVote: (event) ->
|
toggleVote: (event) ->
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
@@ -81,8 +82,8 @@ if Backbone?
|
|||||||
body = @$(".comment-form-input").val()
|
body = @$(".comment-form-input").val()
|
||||||
if not body.trim().length
|
if not body.trim().length
|
||||||
return
|
return
|
||||||
comment = new Comment(body: body, created_at: (new Date()).toISOString(), username: window.user.get("username"), user_id: window.user.get("id"))
|
comment = new Comment(body: body, created_at: (new Date()).toISOString(), username: window.user.get("username"), user_id: window.user.get("id"), id:"unsaved")
|
||||||
@renderComment(comment)
|
view = @renderComment(comment)
|
||||||
@trigger "comment:add", comment
|
@trigger "comment:add", comment
|
||||||
@$(".comment-form-input").val("")
|
@$(".comment-form-input").val("")
|
||||||
|
|
||||||
@@ -93,7 +94,9 @@ if Backbone?
|
|||||||
dataType: 'json'
|
dataType: 'json'
|
||||||
data:
|
data:
|
||||||
body: body
|
body: body
|
||||||
|
success: (response, textStatus) ->
|
||||||
|
comment.set(response.content)
|
||||||
|
view.render() # This is just to update the id for the most part, but might be useful in general
|
||||||
delete: (event) ->
|
delete: (event) ->
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
if not @model.can('can_delete')
|
if not @model.can('can_delete')
|
||||||
|
|||||||
Reference in New Issue
Block a user