Skip to content

Commit

Permalink
Refactor poll view code
Browse files Browse the repository at this point in the history
  • Loading branch information
Flaburgan committed Jan 15, 2016
1 parent c062c47 commit 0e8a293
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 34 deletions.
19 changes: 17 additions & 2 deletions app/assets/stylesheets/poll.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,23 @@
margin-bottom: 0;
}

.result-row > label {
width: 100%;
.poll-content {
input[type=radio],
label {
vertical-align: middle;
margin-bottom: 5px;
font-weight: normal;
}

input[type=radio],
form .poll-result,
form .progress {
display: none; // Hide the result by default when the vote is possible
}

form input[type=radio] {
display: inline;
}
}

.progress {
Expand Down
45 changes: 15 additions & 30 deletions app/assets/templates/poll_tpl.jst.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -9,49 +9,34 @@
<div class="poll-content">
{{#if show_form}}
<form action="/posts/{{poll.post_id}}/poll_participations" method="POST">
{{#poll.poll_answers}}
<div class="radio result-row">
<label>
<input type="radio" name="vote" value="{{id}}"/>
{{answer}}
<div class="poll-result pull-right" style="display: none;">
<span class="percentage"></span>
({{t "poll.answer_count" count=vote_count}})
</div>
<div class="poll_progress_bar_wrapper progress" style="display: none">
<div class="poll_progress_bar bar" data-answerid="{{id}}" style="height: 100%"></div>
</div>
</label>
</div>
{{/poll.poll_answers}}
{{/if}}
{{#poll.poll_answers}}
<div class="result-row">
<input type="radio" name="vote" value="{{id}}"/>
<label>{{answer}}</label>
<div class="poll-result pull-right">
<span class="percentage"></span>
({{t "poll.answer_count" count=vote_count}})
</div>
<div class="poll_progress_bar_wrapper progress">
<div class="poll_progress_bar bar" data-answerid="{{id}}" style="height: 100%"></div>
</div>
</div>
{{/poll.poll_answers}}
{{#if show_form}}
<div class="toggle-result-wrapper">
<a class="toggle_result" href="#">{{t "poll.show_result"}}</a>
</div>
<input type="submit" class="submit pull-right btn btn-default" value="{{t "poll.vote"}}"/>
<div class="clearfix"></div>
</form>
{{else}}
{{#poll.poll_answers}}
<div class="result-row">
{{answer}}
<div class="poll-result pull-right">
<span class="percentage"></span>
({{t "poll.answer_count" count=vote_count}})
</div>
<div class="poll_progress_bar_wrapper progress">
<div class="poll_progress_bar bar" data-answerid="{{id}}">
</div>
</div>
</div>
{{/poll.poll_answers}}
{{/if}}

{{#if is_reshare }}
<div class="poll_footer">
{{{t "poll.go_to_original_post" original_post_link=original_post_link}}}
</div>
{{/if}}

</div>
</div>
{{/if}}
2 changes: 0 additions & 2 deletions config/locales/javascript/javascript.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -297,11 +297,9 @@ en:
original_post: "original post"
result: "Result"
count:
zero: "No vote so far"
one: "1 vote so far"
other: "<%=count%> votes so far"
answer_count:
zero: "0 vote"
one: "1 vote"
other: "<%=count%> votes"
show_result: "Show result"
Expand Down

0 comments on commit 0e8a293

Please sign in to comment.