Commit 2c6c64d5 by Ibrahim Awwal

Sort comment replies in chronological order, keeping the parent references.

parent 2900c169
......@@ -10,10 +10,10 @@ if Backbone?
render: ->
@template = _.template($("#response-comment-template").html())
params = @model.toJSON()
params['deep'] = @options.deep
if @options.deep
params['parent_id'] = @options.parent.id
params['parent_username'] = @options.parent.get('username')
params['deep'] = @model.has('parent')
if @model.has('parent')
params['parent_id'] = @model.get('parent').id
params['parent_username'] = @model.get('parent').get('username')
@$el.html(@template(params))
@initLocal()
@delegateEvents()
......
console.log('test 1')
if Backbone?
console.log('test 2')
class @ThreadResponseView extends DiscussionContentView
tagName: "li"
......@@ -30,16 +27,23 @@ if Backbone?
MathJax.Hub.Queue ["Typeset", MathJax.Hub, element[0]]
renderComments: ->
@model.get("comments").each (comment) => @renderComment(comment, false, null)
comments = new Comments()
comments.comparator = (comment) ->
comment.get('created_at')
collectComments = (comment) ->
comments.add(comment)
children = new Comments(comment.get('children'))
children.each (child) ->
child.set('parent', comment)
collectComments(child)
@model.get('comments').each collectComments
comments.each (comment) => @renderComment(comment, false, null)
renderComment: (comment, deep=false, parent=null) =>
renderComment: (comment) =>
comment.set('thread', @model.get('thread'))
view = new ResponseCommentView(model: comment, deep: deep, parent: parent)
view = new ResponseCommentView(model: comment)
view.render()
@$el.find(".comments li:last").before(view.el)
children = new Comments(comment.get('children'))
children.each (child) => @renderComment child, true, comment
toggleVote: (event) ->
event.preventDefault()
......
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