Poll answers are added dynamically on keypress
Removed add option button poll option can be added dynamically & last option removed if empty upon submission Poll answer can be added dynamically by losing focus poll option can be added dynamically & last option removed if empty upon submission refractored to avoid repetition of publisher:sync event poll option can be added dynamically & last option removed if empty upon submission Added a missing semicolon
This commit is contained in:
parent
80a0a9f999
commit
aa11f7c261
5 changed files with 39 additions and 16 deletions
|
|
@ -2,7 +2,7 @@ app.views.PublisherPollCreator = app.views.Base.extend({
|
||||||
templateName: "poll_creator",
|
templateName: "poll_creator",
|
||||||
|
|
||||||
events: {
|
events: {
|
||||||
'click .add-answer .button': 'clickAddAnswer',
|
'keypress input:last': 'addAnswer',
|
||||||
'click .remove-answer': 'removeAnswer',
|
'click .remove-answer': 'removeAnswer',
|
||||||
'blur input': 'validate',
|
'blur input': 'validate',
|
||||||
'input input': 'validate'
|
'input input': 'validate'
|
||||||
|
|
@ -12,13 +12,13 @@ app.views.PublisherPollCreator = app.views.Base.extend({
|
||||||
this.$pollAnswers = this.$('.poll-answers');
|
this.$pollAnswers = this.$('.poll-answers');
|
||||||
this.inputCount = 2;
|
this.inputCount = 2;
|
||||||
this.trigger('change');
|
this.trigger('change');
|
||||||
|
this.bind('publisher:sync', this.render, this);
|
||||||
},
|
},
|
||||||
|
|
||||||
clickAddAnswer: function(evt){
|
addAnswer: function(evt){
|
||||||
evt.preventDefault();
|
if (!$(evt.target).val()) {
|
||||||
|
|
||||||
this.addAnswerInput();
|
this.addAnswerInput();
|
||||||
this.trigger('change');
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
addAnswerInput: function(){
|
addAnswerInput: function(){
|
||||||
|
|
@ -47,6 +47,13 @@ app.views.PublisherPollCreator = app.views.Base.extend({
|
||||||
this.toggleRemoveAnswer();
|
this.toggleRemoveAnswer();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
removeLastAnswer: function (){
|
||||||
|
var inputs = this.$pollAnswers.find('input');
|
||||||
|
if(inputs.length > 2) {
|
||||||
|
this.$el.find('.poll-answer:last').remove();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
toggleRemoveAnswer: function(){
|
toggleRemoveAnswer: function(){
|
||||||
var inputs = this.$pollAnswers.find('input');
|
var inputs = this.$pollAnswers.find('input');
|
||||||
if(inputs.length < 3){
|
if(inputs.length < 3){
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,11 @@ app.views.Publisher = Backbone.View.extend({
|
||||||
this.showSpinner(false);
|
this.showSpinner(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// resetting the poll view
|
||||||
|
this.on('publisher:sync', function() {
|
||||||
|
this.view_poll_creator.render();
|
||||||
|
});
|
||||||
|
|
||||||
this.initSubviews();
|
this.initSubviews();
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
@ -150,6 +155,7 @@ app.views.Publisher = Backbone.View.extend({
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
if(evt){ evt.preventDefault(); }
|
if(evt){ evt.preventDefault(); }
|
||||||
|
this.view_poll_creator.removeLastAnswer();
|
||||||
|
|
||||||
//add missing mentions at end of post:
|
//add missing mentions at end of post:
|
||||||
this.handleTextchange();
|
this.handleTextchange();
|
||||||
|
|
@ -179,6 +185,7 @@ app.views.Publisher = Backbone.View.extend({
|
||||||
if( app.publisher ) {
|
if( app.publisher ) {
|
||||||
app.publisher.$el.trigger('ajax:success');
|
app.publisher.$el.trigger('ajax:success');
|
||||||
app.publisher.trigger('publisher:sync');
|
app.publisher.trigger('publisher:sync');
|
||||||
|
self.view_poll_creator.trigger('publisher:sync');
|
||||||
}
|
}
|
||||||
|
|
||||||
if(app.stream) app.stream.addNow(statusMessage.toJSON());
|
if(app.stream) app.stream.addNow(statusMessage.toJSON());
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,4 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="control-group add-answer">
|
|
||||||
<div href="#" class="button creation">
|
|
||||||
{{t 'publisher.add_option' }}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
|
||||||
|
|
@ -23,14 +23,16 @@ Feature: posting with a poll
|
||||||
Given "#publisher-poll-creator" is hidden
|
Given "#publisher-poll-creator" is hidden
|
||||||
When I expand the publisher
|
When I expand the publisher
|
||||||
And I press the element "#poll_creator"
|
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
|
Then I should see 3 options
|
||||||
|
|
||||||
Scenario: delete an option
|
Scenario: delete an option
|
||||||
Given "#publisher-poll-creator" is hidden
|
Given "#publisher-poll-creator" is hidden
|
||||||
When I expand the publisher
|
When I expand the publisher
|
||||||
And I press the element "#poll_creator"
|
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
|
And I delete the last option
|
||||||
Then I should see 2 option
|
Then I should see 2 option
|
||||||
And I should not see a remove icon
|
And I should not see a remove icon
|
||||||
|
|
|
||||||
|
|
@ -23,11 +23,22 @@ When /^I check the first option$/ do
|
||||||
first(".poll_form input").click
|
first(".poll_form input").click
|
||||||
end
|
end
|
||||||
|
|
||||||
And /^I press the element "([^"]*)"$/ do |selector|
|
When(/^I press the element "(.*?)"$/) do |selector|
|
||||||
page.should have_css(selector)
|
page.should have_css(selector)
|
||||||
find(selector).click
|
find(selector).click
|
||||||
end
|
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)
|
page.should have_css(selector)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue