Skip to content

Commit

Permalink
Make poll to be compatible with bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
hpetru committed Apr 3, 2014
1 parent fed5ea8 commit cee90e7
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 40 deletions.
2 changes: 1 addition & 1 deletion app/assets/javascripts/app/models/poll_participation.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
app.models.PollParticipation = Backbone.Model.extend({
urlRoot: function(){
return 'posts/' + this.get('post_id') + "/poll_participations";
return '/posts/' + this.get('post_id') + "/poll_participations";
}
});
17 changes: 17 additions & 0 deletions app/assets/javascripts/app/views/poll_blueprint_view.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//= require ./poll_view
app.views.PollBlueprint = app.views.Poll.extend({
templateName: 'poll_blueprint',

initialize: function(options) {
this.constructor.__super__.initialize.apply(this, options);
this.progressBarFactor = 3;
},
setProgressBarData: function(progressBar, percent) {
progressBar.css('width', percent * this.progressBarFactor + 'px');
progressBar.parent().next().html(" - " + percent + "%");
},
toggleElements: function() {
this.$('.poll_progress_bar_wrapper').toggle();
this.$('.percentage').toggle();
}
});
23 changes: 14 additions & 9 deletions app/assets/javascripts/app/views/poll_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ app.views.Poll = app.views.Base.extend({

postRenderTemplate: function() {
this.poll = this.model.attributes.poll;
this.progressBarFactor = 3;
this.setProgressBar();
},

Expand All @@ -30,19 +29,20 @@ app.views.Poll = app.views.Base.extend({
}

var progressBar = _this.$(".poll_progress_bar[data-answerid="+answer.id+"]");
var width = percent * _this.progressBarFactor;

progressBar.parent().next().html(" - " + percent + "%");
progressBar.css("width", width + "px");
_this.setProgressBarData(progressBar, percent);
});
},

