-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/3676 Conduct Polls #4861
Changes from all commits
dfbe17d
fe67bdf
5d56060
8a4f833
c02414c
95d98ff
18a4329
0419983
d0a77ce
e4c68a4
12fabe2
c484b2c
9c24365
7dcf11e
8f9736a
a9843ae
dde39aa
2d0abba
a3837a4
167884e
4174b88
6f3844b
4130592
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,3 +65,6 @@ dump.rdb | |
|
||
#Rubinius's JIT | ||
*.rbc | ||
|
||
#IDE | ||
diaspora.iml | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
app.models.PollParticipation = Backbone.Model.extend({ | ||
url : function(){ | ||
"/poll_participations" | ||
} | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
app.views.Poll = app.views.Base.extend({ | ||
templateName : "poll", | ||
|
||
events : { | ||
"click .submit" : "vote", | ||
"click .toggle_result" : "toggleResult" | ||
}, | ||
|
||
initialize : function(options) { | ||
this.poll = this.model.attributes.poll; | ||
this.progressBarFactor = 3; | ||
this.toggleMode = 0; | ||
}, | ||
|
||
postRenderTemplate : function() { | ||
if(this.poll) { | ||
this.setProgressBar(); | ||
} | ||
}, | ||
|
||
removeForm : function() { | ||
var cnt = this.$("form").contents(); | ||
this.$("form").replaceWith(cnt); | ||
this.$('input').remove(); | ||
this.$('submit').remove(); | ||
this.$('.toggle_result_wrapper').remove(); | ||
}, | ||
|
||
setProgressBar : function() { | ||
var answers = this.poll.poll_answers; | ||
for(index = 0; index < answers.length; ++index) { | ||
var percentage = 0; | ||
if(this.poll.participation_count != 0) { | ||
percentage = Math.round(answers[index].vote_count / this.poll.participation_count * 100); | ||
} | ||
var progressBar = this.$(".poll_progress_bar[data-answerid="+answers[index].id+"]"); | ||
progressBar.parent().next().html(" - " + percentage + "%"); | ||
var width = percentage * this.progressBarFactor; | ||
progressBar.css("width", width + "px"); | ||
} | ||
}, | ||
|
||
toggleResult : function(e) { | ||
this.$('.poll_progress_bar_wrapper').toggle(); | ||
this.$('.percentage').toggle(); | ||
if(this.toggleMode == 0) { | ||
this.$('.toggle_result').html(Diaspora.I18n.t("poll.close_result")); | ||
this.toggleMode = 1; | ||
}else{ | ||
this.$('.toggle_result').html(Diaspora.I18n.t("poll.show_result")); | ||
this.toggleMode = 0; | ||
} | ||
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", {"count" : 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(model, response) { | ||
parent.removeForm(); | ||
parent.refreshResult(result); | ||
if(parent.toggleMode == 0) { | ||
parent.toggleResult(null); | ||
} | ||
|
||
} | ||
}); | ||
return false; | ||
} | ||
|
||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
.poll_form { | ||
display: block; | ||
margin: 10px 0px 10px 0px; | ||
border-top: solid 1px $border-grey; | ||
border-bottom: solid 1px $border-grey; | ||
padding: 10px 0px 5px 0px; | ||
overflow: hidden; | ||
width: 100%; | ||
} | ||
|
||
.poll_form input[type="radio"] { | ||
display:inline !important; | ||
} | ||
|
||
.poll_result { | ||
width:100%px; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is that valid css/scss? Never saw anything like that before. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you mean the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No problem. Let's fix that in one of the next PRs. |
||
} | ||
|
||
.poll_progress_bar { | ||
position:absolute; | ||
width:0px; | ||
height:15px; | ||
top:-12px; | ||
z-index:-1; | ||
background-color:$background-grey; | ||
} | ||
|
||
.poll_statistic{ | ||
float:right; | ||
} | ||
|
||
.poll_progress_bar_wrapper { | ||
position: relative; | ||
width: 0; | ||
height: 0; | ||
display:inline-block; | ||
} | ||
|
||
.poll_answer_entry{ | ||
width:100%; | ||
} | ||
|
||
.percentage { | ||
display:inline; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh and I accepted this but as a little tip for the future: You can have a clone local ignore file by editing
.git/info/exclude