From 1e27b509f952902bccc56476bb2dd4e6114117b4 Mon Sep 17 00:00:00 2001 From: fla Date: Fri, 15 Jan 2016 17:12:09 +0100 Subject: [PATCH] Add number of votes on poll answers --- app/assets/javascripts/app/views/poll_view.js | 5 +-- app/assets/stylesheets/poll.scss | 27 ++++++++++--- app/assets/templates/poll_tpl.jst.hbs | 39 +++++++------------ config/locales/javascript/javascript.en.yml | 4 ++ spec/javascripts/app/views/poll_view_spec.js | 8 ++-- 5 files changed, 46 insertions(+), 37 deletions(-) diff --git a/app/assets/javascripts/app/views/poll_view.js b/app/assets/javascripts/app/views/poll_view.js index 14355716d..751e47538 100644 --- a/app/assets/javascripts/app/views/poll_view.js +++ b/app/assets/javascripts/app/views/poll_view.js @@ -89,8 +89,8 @@ app.views.Poll = app.views.Base.extend({ }, toggleElements: function() { - this.$('.percentage').toggle(); - this.$('.progress').toggle(); + this.$(".poll-result").toggle(); + this.$(".progress").toggle(); }, clickSubmit: function(evt) { @@ -117,4 +117,3 @@ app.views.Poll = app.views.Base.extend({ }); // @license-end - diff --git a/app/assets/stylesheets/poll.scss b/app/assets/stylesheets/poll.scss index a561aeff2..e5d805270 100644 --- a/app/assets/stylesheets/poll.scss +++ b/app/assets/stylesheets/poll.scss @@ -4,10 +4,6 @@ margin: 10px 0; padding: 10px 0 5px; - .poll-content { - margin-top: 5px; - } - .toggle-result-wrapper { display: inline-block; margin-top: 10px; @@ -17,8 +13,6 @@ margin-bottom: 0; } - .result-row > label { width: 100%; } - .progress { background-image: none; box-shadow: 0 0 0; @@ -43,3 +37,24 @@ } } } + +.poll-content { + margin-top: 5px; + + [type=radio], + label { + font-weight: normal; + margin-bottom: 5px; + vertical-align: middle; + } + + [type=radio], + form .poll-result, + form .progress { + display: none; // Hide the result by default when the vote is possible + } + + form [type=radio] { + display: inline; + } +} diff --git a/app/assets/templates/poll_tpl.jst.hbs b/app/assets/templates/poll_tpl.jst.hbs index 9fda886df..e8410d5f4 100644 --- a/app/assets/templates/poll_tpl.jst.hbs +++ b/app/assets/templates/poll_tpl.jst.hbs @@ -9,35 +9,27 @@
{{#if show_form}}
- {{#poll.poll_answers}} -
- -
- {{/poll.poll_answers}} + {{/if}} + {{#poll.poll_answers}} +
+ + +
+ + ({{t "poll.answer_count" count=vote_count}}) +
+
+
+
+
+ {{/poll.poll_answers}} + {{#if show_form}}
- {{else}} - {{#poll.poll_answers}} -
- {{answer}} - -
-
-
-
-
- {{/poll.poll_answers}} {{/if}} {{#if is_reshare }} @@ -45,7 +37,6 @@ {{{t "poll.go_to_original_post" original_post_link=original_post_link}}}
{{/if}} - {{/if}} diff --git a/config/locales/javascript/javascript.en.yml b/config/locales/javascript/javascript.en.yml index 4e870e0b2..0e6f6ec1d 100644 --- a/config/locales/javascript/javascript.en.yml +++ b/config/locales/javascript/javascript.en.yml @@ -300,5 +300,9 @@ en: count: one: "1 vote so far" other: "<%=count%> votes so far" + answer_count: + zero: "0 votes" + one: "1 vote" + other: "<%=count%> votes" show_result: "Show result" close_result: "Hide result" diff --git a/spec/javascripts/app/views/poll_view_spec.js b/spec/javascripts/app/views/poll_view_spec.js index 0b9b7d5cc..bbd45511d 100644 --- a/spec/javascripts/app/views/poll_view_spec.js +++ b/spec/javascripts/app/views/poll_view_spec.js @@ -2,7 +2,7 @@ describe("app.views.Poll", function(){ beforeEach(function() { loginAs({name: "alice", avatar : {small : "http://avatar.com/photo.jpg"}}); this.view = new app.views.Poll({ model: factory.postWithPoll()}); - this.view.render(); + spec.content().html(this.view.render().el); }); describe("setProgressBar", function(){ @@ -15,9 +15,9 @@ describe("app.views.Poll", function(){ describe("toggleResult", function(){ it("toggles the progress bar and result", function(){ - expect(this.view.$('.poll_progress_bar_wrapper:first').css('display')).toBe("none"); - this.view.toggleResult(null); - expect(this.view.$('.poll_progress_bar_wrapper:first').css('display')).toBe("block"); + expect($(".poll_progress_bar_wrapper:first")).toBeHidden(); + this.view.toggleResult(); + expect($(".poll_progress_bar_wrapper:first")).toBeVisible(); }); });