Commit b2c1904c by Rocky Duan

ajax endorse

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