Add poll in post preview
This commit is contained in:
parent
c634aba267
commit
f356ae7216
4 changed files with 59 additions and 6 deletions
|
|
@ -12,6 +12,7 @@ app.views.Poll = app.views.Base.extend({
|
|||
|
||||
postRenderTemplate: function() {
|
||||
this.poll = this.model.attributes.poll;
|
||||
this.pollButtons();
|
||||
this.setProgressBar();
|
||||
},
|
||||
|
||||
|
|
@ -39,9 +40,21 @@ app.views.Poll = app.views.Base.extend({
|
|||
progressBar.parents('.result-row').find('.percentage').text(percent + "%");
|
||||
},
|
||||
|
||||
toggleResult: function(evt) {
|
||||
if(evt) evt.preventDefault();
|
||||
pollButtons: function() {
|
||||
if(!this.poll || !this.poll.post_id) {
|
||||
this.$('.submit').attr('disabled', true);
|
||||
this.$('.toggle_result').attr('disabled', true);
|
||||
}
|
||||
},
|
||||
|
||||
toggleResult: function(evt) {
|
||||
if(evt) {
|
||||
evt.preventDefault();
|
||||
// Disable link
|
||||
if($(evt.target).attr('disabled')) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
this.toggleElements();
|
||||
|
||||
var toggle_result = this.$('.toggle_result');
|
||||
|
|
@ -64,7 +77,7 @@ app.views.Poll = app.views.Base.extend({
|
|||
clickSubmit: function(evt) {
|
||||
evt.preventDefault();
|
||||
|
||||
var answer_id = parseInt($(evt.target).parent().find("input[name=vote]:checked").val());
|
||||
var answer_id = parseInt(this.$("input[name=vote]:checked").val());
|
||||
this.vote(answer_id);
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -254,6 +254,23 @@ app.views.Publisher = Backbone.View.extend({
|
|||
}
|
||||
|
||||
var date = (new Date()).toISOString();
|
||||
|
||||
var poll = undefined;
|
||||
var poll_question = serializedForm["poll_question"];
|
||||
var poll_answers_arry = _.flatten([serializedForm["poll_answers[]"]]);
|
||||
var poll_answers = _.map(poll_answers_arry, function(answer){
|
||||
if(answer) return { 'answer' : answer };
|
||||
});
|
||||
poll_answers = _.without(poll_answers, undefined);
|
||||
|
||||
if(poll_question && poll_answers.length) {
|
||||
poll = {
|
||||
'question': poll_question,
|
||||
'poll_answers' : poll_answers,
|
||||
'participation_count': '0'
|
||||
};
|
||||
}
|
||||
|
||||
var previewMessage = {
|
||||
"id" : 0,
|
||||
"text" : serializedForm["status_message[text]"],
|
||||
|
|
@ -267,9 +284,9 @@ app.views.Publisher = Backbone.View.extend({
|
|||
"frame_name" : "status",
|
||||
"title" : serializedForm["status_message[text]"],
|
||||
"address" : $("#location_address").val(),
|
||||
"interactions" : {"likes":[],"reshares":[],"comments_count":0,"likes_count":0,"reshares_count":0}
|
||||
}
|
||||
|
||||
"interactions" : {"likes":[],"reshares":[],"comments_count":0,"likes_count":0,"reshares_count":0},
|
||||
'poll': poll,
|
||||
};
|
||||
if(app.stream) {
|
||||
this.removePostPreview();
|
||||
app.stream.addNow(previewMessage);
|
||||
|
|
|
|||
|
|
@ -32,4 +32,12 @@
|
|||
text-align: left;
|
||||
}
|
||||
}
|
||||
.submit[disabled] {
|
||||
cursor: default;
|
||||
color: $light-grey;
|
||||
|
||||
&:hover, &:active {
|
||||
background-image: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,3 +70,18 @@ Feature: preview posts in the stream
|
|||
And I press "Preview"
|
||||
Then "This preview rocks" should be post 1
|
||||
And the first post should be a preview
|
||||
|
||||
Scenario: preview a post with the poll
|
||||
Given I expand the publisher
|
||||
When I fill in the following:
|
||||
| status_message_fake_text | I am eating yogurt |
|
||||
And I press the element "#poll_creator"
|
||||
When I fill in the following:
|
||||
| status_message_fake_text | I am eating yogurt |
|
||||
| poll_question | What kind of yogurt do you like? |
|
||||
And I fill in the following for the options:
|
||||
| normal |
|
||||
| not normal |
|
||||
And I press "Preview"
|
||||
Then I should see a ".poll_form" within ".stream_element"
|
||||
And I should see a "form" within ".stream_element"
|
||||
|
|
|
|||
Loading…
Reference in a new issue