diff --git a/app/assets/javascripts/sortable.js.coffee b/app/assets/javascripts/sortable.js.coffee
index 61124264e..ee98703f3 100644
--- a/app/assets/javascripts/sortable.js.coffee
+++ b/app/assets/javascripts/sortable.js.coffee
@@ -7,3 +7,11 @@ App.Sortable =
url: $(".sortable").data("js-url"),
data: { ordered_list: new_order },
type: "POST"
+
+ $(".sortable-priotirized-votation").sortable
+ update: (event, ui) ->
+ new_order = $(this).sortable("toArray", { attribute: "data-answer-id" })
+ $.ajax
+ url: $(this).data("js-url"),
+ data: { ordered_list: new_order },
+ type: "POST"
diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss
index 5a72a100b..f003c4632 100644
--- a/app/assets/stylesheets/participation.scss
+++ b/app/assets/stylesheets/participation.scss
@@ -1745,8 +1745,12 @@
background: #fafafa;
border-bottom: 1px solid #eee;
- .column:nth-child(odd) {
- border-right: 2px solid $text;
+ .margin-bottom {
+ margin-bottom: 0;
+ }
+
+ .orbit-bullets {
+ margin-bottom: 0;
}
.answer-divider {
@@ -1756,14 +1760,35 @@
padding-bottom: $line-height;
}
+ .answer-left-divider {
+ border-left: solid 1px $text;
+ padding-left: rem-calc(10);
+ }
+
+ .margin-top {
+ margin-top: rem-calc(10);
+ }
+
+ .margin-bottom {
+ margin-bottom: rem-calc(20);
+ }
+
.answer-description {
- height: 100%;
+ max-height: rem-calc(1000);
&.short {
- height: rem-calc(300);
+ max-height: rem-calc(70);
overflow: hidden;
+ max-width: rem-calc(700);
}
}
+
+ .question-divider {
+ border-bottom: rgba(219, 219, 219, 0.62) solid 1px;
+ margin-bottom: 1rem;
+ padding: rem-calc(24);
+ }
+
}
.orbit-bullets button {
@@ -1991,6 +2016,69 @@
}
}
+.icon-like,
+.icon-unlike {
+ background: #fff;
+ border: 2px solid $text-light;
+ border-radius: rem-calc(3);
+ color: $text-light;
+ display: inline-block;
+ font-size: rem-calc(30);
+ line-height: rem-calc(30);
+ padding: rem-calc(3) rem-calc(6);
+ position: relative;
+
+ &:hover,
+ &:active {
+ color: #fff;
+ cursor: pointer;
+ opacity: 1 !important;
+ }
+}
+
+.active-like {
+ color: #fff;
+ cursor: pointer;
+ opacity: 1 !important;
+ background: $like;
+ border: 2px solid $like;
+}
+
+.active-unlike {
+ color: #fff;
+ cursor: pointer;
+ opacity: 1 !important;
+ background: $unlike;
+ border: 2px solid $unlike;
+}
+
+.icon-like {
+
+ &:hover,
+ &:active,
+ .picked {
+ background: $like;
+ border: 2px solid $like;
+ }
+}
+
+.icon-unlike {
+
+ &:hover,
+ &:active {
+ background: $unlike;
+ border: 2px solid $unlike;
+ }
+}
+
+.vote-align {
+ float: right;
+}
+
+.vote-divider {
+ border-bottom: 1px solid $text-light;
+}
+
// 09. Polls results and stats
// ---------------------------
diff --git a/app/controllers/polls/answers_controller.rb b/app/controllers/polls/answers_controller.rb
new file mode 100644
index 000000000..49c5fcfc9
--- /dev/null
+++ b/app/controllers/polls/answers_controller.rb
@@ -0,0 +1,70 @@
+class Polls::AnswersController < ApplicationController
+
+ load_and_authorize_resource :poll
+ load_and_authorize_resource :question, class: "Poll::Question"
+ authorize_resource :answer, class: "Poll::Answer"
+
+ def create
+ @question = Poll::Question.find_by(id: params[:id])
+ if @question.votation_type.open? && !check_question_answer_exist
+ @question.question_answers.create(
+ title: params[:answer],
+ given_order: @question.question_answers.count + 1,
+ hidden: false
+ )
+ flash.now[:notice] = t("dashboard.polls.index.succesfull")
+ else
+ flash.now[:alert] = "Unfortunately failed to sent"
+ end
+ load_for_answers
+ if @question.enum_type&.include?("answer_couples")
+ last_pair ||= generate_and_store_new_pair(@question)
+ @last_pair_question_answers = {@question.id => last_pair}
+ end
+ render "polls/questions/answer", format: :js
+ end
+
+ def delete
+ @question = Poll::Question.find_by(id: params[:id])
+ !@question.answers.find_by(author: current_user, answer: params[:answer]).destroy
+ @question.question_answers.each do |question_answer|
+ question_answer.set_most_voted
+ end
+ question_answers
+ load_for_answers
+ if @question.enum_type&.include?("answer_couples")
+ last_pair ||= generate_and_store_new_pair(@question)
+ @last_pair_question_answers = {@question.id => last_pair}
+ end
+ render "polls/questions/answer", format: :js
+ end
+
+ private
+
+ def check_question_answer_exist
+ exist = false
+ @question.question_answers.each do |question_answer|
+ break if exist
+ exist = true if question_answer.title == params[:answer]
+ end
+ exist
+ end
+
+ def load_for_answers
+ @page = params[:page].present? ? params[:page] : 1
+ question_answers
+ @answers_by_question_id = {@question.id => @question.answers
+ .by_author(current_user)
+ .order(:order)
+ .pluck(:answer)}
+ end
+
+ def question_answers
+ if @question.is_positive_negative?
+ @answers = @question.question_answers.visibles.page(params[:page])
+ else
+ @answers = @question.question_answers.visibles
+ end
+ end
+
+end
diff --git a/app/controllers/polls/questions_controller.rb b/app/controllers/polls/questions_controller.rb
index eb054dd1e..b929e0fc5 100644
--- a/app/controllers/polls/questions_controller.rb
+++ b/app/controllers/polls/questions_controller.rb
@@ -3,18 +3,79 @@ class Polls::QuestionsController < ApplicationController
load_and_authorize_resource :poll
load_and_authorize_resource :question, class: "Poll::Question"
- has_orders %w{most_voted newest oldest}, only: :show
+ has_orders %w[most_voted newest oldest], only: :show
def answer
- answer = @question.answers.find_or_initialize_by(author: current_user)
- token = params[:token]
-
- answer.answer = params[:answer]
- answer.touch if answer.persisted?
- answer.save!
- answer.record_voter_participation(token)
-
- @answers_by_question_id = { @question.id => params[:answer] }
+ answer = store_answer
+ vote_stored(answer, params[:answer], params[:token]) if answer.present?
+ load_for_answers
+ if @question.enum_type&.include?("answer_couples")
+ last_pair ||= generate_and_store_new_pair(@question)
+ @last_pair_question_answers = {@question.id => last_pair}
+ end
end
+ def load_answers
+ load_for_answers
+ render action: "answer.js.erb"
+ end
+
+ def prioritized_answers
+ unless params[:ordered_list].empty?
+ params[:ordered_list].each_with_index do |answer, i|
+ answer_obj = @question.votation_type.answer(current_user,
+ answer,
+ order: i + 1)
+ vote_stored(answer_obj, answer, params[:tooken]) if answer_obj.present?
+ end
+ @question.votation_type.update_priorized_values(current_user.id)
+ end
+ load_for_answers
+ render action: "answer.js.erb"
+ end
+
+ private
+
+ def load_for_answers
+ @page = params[:page].present? ? params[:page] : 1
+ question_answers
+ @answers_by_question_id = {@question.id => @question.answers
+ .by_author(current_user)
+ .order(:order)
+ .pluck(:answer)}
+ end
+
+ def vote_stored(answer, new_answer, token)
+ answer.answer = new_answer
+ answer.touch if answer.persisted?
+ answer.save!
+ answer.record_voter_participation(token)
+ @question.question_answers.visibles.where(question_id: @question).each do |question_answer|
+ question_answer.set_most_voted
+ end
+ end
+
+ def store_answer
+ if @question.votation_type.nil?
+ answer = @question.answers.find_or_initialize_by(author: current_user)
+ else
+ answer = @question.votation_type.answer(current_user,
+ params[:answer],
+ positive: params[:positive])
+ end
+ answer
+ end
+
+ def generate_and_store_new_pair(question)
+ Poll::PairAnswer.generate_pair(question, current_user)
+ end
+
+ def question_answers
+ if @question.is_positive_negative?
+ @answers = @question.question_answers.visibles.page(@page)
+ else
+ @answers = @question.question_answers.visibles
+ end
+ end
+
end
diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb
index f322379ce..b95303384 100644
--- a/app/controllers/polls_controller.rb
+++ b/app/controllers/polls_controller.rb
@@ -20,13 +20,27 @@ class PollsController < ApplicationController
def show
@questions = @poll.questions.for_render.sort_for_list
@token = poll_voter_token(@poll, current_user)
- @poll_questions_answers = Poll::Question::Answer.where(question: @poll.questions)
+ @poll_questions_answers = Poll::Question::Answer.visibles
+ .where(question: @poll.questions)
.where.not(description: "").order(:given_order)
@answers_by_question_id = {}
poll_answers = ::Poll::Answer.by_question(@poll.question_ids).by_author(current_user.try(:id))
- poll_answers.each do |answer|
- @answers_by_question_id[answer.question_id] = answer.answer
+
+ @last_pair_question_answers = {}
+ @questions.each do |question|
+ @answers_by_question_id[question.id] = question.answers.by_author(current_user).pluck(:answer)
+
+ if question.enum_type&.include?("answer_couples")
+ last_pair = question.pair_answers.by_author(current_user).first
+ last_pair ||= generate_and_store_new_pair(question)
+ @last_pair_question_answers[question.id] = last_pair
+ end
+
+ if question.enum_type&.include?("answer_set_closed") ||
+ question.enum_type&.include?("answer_set_open")
+ votation_answer_sets(question)
+ end
end
@commentable = @poll
@@ -42,6 +56,18 @@ class PollsController < ApplicationController
private
+ def votation_answer_sets(question)
+ if question.votation_type.votation_set_answers.by_author(current_user).empty?
+ question.question_answers&.sample(question.max_groups_answers).each do |question_answer|
+ answer = VotationSetAnswer.new(answer: question_answer.title,
+ votation_type: question.votation_type,
+ author: current_user)
+ question.votation_type.votation_set_answers << answer
+ end
+ !question.save
+ end
+ end
+
def load_poll
@poll = Poll.where(slug: params[:id]).first || Poll.where(id: params[:id]).first
end
@@ -50,4 +76,8 @@ class PollsController < ApplicationController
@active_poll = ActivePoll.first
end
+ def generate_and_store_new_pair(question)
+ Poll::PairAnswer.generate_pair(question, current_user)
+ end
+
end
diff --git a/app/helpers/polls_helper.rb b/app/helpers/polls_helper.rb
index 2faf9b3f8..963367a4f 100644
--- a/app/helpers/polls_helper.rb
+++ b/app/helpers/polls_helper.rb
@@ -78,4 +78,8 @@ module PollsHelper
def show_polls_description?
@active_poll.present? && @current_filter == "current"
end
+
+ def stored_positive_negative_value(question, answer)
+ question.answers.find_by(author_id: current_user.id, answer: answer.title).positive
+ end
end
diff --git a/app/models/abilities/common.rb b/app/models/abilities/common.rb
index b106ebef5..d26a38680 100644
--- a/app/models/abilities/common.rb
+++ b/app/models/abilities/common.rb
@@ -104,12 +104,18 @@ module Abilities
can :create, DirectMessage
can :show, DirectMessage, sender_id: user.id
- can :answer, Poll do |poll|
+
+ can [:load_answers], Poll::Question
+ can [:answer], Poll do |poll|
poll.answerable_by?(user)
end
- can :answer, Poll::Question do |question|
+ can [:answer, :prioritized_answers], Poll::Question do |question|
question.answerable_by?(user)
end
+
+ can [:create, :delete], Poll::Answer do |answer|
+ answer.question.answerable_by?(user)
+ end
end
can [:create, :show], ProposalNotification, proposal: { author_id: user.id }
diff --git a/app/views/polls/questions/_answers.html.erb b/app/views/polls/questions/_answers.html.erb
index 206896b04..bfba35b91 100644
--- a/app/views/polls/questions/_answers.html.erb
+++ b/app/views/polls/questions/_answers.html.erb
@@ -1,33 +1,22 @@
-
- <% if can?(:answer, question) && !question.poll.voted_in_booth?(current_user) %>
- <% question.question_answers.each do |answer| %>
- <% if @answers_by_question_id[question.id] == answer.title &&
- (!voted_before_sign_in(question) ||
- question.poll.voted_in_booth?(current_user)) %>
- ">
- <%= answer.title %>
-
- <% else %>
- <%= link_to answer.title,
- answer_question_path(question, answer: answer.title, token: token),
- method: :post,
- remote: true,
- title: t("poll_questions.show.vote_answer", answer: answer.title),
- class: "button secondary hollow js-question-answer" %>
- <% end %>
- <% end %>
- <% elsif !user_signed_in? %>
- <% question.question_answers.order(id: :desc).each do |answer| %>
- <%= link_to answer.title, new_user_session_path, class: "button secondary hollow" %>
- <% end %>
- <% elsif !current_user.level_two_or_three_verified? %>
- <% question.question_answers.order(id: :desc).each do |answer| %>
- <%= link_to answer.title, verification_path, class: "button secondary hollow" %>
- <% end %>
+<% if question.votation_type.nil? %>
+ <%= render "polls/questions/answers_unique", question: question, answers: answers, token: token %>
+<% else %>
+ <% case question.votation_type.enum_type %>
+ <% when "unique" %>
+ <%= render "polls/questions/answers_unique", question: question, answers: answers, token: token %>
+ <% when "multiple", "positive_open" %>
+ <%= render "polls/questions/answers_multiple", question: question, answers: answers, token: token %>
+ <% when "positive_negative_open" %>
+ <%= render "polls/questions/answers_positive_negative", question: question, answers: answers, token: token, page: page %>
+ <% when "answer_couples_closed" %>
+ <%= render "polls/questions/answers_couples", answers_open: false, question: question, token: token %>
+ <% when "answer_couples_open" %>
+ <%= render "polls/questions/answers_couples", answers_open: true, question: question, token: token %>
+ <% when "answer_set_closed", "answer_set_open" %>
+ <%= render "polls/questions/answers_set", question: question, token: token, answers: question.votation_type.votation_set_answers.by_author(current_user) %>
+ <% when "prioritized" %>
+ <%= render "polls/questions/answers_prioritized", answers_open: false, question: question, answers: answers, token: token %>
<% else %>
- <% question.question_answers.order(id: :desc).each do |answer| %>
- <%= answer.title %>
- <% end %>
+ <%= render "polls/questions/answers_unique", question: question, answers: answers, token: token %>
<% end %>
-
+<% end %>
diff --git a/app/views/polls/questions/_answers_couples.html.erb b/app/views/polls/questions/_answers_couples.html.erb
new file mode 100644
index 000000000..cab665ed8
--- /dev/null
+++ b/app/views/polls/questions/_answers_couples.html.erb
@@ -0,0 +1,39 @@
+
+ <% if can?(:answer, question) && question.user_can_vote(current_user) %>
+
+ <% @last_pair_question_answers.dig(question.id)&.answers&.each do |answer| %>
+
+ <%= link_to answer.title,
+ answer_question_path(question, answer: answer.title, token: token),
+ method: :post,
+ remote: true,
+ title: t("poll_questions.show.vote_answer", answer: answer.title),
+ class: "button secondary hollow js-question-answer" %>
+
+ <% end %>
+
+
+ <%= link_to "I can't decide",
+ answer_question_path(question, answer: "I can't decided", token: token),
+ method: :post,
+ remote: true,
+ title: "I can't decide",
+ class: "button secondary hollow js-question-answer" %>
+
+
+ <% if answers_open %>
+ <%= render "/polls/questions/new_answer", question: question, token: token %>
+ <% end %>
+
+ <% elsif !user_signed_in? %>
+ <% question.question_answers.visibles.order(id: :desc).each do |answer| %>
+ <%= link_to answer.title, new_user_session_path, class: "button secondary hollow" %>
+ <% end %>
+ <% elsif !current_user.level_two_or_three_verified? %>
+ <% question.question_answers.visibles.order(id: :desc).each do |answer| %>
+ <%= link_to answer.title, verification_path, class: "button secondary hollow" %>
+ <% end %>
+ <% else %>
+ <%= t('polls.index.max_votes_reached') %>
+ <% end %>
+
diff --git a/app/views/polls/questions/_answers_multiple.html.erb b/app/views/polls/questions/_answers_multiple.html.erb
new file mode 100644
index 000000000..3770b0e3c
--- /dev/null
+++ b/app/views/polls/questions/_answers_multiple.html.erb
@@ -0,0 +1,36 @@
+
+ <% if can?(:answer, question) && !question.poll.voted_in_booth?(current_user) %>
+ <% answers&.each do |answer| %>
+ <% if @answers_by_question_id[question.id].include?(answer.title) %>
+ <%= link_to answer.title,
+ answer_question_path(question, answer: answer.title, token: token),
+ method: :delete,
+ remote: true,
+ title: t("poll_questions.show.voted", answer: answer.title),
+ class: "button answered expand" %>
+ <% else %>
+ <%= link_to answer.title,
+ answer_question_path(question, answer: answer.title, token: token),
+ method: :post,
+ remote: true,
+ title: t("poll_questions.show.vote_answer", answer: answer.title),
+ class: "button secondary hollow js-question-answer" %>
+ <% end %>
+ <% end %>
+ <% if question.enum_type == "positive_open" %>
+ <%= render "/polls/questions/new_answer", question: question, token: token %>
+ <% end %>
+ <% elsif !user_signed_in? %>
+ <% answers.order(id: :desc).each do |answer| %>
+ <%= link_to answer.title, new_user_session_path, class: "button secondary hollow" %>
+ <% end %>
+ <% elsif !current_user.level_two_or_three_verified? %>
+ <% answers.order(id: :desc).each do |answer| %>
+ <%= link_to answer.title, verification_path, class: "button secondary hollow" %>
+ <% end %>
+ <% else %>
+ <% answers.order(id: :desc).each do |answer| %>
+ <%= answer.title %>
+ <% end %>
+ <% end %>
+
diff --git a/app/views/polls/questions/_answers_positive_negative.html.erb b/app/views/polls/questions/_answers_positive_negative.html.erb
new file mode 100644
index 000000000..22959931c
--- /dev/null
+++ b/app/views/polls/questions/_answers_positive_negative.html.erb
@@ -0,0 +1,55 @@
+
+ <% if can?(:answer, question) && !question.poll.voted_in_booth?(current_user) %>
+
+ <% answers&.each do |answer| %>
+
+
+ <%= answer.title %>
+
+
+
+ <% if @answers_by_question_id[question.id].include?(answer.title) &&
+ stored_positive_negative_value(question, answer) %>
+ <%= render "polls/questions/like_dislike", question: question,
+ answer: answer, method: "delete", positive: true,
+ token: token, active: true, page: page %>
+ <% else %>
+ <%= render "polls/questions/like_dislike", question: question,
+ answer: answer, method: "post", positive: true,
+ token: token, active: false, page: page %>
+ <% end %>
+
+
+ <% if @answers_by_question_id[question.id].include?(answer.title) &&
+ !stored_positive_negative_value(question, answer) %>
+ <%= render "polls/questions/like_dislike", question: question,
+ answer: answer, method: "delete", positive: false,
+ token: token, active: true, page: page %>
+ <% else %>
+ <%= render "polls/questions/like_dislike", question: question,
+ answer: answer, method: "post", positive: false,
+ token: token, active: false, page: page %>
+ <% end %>
+
+
+
+ <% end %>
+
+ <%= paginate answers, params: {controller: "polls/questions", action: :load_answers, id: question}, remote: true %>
+
+ <%= render "/polls/questions/new_answer", question: question, token: token %>
+
+ <% elsif !user_signed_in? %>
+ <% answers.order(id: :desc).each do |answer| %>
+ <%= link_to answer.title, new_user_session_path, class: "button secondary hollow" %>
+ <% end %>
+ <% elsif !current_user.level_two_or_three_verified? %>
+ <% answers.visibles.order(id: :desc).each do |answer| %>
+ <%= link_to answer.title, verification_path, class: "button secondary hollow" %>
+ <% end %>
+ <% else %>
+ <% answers.order(id: :desc).each do |answer| %>
+
<%= answer.title %>
+ <% end %>
+ <% end %>
+
diff --git a/app/views/polls/questions/_answers_prioritized.html.erb b/app/views/polls/questions/_answers_prioritized.html.erb
new file mode 100644
index 000000000..075008550
--- /dev/null
+++ b/app/views/polls/questions/_answers_prioritized.html.erb
@@ -0,0 +1,44 @@
+
+ <% if can?(:answer, question) && !question.poll.voted_in_booth?(current_user) %>
+
+ <% @answers_by_question_id[question.id].each do |answer| %>
+
+ ">
+ <%= answer %>
+
+
+ <% end %>
+
+
+ <% answers&.each do |answer| %>
+ <% if @answers_by_question_id[question.id].include?(answer.title) %>
+ <%= link_to answer.title,
+ answer_question_path(question, answer: answer.title, token: token),
+ method: :delete,
+ remote: true,
+ title: t("poll_questions.show.voted", answer: answer.title),
+ class: "button answered expand" %>
+ <% else %>
+ <%= link_to answer.title,
+ answer_question_path(question, answer: answer.title, token: token),
+ method: :post,
+ remote: true,
+ title: t("poll_questions.show.vote_answer", answer: answer.title),
+ class: "button secondary hollow js-question-answer" %>
+ <% end %>
+ <% end %>
+ <% elsif !user_signed_in? %>
+ <% answers.order(id: :desc).each do |answer| %>
+ <%= link_to answer.title, new_user_session_path, class: "button secondary hollow" %>
+ <% end %>
+ <% elsif !current_user.level_two_or_three_verified? %>
+ <% answers.order(id: :desc).each do |answer| %>
+ <%= link_to answer.title, verification_path, class: "button secondary hollow" %>
+ <% end %>
+ <% else %>
+ <% answers.order(id: :desc).each do |answer| %>
+
<%= answer.title %>
+ <% end %>
+ <% end %>
+
diff --git a/app/views/polls/questions/_answers_set.html.erb b/app/views/polls/questions/_answers_set.html.erb
new file mode 100644
index 000000000..f8870c0d4
--- /dev/null
+++ b/app/views/polls/questions/_answers_set.html.erb
@@ -0,0 +1,37 @@
+
+ <% if can?(:answer, question) %>
+ <% answers.each do |answer| %>
+ <% if @answers_by_question_id[question.id].include?(answer.answer) %>
+ <%= link_to answer.answer,
+ answer_question_path(question, answer: answer.answer, token: token),
+ method: :delete,
+ remote: true,
+ title: t("poll_questions.show.voted", answer: answer.answer),
+ class: "button answered" %>
+ <% else %>
+ <%= link_to answer.answer,
+ answer_question_path(question, answer: answer.answer, token: token),
+ method: :post,
+ remote: true,
+ title: t("poll_questions.show.vote_answer", answer: answer.answer),
+ class: "button secondary hollow js-question-answer" %>
+ <% end %>
+ <% end %>
+ <% if question.enum_type == "answer_set_open" %>
+ <%= render "/polls/questions/new_answer", question: question, token: token %>
+ <%= flash[:notice] %>
+ <% end %>
+ <% elsif !user_signed_in? %>
+ <% answers.order(id: :desc).each do |answer| %>
+ <%= link_to answer.answer, new_user_session_path, class: "button secondary hollow" %>
+ <% end %>
+ <% elsif !current_user.level_two_or_three_verified? %>
+ <% answers.order(id: :desc).each do |answer| %>
+ <%= link_to answer.answer, verification_path, class: "button secondary hollow" %>
+ <% end %>
+ <% else %>
+ <% answers.order(id: :desc).each do |answer| %>
+ <%= answer.answer %>
+ <% end %>
+ <% end %>
+
diff --git a/app/views/polls/questions/_answers_unique.html.erb b/app/views/polls/questions/_answers_unique.html.erb
new file mode 100644
index 000000000..8029624ee
--- /dev/null
+++ b/app/views/polls/questions/_answers_unique.html.erb
@@ -0,0 +1,33 @@
+
+ <% if can?(:answer, question) && !question.poll.voted_in_booth?(current_user) %>
+ <% answers&.each do |answer| %>
+ <% if @answers_by_question_id[question.id].include?(answer.title) &&
+ (!voted_before_sign_in(question) ||
+ question.poll.voted_in_booth?(current_user)) %>
+ ">
+ <%= answer.title %>
+
+ <% else %>
+ <%= link_to answer.title,
+ answer_question_path(question, answer: answer.title, token: token),
+ method: :post,
+ remote: true,
+ title: t("poll_questions.show.vote_answer", answer: answer.title),
+ class: "button secondary hollow js-question-answer" %>
+ <% end %>
+ <% end %>
+ <% elsif !user_signed_in? %>
+ <% answers.order(id: :desc).each do |answer| %>
+ <%= link_to answer.title, new_user_session_path, class: "button secondary hollow" %>
+ <% end %>
+ <% elsif !current_user.level_two_or_three_verified? %>
+ <% answers.order(id: :desc).each do |answer| %>
+ <%= link_to answer.title, verification_path, class: "button secondary hollow" %>
+ <% end %>
+ <% else %>
+ <% answers.order(id: :desc).each do |answer| %>
+ <%= answer.title %>
+ <% end %>
+ <% end %>
+
diff --git a/app/views/polls/questions/_like_dislike.html.erb b/app/views/polls/questions/_like_dislike.html.erb
new file mode 100644
index 000000000..e34476e9a
--- /dev/null
+++ b/app/views/polls/questions/_like_dislike.html.erb
@@ -0,0 +1,19 @@
+<%= link_to answer_question_path(question, answer: answer.title, positive: positive, token: token, page: page),
+ method: method.to_sym,
+ remote: true,
+ title: t("poll_questions.show.vote_answer", answer: answer.title),
+ class: "expand js-question-answer" do %>
+ <% if positive %>
+ <% if active %>
+
+ <% else %>
+
+ <% end %>
+ <% else %>
+ <% if active %>
+
+ <% else %>
+
+ <% end %>
+ <% end %>
+<% end %>
diff --git a/app/views/polls/questions/_new_answer.html.erb b/app/views/polls/questions/_new_answer.html.erb
new file mode 100644
index 000000000..2f056bafa
--- /dev/null
+++ b/app/views/polls/questions/_new_answer.html.erb
@@ -0,0 +1,5 @@
+<%= form_tag(create_answer_question_path(question, token: token), method: :post, remote: true) do %>
+ You can add your own answer
+
+ ">
+<% end %>
diff --git a/app/views/polls/questions/_question.html.erb b/app/views/polls/questions/_question.html.erb
index 016c0fa95..bb50da3bc 100644
--- a/app/views/polls/questions/_question.html.erb
+++ b/app/views/polls/questions/_question.html.erb
@@ -3,7 +3,35 @@
<%= question.title %>
+ <% unless question.votation_type.nil? %>
+
+ <%= t("poll_questions.description.#{question.enum_type}",
+ maximum: question.votation_type.max_votes,
+ system: question.votation_type.prioritization_type) %>
+
+ <% end %>
+
- <%= render "polls/questions/answers", question: question, token: token %>
+ <% answers = question.is_positive_negative? ? question.question_answers.visibles.page(1) : question.question_answers.visibles %>
+ <%= render "polls/questions/answers", question: question, token: token, answers: answers, page: 1 %>
+
+ <% if question.answers_with_read_more? %>
+
+
<%= t("poll_questions.read_more_about") %>
+
+ <% first = true %>
+ <% question.question_answers&.visibles&.each do |answer| %>
+ <% if answer.description.present? || answer.images.any? ||
+ answer.documents.present? || answer.videos.present? %>
+ <% unless first %>
+ ,
+ <% end %>
+ <% first = false if first %>
+ <%= link_to answer.title, "#answer_description_#{answer.id}" %>
+ <% end %>
+ <% end %>
+
+
+ <% end %>
diff --git a/app/views/polls/questions/answer.js.erb b/app/views/polls/questions/answer.js.erb
index 79978e2c1..c35c55bfc 100644
--- a/app/views/polls/questions/answer.js.erb
+++ b/app/views/polls/questions/answer.js.erb
@@ -1,2 +1,3 @@
<% token = poll_voter_token(@question.poll, current_user) %>
-$("#<%= dom_id(@question) %>_answers").html("<%= j render("polls/questions/answers", question: @question, token: token) %>");
+$("#<%= dom_id(@question) %>_answers").html("<%= j render("polls/questions/answers", question: @question, answers: @answers, token: token, page: @page) %>");
+App.Sortable.initialize();
diff --git a/app/views/polls/results.html.erb b/app/views/polls/results.html.erb
index 7627fe018..c64362b95 100644
--- a/app/views/polls/results.html.erb
+++ b/app/views/polls/results.html.erb
@@ -1,4 +1,5 @@
-<% provide :title do %><%= @poll.name %><% end %>
+<% provide :title do %><%= @poll.name %>
+<% end %>
<%= render "poll_header" %>
@@ -10,37 +11,32 @@
<%= t("polls.show.results.title") %>
<%- @poll.questions.each do |question| %>
- <% most_voted_answer_id = question.most_voted_answer_id %>
<%= question.title %>
-
-
- <%- question.question_answers.each do |answer| %>
- >
- <% if answer.id == most_voted_answer_id %>
- <%= t("polls.show.results.most_voted_answer") %>
- <% end %>
- <%= answer.title %>
-
- <% end %>
-
-
-
- <%- question.question_answers.each do |answer| %>
- >
- <%= answer.total_votes %>
+ <%- question.question_answers.visibles.each do |answer| %>
+ >
+
+ <% if answer.most_voted %>
+ <%= t("polls.show.results.most_voted_answer") %>
+ <% end %>
+ <%= answer.title %>
+
+ >
+ <%= answer.total_votes %>
+ <% unless question.enum_type == "positive_negative_open" || question.enum_type == "prioritized" %>
(<%= answer.total_votes_percentage.round(2) %>%)
-
- <% end %>
+ <% end %>
+
+ <% end %>
<% end %>
diff --git a/app/views/polls/show.html.erb b/app/views/polls/show.html.erb
index 5fc0d6722..045218822 100644
--- a/app/views/polls/show.html.erb
+++ b/app/views/polls/show.html.erb
@@ -1,4 +1,4 @@
-<%= provide :title, t("social_share.polls_show.title_#{@poll.id}", default: @poll.title) %>
+<%= provide :title, t("social_share.polls_show.title_#{@poll.id}", default: @poll.title) %>
<%= provide :meta_description, t("social_share.polls_show.description_#{@poll.id}", default: @poll.title) %>
<%= provide :social_media_meta_tags do %>
<%= render "shared/social_media_meta_tags",
@@ -55,71 +55,80 @@
+ <% @questions.each do |question| %>
+ <% if question.answers_with_read_more? %>
+
+
<%= question.title %>
+ <% question.question_answers.visibles.each do |answer| %>
+ <% if answer.description.present? || answer.images.any? || answer.documents.present? || answer.videos.present? %>
+
+
<%= answer.title %>
+
+
+ <% if answer.description.present? %>
+ <%= answer.description %>
+ <% end %>
- <% @poll_questions_answers.each do |answer| %>
-
" id="answer_<%= answer.id %>">
+ <% if answer.images.any? %>
+
+ <%= render "gallery", answer: answer %>
+
+ <% end %>
- <% if answer.description.present? %>
-
<%= answer.title %>
- <% end %>
+ <% if answer.documents.present? %>
+
+
+
+ <%= t("polls.show.documents") %>
+
+ <% answer.documents.each do |document| %>
+ <%= link_to document.title,
+ document.attachment.url,
+ target: "_blank",
+ rel: "nofollow" %>
+
+ <% end %>
+
+ <% end %>
- <% if answer.images.any? %>
- <%= render "gallery", answer: answer %>
- <% end %>
+ <% if answer.videos.present? %>
+
+
+
+ <%= t("polls.show.videos") %>
+
- <% if answer.description.present? %>
-
-
- <%= safe_html_with_links simple_format(answer.description) %>
-
-
-
- <% end %>
-
- <% if answer.documents.present? %>
-
-
-
- <%= t("polls.show.documents") %>
-
-
- <% answer.documents.each do |document| %>
- <%= link_to document.title,
- document.attachment.url,
- target: "_blank",
- rel: "nofollow" %>
+ <% answer.videos.each do |video| %>
+ <%= link_to video.title,
+ video.url,
+ target: "_blank",
+ rel: "nofollow" %>
+
+ <% end %>
+
+ <% end %>
+
+
+
+
<% end %>
-
- <% end %>
-
- <% if answer.videos.present? %>
-
-
-
- <%= t("polls.show.videos") %>
-
-
- <% answer.videos.each do |video| %>
- <%= link_to video.title,
- video.url,
- target: "_blank",
- rel: "nofollow" %>
- <% end %>
-
- <% end %>
-
+ <% end %>
+
+ <% end %>
<% end %>
diff --git a/config/routes/poll.rb b/config/routes/poll.rb
index 96c43f856..8836fa762 100644
--- a/config/routes/poll.rb
+++ b/config/routes/poll.rb
@@ -5,6 +5,12 @@ resources :polls, only: [:show, :index] do
end
resources :questions, controller: "polls/questions", shallow: true do
- post :answer, on: :member
+ member do
+ post :answer
+ post :prioritized_answers
+ delete :answer, to: "polls/answers#delete"
+ post :create_answer, to: "polls/answers#create"
+ get :load_answers
+ end
end
end
diff --git a/spec/models/abilities/common_spec.rb b/spec/models/abilities/common_spec.rb
index f9fd8fbef..d30c7ddfc 100644
--- a/spec/models/abilities/common_spec.rb
+++ b/spec/models/abilities/common_spec.rb
@@ -213,6 +213,18 @@ describe Abilities::Common do
it { should_not be_able_to(:answer, expired_poll_question_from_all_geozones) }
it { should_not be_able_to(:answer, expired_poll_question_from_other_geozone) }
+ it { should be_able_to(:prioritized_answers, poll_question_from_own_geozone) }
+ it { should be_able_to(:prioritized_answers, poll_question_from_all_geozones) }
+ it { should_not be_able_to(:prioritized_answers, poll_question_from_other_geozone) }
+
+ it { should_not be_able_to(:prioritized_answers, expired_poll_question_from_own_geozone) }
+ it { should_not be_able_to(:prioritized_answers, expired_poll_question_from_all_geozones) }
+ it { should_not be_able_to(:prioritized_answers, expired_poll_question_from_other_geozone) }
+
+ context "Poll::Question" do
+ it { should be_able_to(:load_answers, Poll::Question) }
+ end
+
context "without geozone" do
before { user.geozone = nil }