diff --git a/app/assets/images/icons/poll.png b/app/assets/images/icons/poll.png deleted file mode 100644 index 026a12a2b..000000000 Binary files a/app/assets/images/icons/poll.png and /dev/null differ diff --git a/app/assets/javascripts/app/views/poll.js b/app/assets/javascripts/app/views/poll.js index c7f9ebaab..31fa48379 100644 --- a/app/assets/javascripts/app/views/poll.js +++ b/app/assets/javascripts/app/views/poll.js @@ -2,7 +2,8 @@ app.views.Poll = app.views.Base.extend({ templateName : "poll", events : { - "click .submit" : "vote" + "click .submit" : "vote", + "click .toggle_result" : "toggleResult" }, initialize : function(options) { @@ -14,6 +15,13 @@ app.views.Poll = app.views.Base.extend({ postRenderTemplate : function() { if(this.poll) { this.setProgressBar(); + this.hideResult(); + } + }, + + hideResult : function() { + if(!this.model.attributes.already_participated_in_poll) { + this.$('.poll_result').hide(); } }, @@ -24,27 +32,52 @@ app.views.Poll = app.views.Base.extend({ if(this.poll.participation_count != 0) { percentage = answers[index].vote_count / this.poll.participation_count * 100; } - var input = this.$("input[value="+answers[index].id+"]"); - var progressBar = $(input).parent().find(".poll_progress_bar"); + var progressBar = this.$(".poll_progress_bar[data-answerid="+answers[index].id+"]"); + progressBar.parents().eq(1).find(".percentage").html(" - " + percentage + "%"); var width = percentage * this.progressBarFactor; progressBar.css("width", width + "px"); } - // + }, + + toggleResult : function(e) { + $('.poll_result').toggle(); + return false; + }, + + refreshResult : function(answerId) { + this.updateCounter(answerId); + this.setProgressBar(); + }, + + updateCounter : function(answerId) { + this.poll.participation_count++; + this.$('.poll_statistic').html(Diaspora.I18n.t("poll.count", {"votes" : this.poll.participation_count})); + var answers = this.poll.poll_answers; + for(index = 0; index < answers.length; ++index) { + if(answers[index].id == answerId) { + answers[index].vote_count++; + return; + } + } }, vote : function(evt){ var result = parseInt($(evt.target).parent().find("input[name=vote]:checked").val()); var pollParticipation = new app.models.PollParticipation(); + var parent = this; pollParticipation.save({ "poll_answer_id" : result, "poll_id" : this.poll.poll_id, },{ url : "/posts/"+this.poll.post_id+"/poll_participations", - success : function() { - console.log(success); - //todo remove radios+input + success : function(model, response) { + parent.$('.poll_form form').remove(); + parent.$('.toggle_result_wrapper').remove(); + parent.$('.poll_result').show(); + parent.refreshResult(result); } }); + return false; } }); \ No newline at end of file diff --git a/app/assets/javascripts/app/views/publisher_view.js b/app/assets/javascripts/app/views/publisher_view.js index dc51575a9..b8062347e 100644 --- a/app/assets/javascripts/app/views/publisher_view.js +++ b/app/assets/javascripts/app/views/publisher_view.js @@ -75,7 +75,7 @@ app.views.Publisher = Backbone.View.extend({ }); this.initSubviews(); - + this.addPollAnswer(); return this; }, @@ -202,7 +202,7 @@ app.views.Publisher = Backbone.View.extend({ }, removePollAnswer: function(evt){ - $(evt.target).parent().remove(); + $(evt.target).parents().eq(1).remove(); if($(".poll_answer").size() == 1) { $(".remove_poll_answer").css("visibility","hidden");; } diff --git a/app/assets/stylesheets/poll.css.scss b/app/assets/stylesheets/poll.css.scss index 913bd69be..f72039acb 100644 --- a/app/assets/stylesheets/poll.css.scss +++ b/app/assets/stylesheets/poll.css.scss @@ -14,16 +14,15 @@ .poll_result { width:100%px; - display:inline; } .poll_progress_bar { position:absolute; - width:100px; + width:0px; height:15px; top:-10px; z-index:-1; - background-color:#3f8fba; + background-color:$background-grey; } .poll_statistic{ @@ -38,6 +37,9 @@ } .poll_answer_entry{ - display:inline; width:100%; } + +.percentage { + display:inline; +} diff --git a/app/assets/stylesheets/publisher_blueprint.css.scss b/app/assets/stylesheets/publisher_blueprint.css.scss index e01fef626..f4cb7171f 100644 --- a/app/assets/stylesheets/publisher_blueprint.css.scss +++ b/app/assets/stylesheets/publisher_blueprint.css.scss @@ -311,7 +311,8 @@ } #poll_creator { @extend #locator; - right: 50px; + right: 60px; + margin-bottom:-5px; } .btn { @@ -331,6 +332,12 @@ visibility:hidden; float:right; display: table-cell; + + .icons-deletelabel { + height: 14px; + width: 14px; + margin-top:5px; + } } .poll_answer_input { @@ -342,6 +349,10 @@ display:block; } +#poll_question_wrapper { + margin-right:24px; +} + #poll_question { width: 100%; box-sizing: border-box; diff --git a/app/assets/templates/poll_tpl.jst.hbs b/app/assets/templates/poll_tpl.jst.hbs index 6cac9b4d2..0d10be448 100644 --- a/app/assets/templates/poll_tpl.jst.hbs +++ b/app/assets/templates/poll_tpl.jst.hbs @@ -1,19 +1,32 @@ {{#if poll}}
{{t "poll.result" votes=poll.participation_count}}
+{{t "poll.count" votes=poll.participation_count}}
{{poll.question}}
+
{{t "poll.toggle_result"}}
+