From d816d5fadeb510ff507f0ada2636e5c21bedf82c Mon Sep 17 00:00:00 2001 From: Kevin Chugh Date: Fri, 27 Sep 2013 15:23:05 -0400 Subject: [PATCH 1/2] update coffeescript to dynamically render sr spans --- .../discussion/views/discussion_thread_show_view.coffee | 9 ++++++++- .../discussion/views/thread_response_show_view.coffee | 8 ++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/common/static/coffee/src/discussion/views/discussion_thread_show_view.coffee b/common/static/coffee/src/discussion/views/discussion_thread_show_view.coffee index 46a13db83e..ef873d961c 100644 --- a/common/static/coffee/src/discussion/views/discussion_thread_show_view.coffee +++ b/common/static/coffee/src/discussion/views/discussion_thread_show_view.coffee @@ -42,8 +42,10 @@ if Backbone? renderVoted: => if window.user.voted(@model) @$("[data-role=discussion-vote]").addClass("is-cast") + @$("[data-role=discussion-vote] span.sr").html("votes (click to remove your vote)") else @$("[data-role=discussion-vote]").removeClass("is-cast") + @$("[data-role=discussion-vote] span.sr").html("votes (click to vote)") renderFlagged: => if window.user.id in @model.get("abuse_flaggers") or (DiscussionUtil.isFlagModerator and @model.get("abuse_flaggers").length > 0) @@ -70,7 +72,12 @@ if Backbone? @renderVoted() @renderFlagged() @renderPinned() - @$("[data-role=discussion-vote] .votes-count-number").html(@model.get("votes")["up_count"]) + @$("[data-role=discussion-vote] .votes-count-number").html(@model.get("votes")["up_count"] + '') + if window.user.voted(@model) + @$("[data-role=discussion-vote] .votes-count-number span.sr").html("votes (click to remove your vote)") + else + @$("[data-role=discussion-vote] .votes-count-number span.sr").html("votes (click to vote)") + convertMath: -> element = @$(".post-body") diff --git a/common/static/coffee/src/discussion/views/thread_response_show_view.coffee b/common/static/coffee/src/discussion/views/thread_response_show_view.coffee index cb67125b9f..60371bbf60 100644 --- a/common/static/coffee/src/discussion/views/thread_response_show_view.coffee +++ b/common/static/coffee/src/discussion/views/thread_response_show_view.coffee @@ -23,6 +23,7 @@ if Backbone? @delegateEvents() if window.user.voted(@model) @$(".vote-btn").addClass("is-cast") + @$(".vote-btn span.sr").html("votes (click to remove your vote)") @renderAttrs() @renderFlagged() @$el.find(".posted-details").timeago() @@ -48,12 +49,14 @@ if Backbone? @$(".vote-btn").toggleClass("is-cast") if @$(".vote-btn").hasClass("is-cast") @vote() + @$(".vote-btn span.sr").html("votes (click to remove your vote)") else @unvote() + @$(".vote-btn span.sr").html("votes (click vote)") vote: -> url = @model.urlFor("upvote") - @$(".votes-count-number").html(parseInt(@$(".votes-count-number").html()) + 1) + @$(".votes-count-number").html((parseInt(@$(".votes-count-number").html()) + 1 ) + '') DiscussionUtil.safeAjax $elem: @$(".discussion-vote") url: url @@ -64,7 +67,7 @@ if Backbone? unvote: -> url = @model.urlFor("unvote") - @$(".votes-count-number").html(parseInt(@$(".votes-count-number").html()) - 1) + @$(".votes-count-number").html((parseInt(@$(".votes-count-number").html()) - 1 )+'') DiscussionUtil.safeAjax $elem: @$(".discussion-vote") url: url @@ -73,6 +76,7 @@ if Backbone? if textStatus == 'success' @model.set(response) + edit: (event) -> @trigger "response:edit", event From 9a5e6f1fdd49d2177b900fa0c4c5ca31b6f5235e Mon Sep 17 00:00:00 2001 From: Kevin Chugh Date: Fri, 27 Sep 2013 17:12:48 -0400 Subject: [PATCH 2/2] code review cleanup --- .../src/discussion/views/thread_response_show_view.coffee | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/common/static/coffee/src/discussion/views/thread_response_show_view.coffee b/common/static/coffee/src/discussion/views/thread_response_show_view.coffee index 60371bbf60..43b2d3055e 100644 --- a/common/static/coffee/src/discussion/views/thread_response_show_view.coffee +++ b/common/static/coffee/src/discussion/views/thread_response_show_view.coffee @@ -52,11 +52,11 @@ if Backbone? @$(".vote-btn span.sr").html("votes (click to remove your vote)") else @unvote() - @$(".vote-btn span.sr").html("votes (click vote)") + @$(".vote-btn span.sr").html("votes (click to vote)") vote: -> url = @model.urlFor("upvote") - @$(".votes-count-number").html((parseInt(@$(".votes-count-number").html()) + 1 ) + '') + @$(".votes-count-number").html((parseInt(@$(".votes-count-number").html()) + 1) + '') DiscussionUtil.safeAjax $elem: @$(".discussion-vote") url: url @@ -67,7 +67,7 @@ if Backbone? unvote: -> url = @model.urlFor("unvote") - @$(".votes-count-number").html((parseInt(@$(".votes-count-number").html()) - 1 )+'') + @$(".votes-count-number").html((parseInt(@$(".votes-count-number").html()) - 1)+'') DiscussionUtil.safeAjax $elem: @$(".discussion-vote") url: url @@ -76,7 +76,6 @@ if Backbone? if textStatus == 'success' @model.set(response) - edit: (event) -> @trigger "response:edit", event