diff --git a/app/assets/images/icons/poll.png b/app/assets/images/icons/poll.png new file mode 100644 index 0000000000000000000000000000000000000000..026a12a2b28c952e0df0159fd73bbf66b8dbbb84 Binary files /dev/null and b/app/assets/images/icons/poll.png differ diff --git a/app/assets/javascripts/app/views/publisher_view.js b/app/assets/javascripts/app/views/publisher_view.js index ae60f037632ba91cae2ae81d8d72a4348ffd0f39..4f020d7f78001c668b70d9648d3bd8047450db8e 100644 --- a/app/assets/javascripts/app/views/publisher_view.js +++ b/app/assets/javascripts/app/views/publisher_view.js @@ -133,6 +133,7 @@ app.views.Publisher = Backbone.View.extend({ // lulz this code should be killed. var statusMessage = new app.models.Post(); + statusMessage.save({ "status_message" : { "text" : serializedForm["status_message[text]"] @@ -142,11 +143,11 @@ app.views.Publisher = Backbone.View.extend({ "services" : serializedForm["services[]"], "location_address" : $("#location_address").val(), "location_coords" : serializedForm["location[coords]"], - "poll_question" : serializedForm["poll_question"] + "poll_question" : serializedForm["poll_question"], + "poll_answers" : serializedForm["poll_answers[]"] }, { url : "/status_messages", success : function() { - console.log(statusMessage); if(app.publisher) { $(app.publisher.el).trigger('ajax:success'); } @@ -191,7 +192,7 @@ app.views.Publisher = Backbone.View.extend({ var clone = this.el_poll_answer.clone(); var answer = clone.find('.poll_answer_input'); - answer.attr("name", "poll_answer_" + this.option_counter); + //answer.attr("name", "poll_answer_" + this.option_counter); var placeholder = answer.attr("placeholder"); var expression = /[^0-9]+/; diff --git a/app/controllers/status_messages_controller.rb b/app/controllers/status_messages_controller.rb index 78507fc81c2ece34caf1787ee1a9b25f54971046..1a083d31c819f0bbba89cf23aa07b194dbd5b784 100644 --- a/app/controllers/status_messages_controller.rb +++ b/app/controllers/status_messages_controller.rb @@ -50,9 +50,14 @@ class StatusMessagesController < ApplicationController @status_message = current_user.build_post(:status_message, params[:status_message]) @status_message.build_location(:address => params[:location_address], :coordinates => params[:location_coords]) if params[:location_address].present? @status_message.build_poll(:question => params[:poll_question]) if params[:poll_question].present? - - #save all answers for poll - + poll_answers = params[:poll_answers] + if params[:poll_answers].instance_of? String + poll_answers = [params[:poll_answers]] + end + + poll_answers.each do |poll_answer| + @status_message.poll.poll_answers.build(:answer => poll_answer) + end @status_message.attach_photos_by_ids(params[:photos]) @@ -83,7 +88,7 @@ class StatusMessagesController < ApplicationController respond_to do |format| format.html { redirect_to :back } format.mobile { redirect_to stream_path } - format.json { render :nothing => true , :status => 403 } + format.json { render {:nothing => true} , :status => 403 } end end end diff --git a/app/models/status_message.rb b/app/models/status_message.rb index aa79c69f7624b951139e4a28d778c3d070f79126..6e73ecb48ce67b36029915c19b03fe70f3462e68 100644 --- a/app/models/status_message.rb +++ b/app/models/status_message.rb @@ -25,7 +25,8 @@ class StatusMessage < Post has_many :photos, :dependent => :destroy, :foreign_key => :status_message_guid, :primary_key => :guid has_one :location - has_one :poll + has_one :poll, autosave: true + # a StatusMessage is federated before its photos are so presence_of_content() fails erroneously if no text is present # therefore, we put the validation in a before_destory callback instead of a validation diff --git a/app/views/publisher/_publisher_blueprint.html.haml b/app/views/publisher/_publisher_blueprint.html.haml index a34e10893822f5db5203dbf55a2ab2ebbd0adc07..daefa53c233058fd81374982ebac7f0de472fa55 100644 --- a/app/views/publisher/_publisher_blueprint.html.haml +++ b/app/views/publisher/_publisher_blueprint.html.haml @@ -29,7 +29,7 @@ %span.markdownIndications != t('shared.publisher.formatWithMarkdown', markdown_link: link_to(t('help.markdown'), 'https://diasporafoundation.org/formatting', target: :blank)) #poll_creator.btn{:title => t('.create_poll')} - = image_tag 'icons/marker.png', :alt => t('.create_poll').titleize, :class => 'publisher_image' + = image_tag 'icons/poll.png', :alt => t('.create_poll').titleize, :class => 'publisher_image' #locator.btn{:title => t('shared.publisher.get_location')} = image_tag 'icons/marker.png', :alt => t('shared.publisher.get_location').titleize, :class => 'publisher_image' #file-upload.btn{:title => t('shared.publisher.upload_photos')} @@ -42,7 +42,7 @@ %input{:id => 'poll_question', :placeholder => t('shared.publisher.poll.question'), :name => 'poll_question'} .poll_answer %span{:class => 'poll_answer_input_wrapper'} - %input{:class => 'poll_answer_input', :placeholder => t('shared.publisher.poll.option'), :name => 'poll_answer_1'} + %input{:class => 'poll_answer_input', :placeholder => t('shared.publisher.poll.option'), :name => 'poll_answers[]'} %a{:class => 'remove_poll_answer'} = t('shared.publisher.poll.remove_poll_answer') #add_poll_answer_wrapper