Poll input fields and data model now available
question field of poll now in db fixed merge issues
This commit is contained in:
parent
b207077405
commit
dfbe17d046
11 changed files with 161 additions and 22 deletions
|
|
@ -23,6 +23,9 @@ app.views.Publisher = Backbone.View.extend({
|
||||||
"click .post_preview_button" : "createPostPreview",
|
"click .post_preview_button" : "createPostPreview",
|
||||||
"textchange #status_message_fake_text": "handleTextchange",
|
"textchange #status_message_fake_text": "handleTextchange",
|
||||||
"click #locator" : "showLocation",
|
"click #locator" : "showLocation",
|
||||||
|
"click #poll_creator" : "showPollCreator",
|
||||||
|
"click #add_poll_answer" : "addPollAnswer",
|
||||||
|
"click .remove_poll_answer" : "removePollAnswer",
|
||||||
"click #hide_location" : "destroyLocation",
|
"click #hide_location" : "destroyLocation",
|
||||||
"keypress #location_address" : "avoidEnter"
|
"keypress #location_address" : "avoidEnter"
|
||||||
},
|
},
|
||||||
|
|
@ -37,6 +40,8 @@ app.views.Publisher = Backbone.View.extend({
|
||||||
this.el_submit = this.$('input[type=submit], button#submit');
|
this.el_submit = this.$('input[type=submit], button#submit');
|
||||||
this.el_preview = this.$('button.post_preview_button');
|
this.el_preview = this.$('button.post_preview_button');
|
||||||
this.el_photozone = this.$('#photodropzone');
|
this.el_photozone = this.$('#photodropzone');
|
||||||
|
this.el_poll_creator = this.$('#poll_creator_wrapper');
|
||||||
|
this.el_poll_answer = this.$('#poll_creator_wrapper .poll_answer');
|
||||||
|
|
||||||
// init mentions plugin
|
// init mentions plugin
|
||||||
Mentions.initialize(this.el_input);
|
Mentions.initialize(this.el_input);
|
||||||
|
|
@ -127,7 +132,6 @@ 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]"]
|
||||||
|
|
@ -136,10 +140,12 @@ app.views.Publisher = Backbone.View.extend({
|
||||||
"photos" : serializedForm["photos[]"],
|
"photos" : serializedForm["photos[]"],
|
||||||
"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"]
|
||||||
}, {
|
}, {
|
||||||
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');
|
||||||
}
|
}
|
||||||
|
|
@ -171,6 +177,23 @@ app.views.Publisher = Backbone.View.extend({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
showPollCreator: function(){
|
||||||
|
this.el_poll_creator.toggle();
|
||||||
|
},
|
||||||
|
|
||||||
|
addPollAnswer: function(){
|
||||||
|
var clone = this.el_poll_answer.clone();
|
||||||
|
var count_of_answers = this.el_poll_answer.size()+1;
|
||||||
|
clone.attr("name", "poll_answer_"+count_of_answers)
|
||||||
|
this.el_poll_answer.last().after(clone);
|
||||||
|
},
|
||||||
|
|
||||||
|
removePollAnswer: function(evt){
|
||||||
|
if($(".poll_answer_input").size() > 1) {
|
||||||
|
$(evt.target).parent().remove();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
},
|
||||||
// avoid submitting form when pressing Enter key
|
// avoid submitting form when pressing Enter key
|
||||||
avoidEnter: function(evt){
|
avoidEnter: function(evt){
|
||||||
if(evt.keyCode == 13)
|
if(evt.keyCode == 13)
|
||||||
|
|
@ -323,7 +346,7 @@ app.views.Publisher = Backbone.View.extend({
|
||||||
$(this.el).addClass("closed");
|
$(this.el).addClass("closed");
|
||||||
this.el_wrapper.removeClass("active");
|
this.el_wrapper.removeClass("active");
|
||||||
this.el_input.css('height', '');
|
this.el_input.css('height', '');
|
||||||
|
this.el_poll_creator.hide();
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,7 @@
|
||||||
resize: none;
|
resize: none;
|
||||||
height: 50px;
|
height: 50px;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
&.active textarea {
|
&.active textarea {
|
||||||
min-height: 70px;
|
min-height: 70px;
|
||||||
|
|
@ -78,6 +79,7 @@
|
||||||
line-height: 20px !important;
|
line-height: 20px !important;
|
||||||
width: 100% !important;
|
width: 100% !important;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
&.with_attachments .row-fluid#photodropzone_container {
|
&.with_attachments .row-fluid#photodropzone_container {
|
||||||
border-top: 1px dashed $border-grey;
|
border-top: 1px dashed $border-grey;
|
||||||
|
|
@ -162,6 +164,7 @@
|
||||||
margin-right: 5px;
|
margin-right: 5px;
|
||||||
#file-upload,
|
#file-upload,
|
||||||
#locator,
|
#locator,
|
||||||
|
#poll_creator,
|
||||||
#hide_location {
|
#hide_location {
|
||||||
text-decoration: none !important;
|
text-decoration: none !important;
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
|
|
@ -215,3 +218,4 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -309,8 +309,25 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#poll_creator {
|
||||||
|
@extend #locator;
|
||||||
|
right: 50px;
|
||||||
|
}
|
||||||
|
|
||||||
.btn {
|
.btn {
|
||||||
height: 19px;
|
height: 19px;
|
||||||
width: 19px;
|
width: 19px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#poll_creator_wrapper {
|
||||||
|
display:none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.remove_poll_answer {
|
||||||
|
display:inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.poll_answer_input {
|
||||||
|
display:inline-block !important;
|
||||||
|
}
|
||||||
|
|
@ -49,6 +49,11 @@ 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?
|
||||||
|
|
||||||
|
#save all answers for poll
|
||||||
|
|
||||||
|
|
||||||
@status_message.attach_photos_by_ids(params[:photos])
|
@status_message.attach_photos_by_ids(params[:photos])
|
||||||
|
|
||||||
if @status_message.save
|
if @status_message.save
|
||||||
|
|
|
||||||
7
app/models/poll.rb
Normal file
7
app/models/poll.rb
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
class Poll < ActiveRecord::Base
|
||||||
|
attr_accessible :question
|
||||||
|
|
||||||
|
belongs_to :status_message
|
||||||
|
belongs_to :author, :class_name => :person, :foreign_key => :author_id
|
||||||
|
#has_many :poll_answers
|
||||||
|
end
|
||||||
|
|
@ -24,6 +24,7 @@ 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
|
||||||
|
|
||||||
# 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
|
||||||
|
|
|
||||||
|
|
@ -28,12 +28,25 @@
|
||||||
%span#publisher-images
|
%span#publisher-images
|
||||||
%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')}
|
||||||
|
= image_tag 'icons/marker.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')}
|
||||||
= image_tag 'icons/camera.png', :alt => t('shared.publisher.upload_photos').titleize, :class => 'publisher_image'
|
= image_tag 'icons/camera.png', :alt => t('shared.publisher.upload_photos').titleize, :class => 'publisher_image'
|
||||||
= hidden_field :location, :coords
|
= hidden_field :location, :coords
|
||||||
#location_container
|
#location_container
|
||||||
|
#poll_creator_wrapper
|
||||||
|
= 'Poll creation'
|
||||||
|
%br
|
||||||
|
%br
|
||||||
|
%input{:id => 'poll_question', :placeholder => 'Question', :name => 'poll_question'}
|
||||||
|
%div{:class => 'poll_answer'}
|
||||||
|
%input{:class => 'poll_answer_input', :placeholder => 'Answer', :name => 'poll_answer_1'}
|
||||||
|
%a{:class => 'remove_poll_answer'}
|
||||||
|
= t('shared.publisher.poll.remove_poll_answer')
|
||||||
|
%div{:id => 'add_poll_answer', :class => 'button creation'}
|
||||||
|
= t('shared.publisher.poll.add_poll_answer')
|
||||||
|
|
||||||
- if publisher_public
|
- if publisher_public
|
||||||
= hidden_field_tag 'aspect_ids[]', "public"
|
= hidden_field_tag 'aspect_ids[]', "public"
|
||||||
|
|
|
||||||
|
|
@ -1037,6 +1037,9 @@ en:
|
||||||
hello: "Hey everyone, I'm #%{new_user_tag}. "
|
hello: "Hey everyone, I'm #%{new_user_tag}. "
|
||||||
i_like: "I'm interested in %{tags}. "
|
i_like: "I'm interested in %{tags}. "
|
||||||
invited_by: "Thanks for the invite, "
|
invited_by: "Thanks for the invite, "
|
||||||
|
poll:
|
||||||
|
remove_poll_answer: "Remove answer"
|
||||||
|
add_poll_answer: "Add answer"
|
||||||
add_contact:
|
add_contact:
|
||||||
enter_a_diaspora_username: "Enter a diaspora* username:"
|
enter_a_diaspora_username: "Enter a diaspora* username:"
|
||||||
your_diaspora_username_is: "Your diaspora* username is: %{diaspora_handle}"
|
your_diaspora_username_is: "Your diaspora* username is: %{diaspora_handle}"
|
||||||
|
|
|
||||||
33
db/migrate/20140308154022_create_polls.rb
Normal file
33
db/migrate/20140308154022_create_polls.rb
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
class CreatePolls < ActiveRecord::Migration
|
||||||
|
def up
|
||||||
|
create_table :polls do |t|
|
||||||
|
t.string :question, :null => false
|
||||||
|
t.belongs_to :status_message, :null => false
|
||||||
|
t.boolean :status
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
add_index :polls, :status_message_id
|
||||||
|
|
||||||
|
create_table :poll_answers do |t|
|
||||||
|
t.string :answer, :null => false
|
||||||
|
t.belongs_to :poll, :null => false
|
||||||
|
end
|
||||||
|
add_index :poll_answers, :poll_id
|
||||||
|
|
||||||
|
create_table :poll_participations do |t|
|
||||||
|
t.belongs_to :poll_answer, :null => false
|
||||||
|
t.belongs_to :author, :null => false
|
||||||
|
t.belongs_to :poll, :null => false
|
||||||
|
t.datetime :time
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
add_index :poll_participations, :poll_id
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
drop_table :polls
|
||||||
|
drop_table :poll_answers
|
||||||
|
drop_table :poll_participations
|
||||||
|
end
|
||||||
|
end
|
||||||
66
db/schema.rb
66
db/schema.rb
|
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended to check this file into your version control system.
|
# It's strongly recommended to check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(:version => 20140222162826) do
|
ActiveRecord::Schema.define(:version => 20140308154022) do
|
||||||
|
|
||||||
create_table "account_deletions", :force => true do |t|
|
create_table "account_deletions", :force => true do |t|
|
||||||
t.string "diaspora_handle"
|
t.string "diaspora_handle"
|
||||||
|
|
@ -283,6 +283,34 @@ ActiveRecord::Schema.define(:version => 20140222162826) do
|
||||||
t.datetime "updated_at", :null => false
|
t.datetime "updated_at", :null => false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
create_table "poll_answers", :force => true do |t|
|
||||||
|
t.string "answer", :null => false
|
||||||
|
t.integer "poll_id", :null => false
|
||||||
|
end
|
||||||
|
|
||||||
|
add_index "poll_answers", ["poll_id"], :name => "index_poll_answers_on_poll_id"
|
||||||
|
|
||||||
|
create_table "poll_participations", :force => true do |t|
|
||||||
|
t.integer "poll_answer_id", :null => false
|
||||||
|
t.integer "author_id", :null => false
|
||||||
|
t.integer "poll_id", :null => false
|
||||||
|
t.datetime "time"
|
||||||
|
t.datetime "created_at", :null => false
|
||||||
|
t.datetime "updated_at", :null => false
|
||||||
|
end
|
||||||
|
|
||||||
|
add_index "poll_participations", ["poll_id"], :name => "index_poll_participations_on_poll_id"
|
||||||
|
|
||||||
|
create_table "polls", :force => true do |t|
|
||||||
|
t.string "question", :null => false
|
||||||
|
t.integer "status_message_id", :null => false
|
||||||
|
t.boolean "status"
|
||||||
|
t.datetime "created_at", :null => false
|
||||||
|
t.datetime "updated_at", :null => false
|
||||||
|
end
|
||||||
|
|
||||||
|
add_index "polls", ["status_message_id"], :name => "index_polls_on_status_message_id"
|
||||||
|
|
||||||
create_table "post_reports", :force => true do |t|
|
create_table "post_reports", :force => true do |t|
|
||||||
t.integer "post_id", :null => false
|
t.integer "post_id", :null => false
|
||||||
t.string "user_id"
|
t.string "user_id"
|
||||||
|
|
@ -502,36 +530,36 @@ ActiveRecord::Schema.define(:version => 20140222162826) do
|
||||||
add_index "users", ["invitation_token"], :name => "index_users_on_invitation_token"
|
add_index "users", ["invitation_token"], :name => "index_users_on_invitation_token"
|
||||||
add_index "users", ["username"], :name => "index_users_on_username", :unique => true
|
add_index "users", ["username"], :name => "index_users_on_username", :unique => true
|
||||||
|
|
||||||
add_foreign_key "aspect_memberships", "aspects", :name => "aspect_memberships_aspect_id_fk", :dependent => :delete
|
add_foreign_key "aspect_memberships", "aspects", name: "aspect_memberships_aspect_id_fk", dependent: :delete
|
||||||
add_foreign_key "aspect_memberships", "contacts", :name => "aspect_memberships_contact_id_fk", :dependent => :delete
|
add_foreign_key "aspect_memberships", "contacts", name: "aspect_memberships_contact_id_fk", dependent: :delete
|
||||||
|
|
||||||
add_foreign_key "aspect_visibilities", "aspects", :name => "aspect_visibilities_aspect_id_fk", :dependent => :delete
|
add_foreign_key "aspect_visibilities", "aspects", name: "aspect_visibilities_aspect_id_fk", dependent: :delete
|
||||||
|
|
||||||
add_foreign_key "comments", "people", :name => "comments_author_id_fk", :column => "author_id", :dependent => :delete
|
add_foreign_key "comments", "people", name: "comments_author_id_fk", column: "author_id", dependent: :delete
|
||||||
|
|
||||||
add_foreign_key "contacts", "people", :name => "contacts_person_id_fk", :dependent => :delete
|
add_foreign_key "contacts", "people", name: "contacts_person_id_fk", dependent: :delete
|
||||||
|
|
||||||
add_foreign_key "conversation_visibilities", "conversations", :name => "conversation_visibilities_conversation_id_fk", :dependent => :delete
|
add_foreign_key "conversation_visibilities", "conversations", name: "conversation_visibilities_conversation_id_fk", dependent: :delete
|
||||||
add_foreign_key "conversation_visibilities", "people", :name => "conversation_visibilities_person_id_fk", :dependent => :delete
|
add_foreign_key "conversation_visibilities", "people", name: "conversation_visibilities_person_id_fk", dependent: :delete
|
||||||
|
|
||||||
add_foreign_key "conversations", "people", :name => "conversations_author_id_fk", :column => "author_id", :dependent => :delete
|
add_foreign_key "conversations", "people", name: "conversations_author_id_fk", column: "author_id", dependent: :delete
|
||||||
|
|
||||||
add_foreign_key "invitations", "users", :name => "invitations_recipient_id_fk", :column => "recipient_id", :dependent => :delete
|
add_foreign_key "invitations", "users", name: "invitations_recipient_id_fk", column: "recipient_id", dependent: :delete
|
||||||
add_foreign_key "invitations", "users", :name => "invitations_sender_id_fk", :column => "sender_id", :dependent => :delete
|
add_foreign_key "invitations", "users", name: "invitations_sender_id_fk", column: "sender_id", dependent: :delete
|
||||||
|
|
||||||
add_foreign_key "likes", "people", :name => "likes_author_id_fk", :column => "author_id", :dependent => :delete
|
add_foreign_key "likes", "people", name: "likes_author_id_fk", column: "author_id", dependent: :delete
|
||||||
|
|
||||||
add_foreign_key "messages", "conversations", :name => "messages_conversation_id_fk", :dependent => :delete
|
add_foreign_key "messages", "conversations", name: "messages_conversation_id_fk", dependent: :delete
|
||||||
add_foreign_key "messages", "people", :name => "messages_author_id_fk", :column => "author_id", :dependent => :delete
|
add_foreign_key "messages", "people", name: "messages_author_id_fk", column: "author_id", dependent: :delete
|
||||||
|
|
||||||
add_foreign_key "notification_actors", "notifications", :name => "notification_actors_notification_id_fk", :dependent => :delete
|
add_foreign_key "notification_actors", "notifications", name: "notification_actors_notification_id_fk", dependent: :delete
|
||||||
|
|
||||||
add_foreign_key "posts", "people", :name => "posts_author_id_fk", :column => "author_id", :dependent => :delete
|
add_foreign_key "posts", "people", name: "posts_author_id_fk", column: "author_id", dependent: :delete
|
||||||
|
|
||||||
add_foreign_key "profiles", "people", :name => "profiles_person_id_fk", :dependent => :delete
|
add_foreign_key "profiles", "people", name: "profiles_person_id_fk", dependent: :delete
|
||||||
|
|
||||||
add_foreign_key "services", "users", :name => "services_user_id_fk", :dependent => :delete
|
add_foreign_key "services", "users", name: "services_user_id_fk", dependent: :delete
|
||||||
|
|
||||||
add_foreign_key "share_visibilities", "contacts", :name => "post_visibilities_contact_id_fk", :dependent => :delete
|
add_foreign_key "share_visibilities", "contacts", name: "post_visibilities_contact_id_fk", dependent: :delete
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
5
spec/models/poll_spec.rb
Normal file
5
spec/models/poll_spec.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe Poll do
|
||||||
|
pending "add some examples to (or delete) #{__FILE__}"
|
||||||
|
end
|
||||||
Loading…
Reference in a new issue