poll creation done

This commit is contained in:
Jannik Streek 2014-03-23 20:38:12 +01:00
parent 18a43295b7
commit 04199837b3
5 changed files with 17 additions and 10 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 187 B

View file

@ -133,6 +133,7 @@ app.views.Publisher = Backbone.View.extend({
// lulz this code should be killed. // lulz this code should be killed.
var statusMessage = new app.models.Post(); var statusMessage = new app.models.Post();
statusMessage.save({ statusMessage.save({
"status_message" : { "status_message" : {
"text" : serializedForm["status_message[text]"] "text" : serializedForm["status_message[text]"]
@ -142,11 +143,11 @@ app.views.Publisher = Backbone.View.extend({
"services" : serializedForm["services[]"], "services" : serializedForm["services[]"],
"location_address" : $("#location_address").val(), "location_address" : $("#location_address").val(),
"location_coords" : serializedForm["location[coords]"], "location_coords" : serializedForm["location[coords]"],
"poll_question" : serializedForm["poll_question"] "poll_question" : serializedForm["poll_question"],
"poll_answers" : serializedForm["poll_answers[]"]
}, { }, {
url : "/status_messages", url : "/status_messages",
success : function() { success : function() {
console.log(statusMessage);
if(app.publisher) { if(app.publisher) {
$(app.publisher.el).trigger('ajax:success'); $(app.publisher.el).trigger('ajax:success');
} }
@ -191,7 +192,7 @@ app.views.Publisher = Backbone.View.extend({
var clone = this.el_poll_answer.clone(); var clone = this.el_poll_answer.clone();
var answer = clone.find('.poll_answer_input'); 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 placeholder = answer.attr("placeholder");
var expression = /[^0-9]+/; var expression = /[^0-9]+/;

View file

@ -50,9 +50,14 @@ class StatusMessagesController < ApplicationController
@status_message = current_user.build_post(:status_message, params[:status_message]) @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_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? @status_message.build_poll(:question => params[:poll_question]) if params[:poll_question].present?
poll_answers = params[:poll_answers]
#save all answers for poll 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]) @status_message.attach_photos_by_ids(params[:photos])
@ -83,7 +88,7 @@ class StatusMessagesController < ApplicationController
respond_to do |format| respond_to do |format|
format.html { redirect_to :back } format.html { redirect_to :back }
format.mobile { redirect_to stream_path } format.mobile { redirect_to stream_path }
format.json { render :nothing => true , :status => 403 } format.json { render {:nothing => true} , :status => 403 }
end end
end end
end end

View file

@ -25,7 +25,8 @@ class StatusMessage < Post
has_many :photos, :dependent => :destroy, :foreign_key => :status_message_guid, :primary_key => :guid has_many :photos, :dependent => :destroy, :foreign_key => :status_message_guid, :primary_key => :guid
has_one :location 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 # 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 # therefore, we put the validation in a before_destory callback instead of a validation

View file

@ -29,7 +29,7 @@
%span.markdownIndications %span.markdownIndications
!= t('shared.publisher.formatWithMarkdown', markdown_link: link_to(t('help.markdown'), 'https://diasporafoundation.org/formatting', target: :blank)) != t('shared.publisher.formatWithMarkdown', markdown_link: link_to(t('help.markdown'), 'https://diasporafoundation.org/formatting', target: :blank))
#poll_creator.btn{:title => t('.create_poll')} #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')} #locator.btn{:title => t('shared.publisher.get_location')}
= image_tag 'icons/marker.png', :alt => t('shared.publisher.get_location').titleize, :class => 'publisher_image' = image_tag 'icons/marker.png', :alt => t('shared.publisher.get_location').titleize, :class => 'publisher_image'
#file-upload.btn{:title => t('shared.publisher.upload_photos')} #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'} %input{:id => 'poll_question', :placeholder => t('shared.publisher.poll.question'), :name => 'poll_question'}
.poll_answer .poll_answer
%span{:class => 'poll_answer_input_wrapper'} %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'} %a{:class => 'remove_poll_answer'}
= t('shared.publisher.poll.remove_poll_answer') = t('shared.publisher.poll.remove_poll_answer')
#add_poll_answer_wrapper #add_poll_answer_wrapper