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
PERFSTATS = False
DISCUSSION_SETTINGS = {
'MAX_COMMENT_DEPTH': 2,
'MAX_COMMENT_DEPTH': None, # Don't force a max comment depth
}
# Features
......
......@@ -5,6 +5,7 @@ if Backbone?
events:
"click .discussion-submit-comment": "submitComment"
"focus .wmd-input": "showEditorChrome"
"click .comment-reply-link": "replyToComment"
$: (selector) ->
@$el.find(selector)
......@@ -52,17 +53,17 @@ if Backbone?
})
renderComments: ->
comments = new Comments()
comments.comparator = (comment) ->
@comments = new Comments()
@comments.comparator = (comment) ->
comment.get('created_at')
collectComments = (comment) ->
comments.add(comment)
collectComments = (comment) =>
@comments.add(comment)
children = new Comments(comment.get('children'))
children.each (child) ->
child.parent = comment
collectComments(child)
@model.get('comments').each collectComments
comments.each (comment) => @renderComment(comment, false, null)
@comments.each (comment) => @renderComment(comment, false, null)
renderComment: (comment) =>
comment.set('thread', @model.get('thread'))
......@@ -73,11 +74,16 @@ if Backbone?
submitComment: (event) ->
event.preventDefault()
url = @model.urlFor('reply')
body = @getWmdContent("comment-body")
return if not body.trim().length
@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")
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)
@hideEditorChrome()
@trigger "comment:add", comment
......@@ -89,9 +95,10 @@ if Backbone?
dataType: 'json'
data:
body: body
success: (response, textStatus) ->
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
@comments.add(comment)
view.render()
delete: (event) =>
event.preventDefault()
......@@ -186,3 +193,8 @@ if Backbone?
@renderShowView()
@showCommentForm()
replyToComment: (event)=>
event.preventDefault()
elem = $(event.target)
@parentComment = @comments.get(elem.data('comment-id'))
@$('.wmd-input').focus()
......@@ -123,6 +123,7 @@
${"<% if (obj.username) { %>"}
<a href="${'<%- user_url %>'}" class="profile-link">${'<%- username %>'}</a>
${"<% } else {print('anonymous');} %>"}
<a class="comment-reply-link" href="#comment_${'<%- id %>'}" data-comment-id="${'<%- id %>'}">Reply</a>
</p>
</div>
</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