diff --git a/app/assets/javascripts/app/views/publisher/poll_creator_view.js b/app/assets/javascripts/app/views/publisher/poll_creator_view.js index 158512e4a..f563485c9 100644 --- a/app/assets/javascripts/app/views/publisher/poll_creator_view.js +++ b/app/assets/javascripts/app/views/publisher/poll_creator_view.js @@ -2,7 +2,7 @@ app.views.PublisherPollCreator = app.views.Base.extend({ templateName: "poll_creator", events: { - 'click .add-answer .button': 'clickAddAnswer', + 'keypress input:last': 'addAnswer', 'click .remove-answer': 'removeAnswer', 'blur input': 'validate', 'input input': 'validate' @@ -12,13 +12,13 @@ app.views.PublisherPollCreator = app.views.Base.extend({ this.$pollAnswers = this.$('.poll-answers'); this.inputCount = 2; this.trigger('change'); + this.bind('publisher:sync', this.render, this); }, - - clickAddAnswer: function(evt){ - evt.preventDefault(); - this.addAnswerInput(); - this.trigger('change'); + addAnswer: function(evt){ + if (!$(evt.target).val()) { + this.addAnswerInput(); + } }, addAnswerInput: function(){ @@ -47,6 +47,13 @@ app.views.PublisherPollCreator = app.views.Base.extend({ this.toggleRemoveAnswer(); }, + removeLastAnswer: function (){ + var inputs = this.$pollAnswers.find('input'); + if(inputs.length > 2) { + this.$el.find('.poll-answer:last').remove(); + } + }, + toggleRemoveAnswer: function(){ var inputs = this.$pollAnswers.find('input'); if(inputs.length < 3){ @@ -96,7 +103,7 @@ app.views.PublisherPollCreator = app.views.Base.extend({ var _this = this; return _.every(this.$('input:visible'), function(input){ - if(_this.isValidInput($(input))) + if(_this.isValidInput($(input))) return true; }); } diff --git a/app/assets/javascripts/app/views/publisher_view.js b/app/assets/javascripts/app/views/publisher_view.js index 6d983737d..01d495dae 100644 --- a/app/assets/javascripts/app/views/publisher_view.js +++ b/app/assets/javascripts/app/views/publisher_view.js @@ -82,6 +82,11 @@ app.views.Publisher = Backbone.View.extend({ this.showSpinner(false); }); + // resetting the poll view + this.on('publisher:sync', function() { + this.view_poll_creator.render(); + }); + this.initSubviews(); return this; }, @@ -150,6 +155,7 @@ app.views.Publisher = Backbone.View.extend({ var self = this; if(evt){ evt.preventDefault(); } + this.view_poll_creator.removeLastAnswer(); //add missing mentions at end of post: this.handleTextchange(); @@ -179,6 +185,7 @@ app.views.Publisher = Backbone.View.extend({ if( app.publisher ) { app.publisher.$el.trigger('ajax:success'); app.publisher.trigger('publisher:sync'); + self.view_poll_creator.trigger('publisher:sync'); } if(app.stream) app.stream.addNow(statusMessage.toJSON()); diff --git a/app/assets/templates/poll_creator_tpl.jst.hbs b/app/assets/templates/poll_creator_tpl.jst.hbs index e8d50a84d..95e5cfcd4 100644 --- a/app/assets/templates/poll_creator_tpl.jst.hbs +++ b/app/assets/templates/poll_creator_tpl.jst.hbs @@ -17,8 +17,4 @@ -
-
- {{t 'publisher.add_option' }} -
-
+ diff --git a/features/desktop/post_with_a_poll.feature b/features/desktop/post_with_a_poll.feature index f2f64cd67..807ec908f 100644 --- a/features/desktop/post_with_a_poll.feature +++ b/features/desktop/post_with_a_poll.feature @@ -23,14 +23,16 @@ Feature: posting with a poll Given "#publisher-poll-creator" is hidden When I expand the publisher And I press the element "#poll_creator" - And I press the element ".add-answer .button.creation" + And I fill in values for the first two options + And I lose focus Then I should see 3 options Scenario: delete an option Given "#publisher-poll-creator" is hidden When I expand the publisher And I press the element "#poll_creator" - And I press the element ".add-answer .button.creation" + And I fill in values for the first two options + And I lose focus And I delete the last option Then I should see 2 option And I should not see a remove icon diff --git a/features/step_definitions/post_with_poll_steps.rb b/features/step_definitions/post_with_poll_steps.rb index 60fb3eeb7..7dd3abba1 100644 --- a/features/step_definitions/post_with_poll_steps.rb +++ b/features/step_definitions/post_with_poll_steps.rb @@ -23,11 +23,22 @@ When /^I check the first option$/ do first(".poll_form input").click end -And /^I press the element "([^"]*)"$/ do |selector| +When(/^I press the element "(.*?)"$/) do |selector| page.should have_css(selector) find(selector).click end -Then /^I should see an element "([^"]*)"$/ do |selector| + +When(/^I fill in values for the first two options$/) do + all(".poll-answer input").each_with_index do |answer, i| + answer.set "answer option #{i}" + end +end + +When(/^I lose focus$/) do + find("#publisher-poll-creator").click +end + +Then /^I should see an element '([^"]*)'$/ do |selector| page.should have_css(selector) end