toggleResult: function(e) {
if(e)
e.preventDefault();
setProgressBarData: function(progressBar, percent) {
progressBar.css("width", percent + "%");
progressBar.parents('.result-row').find('.percentage').text(percent + "%");
},

this.$('.poll_progress_bar_wrapper').toggle();
this.$('.percentage').toggle();
toggleResult: function(evt) {
if(evt) evt.preventDefault();

this.toggleElements();

var toggle_result = this.$('.toggle_result');

Expand All @@ -56,6 +56,11 @@ app.views.Poll = app.views.Base.extend({
}
},

toggleElements: function() {
this.$('.percentage').toggle();
this.$('.progress').toggle();
},

clickSubmit: function(evt) {
evt.preventDefault();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ app.views.SinglePostContent = app.views.Base.extend({
'#real-post-content' : 'postContentView',
".oembed" : "oEmbedView",
".opengraph" : "openGraphView",
".status-message-location" : "postLocationStreamView"
".status-message-location" : "postLocationStreamView",
'.poll': 'pollView',
},

initialize : function() {
this.singlePostActionsView = new app.views.SinglePostActions({model: this.model});
this.oEmbedView = new app.views.OEmbed({model : this.model});
this.openGraphView = new app.views.OpenGraph({model : this.model});
this.postContentView = new app.views.ExpandedStatusMessage({model: this.model});
this.pollView = new app.views.Poll({ model: this.model });
},

postLocationStreamView : function(){
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/app/views/stream_post_views.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ app.views.StreamPost = app.views.Post.extend({
this.commentStreamView = new app.views.CommentStream({model : this.model});
this.oEmbedView = new app.views.OEmbed({model : this.model});
this.openGraphView = new app.views.OpenGraph({model : this.model});
this.pollView = new app.views.Poll({model : this.model});
this.pollView = new app.views.PollBlueprint({model : this.model});
},


Expand Down
1 change: 1 addition & 0 deletions app/assets/stylesheets/new-templates.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
@import 'bootstrap-headerfix';
@import 'opengraph';
@import 'single-post-view';
@import 'new_styles/poll';

/* conversations */
@import 'conversations';
Expand Down
35 changes: 35 additions & 0 deletions app/assets/stylesheets/new_styles/_poll.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@import '../colors';
@import '../mixins';
@import 'new_mixins';

.poll_form {
border-top: 1px solid $border-grey;
border-bottom: 1px solid $border-grey;
margin: 10px 0px 10px 0px;
padding: 10px 0px 5px 0px;

.poll_content {
margin-top: 5px;
}
.toggle_result_wrapper {
display: inline-block;
margin-top: 10px;
}
form {
margin-bottom: 0px;
}

.progress {
background-image: none;
@include box-shadow(0, 0, 0);
margin-bottom: 5px;
height: 10px !important;

.bar {
background-image: none;
background-color: $border-dark-grey;
color: $text-dark-grey;
text-align: left;
}
}
}
32 changes: 32 additions & 0 deletions app/assets/templates/poll_blueprint_tpl.jst.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{{#if poll}}
<div class="poll_form">
<p class="poll_statistic">{{t "poll.count" count=poll.participation_count}}</p>
<strong>{{poll.question}}</strong><br/>
{{#unless already_participated_in_poll}}
<form action="/posts/{{poll.post_id}}/poll_participations" method="POST">
{{#poll.poll_answers}}
<input type="radio" name="vote" value="{{id}}"/>
<div class="poll_progress_bar_wrapper" style="display:none;">
<div class="poll_progress_bar" data-answerid="{{id}}"></div>
</div>
{{answer}}
<p class="percentage" style="display:none;"></p>
<br/>
{{/poll.poll_answers}}
<input type="submit" class="button submit" style="float:right;" value="{{t "poll.vote"}}"/>
</form>
<p class="toggle_result_wrapper">
<br/><a href="#" class="toggle_result">{{t "poll.show_result"}}</a><br/>
</p>
{{else}}
{{#poll.poll_answers}}
<div class="poll_progress_bar_wrapper">
<div class="poll_progress_bar" data-answerid="{{id}}"></div>
</div>
{{answer}}
<p class="percentage"></p>
<br/>
{{/poll.poll_answers}}
{{/unless}}
</div>
{{/if}}
62 changes: 36 additions & 26 deletions app/assets/templates/poll_tpl.jst.hbs
Original file line number Diff line number Diff line change
@@ -1,32 +1,42 @@
{{#if poll}}
<div class="poll_form">
<p class="poll_statistic">{{t "poll.count" count=poll.participation_count}}</p>
<strong>{{poll.question}}</strong><br/>
{{#unless already_participated_in_poll}}
<form action="/posts/{{poll.post_id}}/poll_participations" method="POST">
<div class="row-fluid poll_head">
<strong>{{{poll.question}}}</strong>
<div class="poll_statistic pull-right">
{{t "poll.count" count=poll.participation_count}}
</div>
</div>
<div class="row-fluid poll_content">
{{#unless already_participated_in_poll}}
<form action="/posts/{{poll.post_id}}/poll_participations" method="POST">
{{#poll.poll_answers}}
<label class="radio result-row">
<input type="radio" name="vote" value="{{id}}"/>
{{answer}}
<span class="percentage pull-right" style="display: none;"></span>
<div class="poll_progress_bar_wrapper progress" style="display: none">
<div class="poll_progress_bar bar" data-answerid="{{id}}">
</div>
</div>
</label>
{{/poll.poll_answers}}
<div class="toggle_result_wrapper">
<a class="toggle_result" href="#">{{t "poll.show_result"}}</a>
</div>
<input type="submit" class="button submit pull-rigth btn" style="float:right;" value="{{t "poll.vote"}}"/>
</form>
{{else}}
{{#poll.poll_answers}}
<input type="radio" name="vote" value="{{id}}"/>
<div class="poll_progress_bar_wrapper" style="display:none;">
<div class="poll_progress_bar" data-answerid="{{id}}"></div>
<div class="result-row">
{{answer}}
<span class="percentage pull-right"></span>
<div class="poll_progress_bar_wrapper progress">
<div class="poll_progress_bar bar" data-answerid="{{id}}">
</div>
</div>
</div>
{{answer}}
<p class="percentage" style="display:none;"></p>
<br/>
{{/poll.poll_answers}}
<input type="submit" class="button submit" style="float:right;" value="{{t "poll.vote"}}"/>
</form>
<p class="toggle_result_wrapper">
<br/><a href="#" class="toggle_result">{{t "poll.show_result"}}</a><br/>
</p>
{{else}}
{{#poll.poll_answers}}
<div class="poll_progress_bar_wrapper">
<div class="poll_progress_bar" data-answerid="{{id}}"></div>
</div>
{{answer}}
<p class="percentage"></p>
<br/>
{{/poll.poll_answers}}
{{/unless}}
{{/unless}}
</div>
</div>
{{/if}}
{{/if}}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
describe("app.views.Poll", function(){
describe("app.views.PollBlueprint", function(){
beforeEach(function() {
loginAs({name: "alice", avatar : {small : "http://avatar.com/photo.jpg"}});
this.view = new app.views.Poll({ "model" : factory.postWithPoll()});
this.view = new app.views.PollBlueprint({ model: factory.postWithPoll()});
this.view.render();
});

Expand Down

0 comments on commit cee90e7

Please sign in to comment.