Commit db94cc42 by Ibrahim Awwal

Allows replying to comments at any level of nesting, and removes the nesting limit.

Nested comments are displayed inline with an @reference.
parent be27907a
...@@ -39,7 +39,7 @@ GENERATE_RANDOM_USER_CREDENTIALS = False ...@@ -39,7 +39,7 @@ GENERATE_RANDOM_USER_CREDENTIALS = False
PERFSTATS = False PERFSTATS = False
DISCUSSION_SETTINGS = { DISCUSSION_SETTINGS = {
'MAX_COMMENT_DEPTH': 2, 'MAX_COMMENT_DEPTH': None, # Don't force a max comment depth
} }
# Features # Features
......
...@@ -5,6 +5,7 @@ if Backbone? ...@@ -5,6 +5,7 @@ if Backbone?
events: events:
"click .discussion-submit-comment": "submitComment" "click .discussion-submit-comment": "submitComment"
"focus .wmd-input": "showEditorChrome" "focus .wmd-input": "showEditorChrome"
"click .comment-reply-link": "replyToComment"
$: (selector) -> $: (selector) ->
@$el.find(selector) @$el.find(selector)
...@@ -52,17 +53,17 @@ if Backbone? ...@@ -52,17 +53,17 @@ if Backbone?
}) })
renderComments: -> renderComments: ->
comments = new Comments() @comments = new Comments()
comments.comparator = (comment) -> @comments.comparator = (comment) ->
comment.get('created_at') comment.get('created_at')
collectComments = (comment) -> collectComments = (comment) =>
comments.add(comment) @comments.add(comment)
children = new Comments(comment.get('children')) children = new Comments(comment.get('children'))
children.each (child) -> children.each (child) ->
child.parent = comment child.parent = comment
collectComments(child) collectComments(child)
@model.get('comments').each collectComments @model.get('comments').each collectComments
comments.each (comment) => @renderComment(comment, false, null) @comments.each (comment) => @renderComment(comment, false, null)
renderComment: (comment) => renderComment: (comment) =>
comment.set('thread', @model.get('thread')) comment.set('thread', @model.get('thread'))
...@@ -73,11 +74,16 @@ if Backbone? ...@@ -73,11 +74,16 @@ if Backbone?
submitComment: (event) -> submitComment: (event) ->
event.preventDefault() event.preventDefault()
url = @model.urlFor('reply')
body = @getWmdContent("comment-body") body = @getWmdContent("comment-body")
return if not body.trim().length return if not body.trim().length
@setWmdContent("comment-body", "") @setWmdContent("comment-body", "")
comment = new Comment(body: body, created_at: (new Date()).toISOString(), username: window.user.get("username"), user_id: window.user.get("id"), id:"unsaved") comment = new Comment(body: body, created_at: (new Date()).toISOString(), username: window.user.get("username"), user_id: window.user.get("id"), id:"unsaved")
if @parentComment
url = @parentComment.urlFor('reply')
comment.parent = @parentComment
delete @parentComment # Remove reference so future comments aren't incorrectly parented
else
url = @model.urlFor('reply')
view = @renderComment(comment) view = @renderComment(comment)
@hideEditorChrome() @hideEditorChrome()
@trigger "comment:add", comment @trigger "comment:add", comment
...@@ -89,9 +95,10 @@ if Backbone? ...@@ -89,9 +95,10 @@ if Backbone?
dataType: 'json' dataType: 'json'
data: data:
body: body body: body
success: (response, textStatus) -> success: (response, textStatus) =>
comment.set(response.content) comment.set(response.content)
view.render() # This is just to update the id for the most part, but might be useful in general @comments.add(comment)
view.render()
delete: (event) => delete: (event) =>
event.preventDefault() event.preventDefault()
...@@ -186,3 +193,8 @@ if Backbone? ...@@ -186,3 +193,8 @@ if Backbone?
@renderShowView() @renderShowView()
@showCommentForm() @showCommentForm()
replyToComment: (event)=>
event.preventDefault()
elem = $(event.target)
@parentComment = @comments.get(elem.data('comment-id'))
@$('.wmd-input').focus()
...@@ -123,6 +123,7 @@ ...@@ -123,6 +123,7 @@
${"<% if (obj.username) { %>"} ${"<% if (obj.username) { %>"}
<a href="${'<%- user_url %>'}" class="profile-link">${'<%- username %>'}</a> <a href="${'<%- user_url %>'}" class="profile-link">${'<%- username %>'}</a>
${"<% } else {print('anonymous');} %>"} ${"<% } else {print('anonymous');} %>"}
<a class="comment-reply-link" href="#comment_${'<%- id %>'}" data-comment-id="${'<%- id %>'}">Reply</a>
</p> </p>
</div> </div>
</script> </script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment