refactored out thread rendering; vote

This commit is contained in:
Rocky Duan
2012-07-23 19:03:36 -04:00
parent 28113d8b43
commit 5e5dda2dfb
5 changed files with 146 additions and 125 deletions

View File

@@ -9,6 +9,7 @@ $ ->
$('#open_close_accordion a').click @toggle
$('#accordion').show()
$("section.discussion").each (index, discussion) ->
Discussion.bindDiscussionEvents(discussion)
@@ -32,7 +33,7 @@ Discussion =
}[name]
handleAnchorAndReload: (response) ->
window.location = window.location.pathname + "#" + response['id']
#window.location = window.location.pathname + "#" + response['id']
window.location.reload()
bindContentEvents: (content) ->
@@ -100,12 +101,26 @@ Discussion =
Discussion.handleAnchorAndReload(response)
, 'json'
handleVote = (elem, value) ->
contentType = if $content.hasClass("thread") then "thread" else "comment"
url = Discussion.urlFor("#{value}vote_#{contentType}", $content.attr("_id"))
$.post url, {}, (response, textStatus) ->
if textStatus == "success"
Discussion.handleAnchorAndReload(response)
, 'json'
$local(".discussion-reply").click ->
handleReply(this)
$local(".discussion-cancel-reply").click ->
handleCancelReply(this)
$local(".discussion-vote-up").click ->
handleVote(this, "up")
$local(".discussion-vote-down").click ->
handleVote(this, "down")
bindDiscussionEvents: (discussion) ->
$discussion = $(discussion)
$discussionNonContent = $discussion.children(".discussion-non-content")