Merge pull request #4899 from hpetru/poll-in-post-preview

Add poll in post preview
This commit is contained in:
Jonne Haß 2014-04-04 14:06:55 +02:00
commit 5a60cb72bf
5 changed files with 60 additions and 7 deletions

View file

@ -41,7 +41,7 @@
* Added comment count to statistic to enable calculations of posts/comments ratios [#4799](https://github.com/diaspora/diaspora/pull/4799)
* Add filters to notifications controller [#4814](https://github.com/diaspora/diaspora/pull/4814)
* Activate hovercards in SPV and conversations [#4870](https://github.com/diaspora/diaspora/pull/4870)
* Added possibility to conduct polls [#4861](https://github.com/diaspora/diaspora/pull/4861) [#4894](https://github.com/diaspora/diaspora/pull/4894) [#4897](https://github.com/diaspora/diaspora/pull/4897)
* Added possibility to conduct polls [#4861](https://github.com/diaspora/diaspora/pull/4861) [#4894](https://github.com/diaspora/diaspora/pull/4894) [#4897](https://github.com/diaspora/diaspora/pull/4897) [#4899](https://github.com/diaspora/diaspora/pull/4899)
# 0.3.0.3

View file

@ -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);
},

View file

@ -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);

View file

@ -32,4 +32,12 @@
text-align: left;
}
}
.submit[disabled] {
cursor: default;
color: $light-grey;
&:hover, &:active {
background-image: none;
}
}
}

View file

@ -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"