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")
......
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