From 04199837b3eef45c02789e02e4dd45a16f54d9d3 Mon Sep 17 00:00:00 2001 From: Jannik Streek <theshowcanbegin@gmail.com> Date: Sun, 23 Mar 2014 20:38:12 +0100 Subject: [PATCH] poll creation done --- app/assets/images/icons/poll.png | Bin 0 -> 187 bytes .../javascripts/app/views/publisher_view.js | 7 ++++--- app/controllers/status_messages_controller.rb | 13 +++++++++---- app/models/status_message.rb | 3 ++- .../publisher/_publisher_blueprint.html.haml | 4 ++-- 5 files changed, 17 insertions(+), 10 deletions(-) create mode 100644 app/assets/images/icons/poll.png diff --git a/app/assets/images/icons/poll.png b/app/assets/images/icons/poll.png new file mode 100644 index 0000000000000000000000000000000000000000..026a12a2b28c952e0df0159fd73bbf66b8dbbb84 GIT binary patch literal 187 zcmeAS@N?(olHy`uVBq!ia0vp^qChOj!3HFa+MYK6DVB6cUq=Rp^(V|(yIunMk|nMY zCBgY=CFO}lsSJ)O`AMk?p1FzXsX?iUDV2pMQ*D5Xd_7$pLn>}1{rUgjo_Q<d;}r`J zpSTdYIqmA98=0AzXIriqPkhjzmL$3<;Be}a9a}o@7^EgGU`$YS7hd>a;gO}jPb&8J ix%|s8Yh`F)U}lher}N)Cdt)=uU<OZDKbLh*2~7ZY14L8+ literal 0 HcmV?d00001 diff --git a/app/assets/javascripts/app/views/publisher_view.js b/app/assets/javascripts/app/views/publisher_view.js index ae60f03763..4f020d7f78 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 78507fc81c..1a083d31c8 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 aa79c69f76..6e73ecb48c 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 a34e108938..daefa53c23 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 -- GitLab