Commit 96b613af by Rocky Duan

ajax endorse

parent 655d1529
...@@ -166,13 +166,20 @@ Discussion = @Discussion ...@@ -166,13 +166,20 @@ Discussion = @Discussion
Discussion.bindContentEvents($content) Discussion.bindContentEvents($content)
) )
handleEndorse = (elem) -> handleEndorse = (elem, endorsed) ->
url = Discussion.urlFor('endorse_comment', id) url = Discussion.urlFor('endorse_comment', id)
endorsed = $local(".discussion-endorse").is(":checked") Discussion.safeAjax
$.post url, {endorsed: endorsed}, (response, textStatus) -> $elem: $(elem)
# TODO error handling url: url
Discussion.handleAnchorAndReload(response) type: "POST"
, 'json' dataType: "json"
data: {endorsed: endorsed}
success: (response, textStatus) ->
if textStatus == "success"
if endorsed
$(content).addClass("endorsed")
else
$(content).removeClass("endorsed")
handleHideSingleThread = (elem) -> handleHideSingleThread = (elem) ->
$threadTitle = $local(".thread-title") $threadTitle = $local(".thread-title")
...@@ -248,7 +255,7 @@ Discussion = @Discussion ...@@ -248,7 +255,7 @@ Discussion = @Discussion
handleVote($elem, "down") handleVote($elem, "down")
"click .discussion-endorse": -> "click .discussion-endorse": ->
handleEndorse(this) handleEndorse(this, $(this).is(":checked"))
"click .discussion-edit": -> "click .discussion-edit": ->
if $content.hasClass("thread") if $content.hasClass("thread")
......
...@@ -4,13 +4,13 @@ if not @Discussion? ...@@ -4,13 +4,13 @@ if not @Discussion?
Discussion = @Discussion Discussion = @Discussion
initializeVote = (index, content) -> initializeVote = (index, content) ->
$content = $(content) $content = $(content)
$local = Discussion.generateLocal($content.children(".discussion-content")) $local = Discussion.generateLocal($content.children(".discussion-content"))
id = $content.attr("_id") id = $content.attr("_id")
if Discussion.isUpvoted id if Discussion.isUpvoted id
$local(".discussion-vote-up").addClass("voted") $local(".discussion-vote-up").addClass("voted")
else if Discussion.isDownvoted id else if Discussion.isDownvoted id
$local(".discussion-vote-down").addClass("voted") $local(".discussion-vote-down").addClass("voted")
subscriptionLink = (type, id) -> subscriptionLink = (type, id) ->
......
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