diff --git a/app/assets/javascripts/answers.js b/app/assets/javascripts/answers.js deleted file mode 100644 index 74cb29305..000000000 --- a/app/assets/javascripts/answers.js +++ /dev/null @@ -1,30 +0,0 @@ -(function() { - "use strict"; - App.Answers = { - initializeAnswers: function(answers) { - $(answers).on("cocoon:after-insert", function(e, new_answer) { - var given_order; - given_order = App.Answers.maxGivenOrder(answers) + 1; - $(new_answer).find("[name$='[given_order]']").val(given_order); - }); - }, - maxGivenOrder: function(answers) { - var max_order; - max_order = 0; - $(answers).find("[name$='[given_order]']").each(function(index, answer) { - var value; - value = parseFloat($(answer).val()); - max_order = value > max_order ? value : max_order; - }); - return max_order; - }, - nestedAnswers: function() { - $(".js-answers").each(function(index, answers) { - App.Answers.initializeAnswers(answers); - }); - }, - initialize: function() { - App.Answers.nestedAnswers(); - } - }; -}).call(this); diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 9e6031dd4..5003ec2f0 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -89,7 +89,7 @@ //= require markdown_editor //= require html_editor //= require cocoon -//= require answers +//= require options //= require questions //= require legislation_admin //= require legislation @@ -129,7 +129,7 @@ var initialize_modules = function() { "use strict"; - App.Answers.initialize(); + App.Options.initialize(); App.Questions.initialize(); App.Comments.initialize(); App.ParticipationNotAllowed.initialize(); diff --git a/app/assets/javascripts/options.js b/app/assets/javascripts/options.js new file mode 100644 index 000000000..f67e98e63 --- /dev/null +++ b/app/assets/javascripts/options.js @@ -0,0 +1,30 @@ +(function() { + "use strict"; + App.Options = { + initializeOptions: function(options) { + $(options).on("cocoon:after-insert", function(e, new_option) { + var given_order; + given_order = App.Options.maxGivenOrder(options) + 1; + $(new_option).find("[name$='[given_order]']").val(given_order); + }); + }, + maxGivenOrder: function(options) { + var max_order; + max_order = 0; + $(options).find("[name$='[given_order]']").each(function(index, option) { + var value; + value = parseFloat($(option).val()); + max_order = value > max_order ? value : max_order; + }); + return max_order; + }, + nestedOptions: function() { + $(".js-options").each(function(index, options) { + App.Options.initializeOptions(options); + }); + }, + initialize: function() { + App.Options.nestedOptions(); + } + }; +}).call(this); diff --git a/app/assets/javascripts/polls.js b/app/assets/javascripts/polls.js index fa0495e27..742042ac3 100644 --- a/app/assets/javascripts/polls.js +++ b/app/assets/javascripts/polls.js @@ -3,20 +3,20 @@ App.Polls = { initialize: function() { $(".zoom-link").on("click", function(event) { - var answer; - answer = $(event.target).closest("div.answer"); + var option; + option = $(event.target).closest("div.option"); - if ($(answer).hasClass("medium-6")) { - $(answer).removeClass("medium-6"); - $(answer).addClass("answer-divider"); - if (!$(answer).hasClass("first")) { - $(answer).insertBefore($(answer).prev("div.answer")); + if ($(option).hasClass("medium-6")) { + $(option).removeClass("medium-6"); + $(option).addClass("option-divider"); + if (!$(option).hasClass("first")) { + $(option).insertBefore($(option).prev("div.option")); } } else { - $(answer).addClass("medium-6"); - $(answer).removeClass("answer-divider"); - if (!$(answer).hasClass("first")) { - $(answer).insertAfter($(answer).next("div.answer")); + $(option).addClass("medium-6"); + $(option).removeClass("option-divider"); + if (!$(option).hasClass("first")) { + $(option).insertAfter($(option).next("div.option")); } } }); diff --git a/app/assets/javascripts/questions.js b/app/assets/javascripts/questions.js index 5ce74d1fd..59058d6c1 100644 --- a/app/assets/javascripts/questions.js +++ b/app/assets/javascripts/questions.js @@ -3,7 +3,7 @@ App.Questions = { nestedQuestions: function() { $(".js-questions").on("cocoon:after-insert", function(e, new_question) { - App.Answers.initializeAnswers($(new_question).find(".js-answers")); + App.Options.initializeOptions($(new_question).find(".js-options")); }); }, initialize: function() { diff --git a/app/assets/javascripts/sortable.js b/app/assets/javascripts/sortable.js index ed085d5bd..69fa1da2e 100644 --- a/app/assets/javascripts/sortable.js +++ b/app/assets/javascripts/sortable.js @@ -6,7 +6,7 @@ update: function() { var new_order; new_order = $(this).sortable("toArray", { - attribute: "data-answer-id" + attribute: "data-option-id" }); $.ajax({ url: $(this).data("js-url"), diff --git a/app/assets/stylesheets/dashboard.scss b/app/assets/stylesheets/dashboard.scss index 746f7b1a2..d4d6afdfb 100644 --- a/app/assets/stylesheets/dashboard.scss +++ b/app/assets/stylesheets/dashboard.scss @@ -423,7 +423,7 @@ margin-bottom: $line-height; } -.answer-fields { +.option-fields { background: #fbfbfb; border: 1px solid $border; margin-bottom: $line-height; diff --git a/app/assets/stylesheets/mixins/icons.scss b/app/assets/stylesheets/mixins/icons.scss index bbf01a4ee..e6a81cea8 100644 --- a/app/assets/stylesheets/mixins/icons.scss +++ b/app/assets/stylesheets/mixins/icons.scss @@ -1597,7 +1597,7 @@ $font-awesome-icons: ( } .configure-link, - .answers-link { + .options-link { @include has-fa-icon(tools, solid); } diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index bc5148df7..a93f32562 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -1400,7 +1400,7 @@ } .poll-more-info, -.poll-more-info-answers { +.poll-more-info-options { .read-more { margin-bottom: $line-height; @@ -1416,7 +1416,7 @@ border-top: 1px solid #eee; } -.poll-more-info-answers { +.poll-more-info-options { @include full-width-background; @include full-width-border(top, 1px solid #eee); @include full-width-border(bottom, 1px solid #eee); @@ -1426,14 +1426,14 @@ border-right: 2px solid; } - .answer-divider { + .option-divider { border-bottom: 2px solid; border-right: 0 !important; margin-bottom: $line-height; padding-bottom: $line-height; } - .answer-description { + .option-description { height: 100%; &.short { @@ -1544,7 +1544,7 @@ } } -.poll-question-answers { +.poll-question-options { @include flex-with-gap($line-height * 0.25); flex-wrap: wrap; diff --git a/app/components/admin/action_component.rb b/app/components/admin/action_component.rb index fc592aff3..f7918834c 100644 --- a/app/components/admin/action_component.rb +++ b/app/components/admin/action_component.rb @@ -89,7 +89,7 @@ class Admin::ActionComponent < ApplicationComponent end def default_path - if %i[answers configure destroy preview show].include?(action.to_sym) + if %i[configure destroy options preview show].include?(action.to_sym) namespaced_polymorphic_path(namespace, record) else namespaced_polymorphic_path(namespace, record, { action: action }.merge(request.query_parameters)) diff --git a/app/components/admin/menu_component.rb b/app/components/admin/menu_component.rb index 2fb97d858..bbb9141ac 100644 --- a/app/components/admin/menu_component.rb +++ b/app/components/admin/menu_component.rb @@ -39,8 +39,8 @@ class Admin::MenuComponent < ApplicationComponent end def polls? - controller.class.module_parent == Admin::Poll::Questions::Answers || - %w[polls active_polls recounts results questions answers].include?(controller_name) && + controller.class.module_parent == Admin::Poll::Questions::Options || + %w[polls active_polls recounts results questions options].include?(controller_name) && action_name != "booth_assignments" end @@ -62,7 +62,7 @@ class Admin::MenuComponent < ApplicationComponent controllers_names = ["pages", "banners", "information_texts", "documents", "images", "content_blocks"] (controllers_names.include?(controller_name) || homepage? || pages?) && - controller.class.module_parent != Admin::Poll::Questions::Answers + controller.class.module_parent != Admin::Poll::Questions::Options end def homepage? @@ -515,7 +515,7 @@ class Admin::MenuComponent < ApplicationComponent [ t("admin.menu.site_customization.images"), admin_site_customization_images_path, - controller_name == "images" && controller.class.module_parent != Admin::Poll::Questions::Answers + controller_name == "images" && controller.class.module_parent != Admin::Poll::Questions::Options ] end diff --git a/app/components/admin/poll/questions/answers/documents/index_component.rb b/app/components/admin/poll/questions/answers/documents/index_component.rb deleted file mode 100644 index 60e816dc8..000000000 --- a/app/components/admin/poll/questions/answers/documents/index_component.rb +++ /dev/null @@ -1,14 +0,0 @@ -class Admin::Poll::Questions::Answers::Documents::IndexComponent < ApplicationComponent - attr_reader :answer - use_helpers :can? - - def initialize(answer) - @answer = answer - end - - private - - def documents - @documents ||= @answer.class.find(@answer.id).documents - end -end diff --git a/app/components/admin/poll/questions/answers/table_actions_component.html.erb b/app/components/admin/poll/questions/answers/table_actions_component.html.erb deleted file mode 100644 index d401f1a36..000000000 --- a/app/components/admin/poll/questions/answers/table_actions_component.html.erb +++ /dev/null @@ -1 +0,0 @@ -<%= render Admin::AllowedTableActionsComponent.new(answer) %> diff --git a/app/components/admin/poll/questions/answers/table_actions_component.rb b/app/components/admin/poll/questions/answers/table_actions_component.rb deleted file mode 100644 index 94b60b92e..000000000 --- a/app/components/admin/poll/questions/answers/table_actions_component.rb +++ /dev/null @@ -1,7 +0,0 @@ -class Admin::Poll::Questions::Answers::TableActionsComponent < ApplicationComponent - attr_reader :answer - - def initialize(answer) - @answer = answer - end -end diff --git a/app/components/admin/poll/questions/answers/documents/index_component.html.erb b/app/components/admin/poll/questions/options/documents/index_component.html.erb similarity index 71% rename from app/components/admin/poll/questions/answers/documents/index_component.html.erb rename to app/components/admin/poll/questions/options/documents/index_component.html.erb index 627159982..49666c076 100644 --- a/app/components/admin/poll/questions/answers/documents/index_component.html.erb +++ b/app/components/admin/poll/questions/options/documents/index_component.html.erb @@ -1,16 +1,16 @@ -<%= back_link_to admin_question_path(@answer.question) %> +<%= back_link_to admin_question_path(option.question) %>

<%= t("admin.questions.show.answers.documents_list") %>

- <% if can?(:update, @answer) %> - <%= form_for(Poll::Question::Answer.new, url: admin_answer_documents_path(answer)) do |f| %> - <%= render "shared/errors", resource: answer %> + <% if can?(:update, option) %> + <%= form_for(Poll::Question::Option.new, url: admin_option_documents_path(option)) do |f| %> + <%= render "shared/errors", resource: option %> <%= render Documents::NestedComponent.new(f) %> @@ -37,7 +37,7 @@ <%= document.title %> - <%= render Admin::Poll::Questions::Answers::Documents::TableActionsComponent.new(document) %> + <%= render Admin::Poll::Questions::Options::Documents::TableActionsComponent.new(document) %> <% end %> diff --git a/app/components/admin/poll/questions/options/documents/index_component.rb b/app/components/admin/poll/questions/options/documents/index_component.rb new file mode 100644 index 000000000..08925174d --- /dev/null +++ b/app/components/admin/poll/questions/options/documents/index_component.rb @@ -0,0 +1,14 @@ +class Admin::Poll::Questions::Options::Documents::IndexComponent < ApplicationComponent + attr_reader :option + use_helpers :can? + + def initialize(option) + @option = option + end + + private + + def documents + @documents ||= @option.class.find(@option.id).documents + end +end diff --git a/app/components/admin/poll/questions/answers/documents/table_actions_component.html.erb b/app/components/admin/poll/questions/options/documents/table_actions_component.html.erb similarity index 100% rename from app/components/admin/poll/questions/answers/documents/table_actions_component.html.erb rename to app/components/admin/poll/questions/options/documents/table_actions_component.html.erb diff --git a/app/components/admin/poll/questions/answers/documents/table_actions_component.rb b/app/components/admin/poll/questions/options/documents/table_actions_component.rb similarity index 64% rename from app/components/admin/poll/questions/answers/documents/table_actions_component.rb rename to app/components/admin/poll/questions/options/documents/table_actions_component.rb index da895ef1a..a261351fb 100644 --- a/app/components/admin/poll/questions/answers/documents/table_actions_component.rb +++ b/app/components/admin/poll/questions/options/documents/table_actions_component.rb @@ -1,4 +1,4 @@ -class Admin::Poll::Questions::Answers::Documents::TableActionsComponent < ApplicationComponent +class Admin::Poll::Questions::Options::Documents::TableActionsComponent < ApplicationComponent attr_reader :document def initialize(document) diff --git a/app/components/admin/poll/questions/options/table_actions_component.html.erb b/app/components/admin/poll/questions/options/table_actions_component.html.erb new file mode 100644 index 000000000..a49f959fc --- /dev/null +++ b/app/components/admin/poll/questions/options/table_actions_component.html.erb @@ -0,0 +1 @@ +<%= render Admin::AllowedTableActionsComponent.new(option) %> diff --git a/app/components/admin/poll/questions/options/table_actions_component.rb b/app/components/admin/poll/questions/options/table_actions_component.rb new file mode 100644 index 000000000..24acf4a0e --- /dev/null +++ b/app/components/admin/poll/questions/options/table_actions_component.rb @@ -0,0 +1,7 @@ +class Admin::Poll::Questions::Options::TableActionsComponent < ApplicationComponent + attr_reader :option + + def initialize(option) + @option = option + end +end diff --git a/app/components/admin/poll/questions/answers/videos/table_actions_component.html.erb b/app/components/admin/poll/questions/options/videos/table_actions_component.html.erb similarity index 100% rename from app/components/admin/poll/questions/answers/videos/table_actions_component.html.erb rename to app/components/admin/poll/questions/options/videos/table_actions_component.html.erb diff --git a/app/components/admin/poll/questions/answers/videos/table_actions_component.rb b/app/components/admin/poll/questions/options/videos/table_actions_component.rb similarity index 61% rename from app/components/admin/poll/questions/answers/videos/table_actions_component.rb rename to app/components/admin/poll/questions/options/videos/table_actions_component.rb index 06e772b6b..750e14f77 100644 --- a/app/components/admin/poll/questions/answers/videos/table_actions_component.rb +++ b/app/components/admin/poll/questions/options/videos/table_actions_component.rb @@ -1,4 +1,4 @@ -class Admin::Poll::Questions::Answers::Videos::TableActionsComponent < ApplicationComponent +class Admin::Poll::Questions::Options::Videos::TableActionsComponent < ApplicationComponent attr_reader :video def initialize(video) diff --git a/app/components/admin/poll/questions/table_actions_component.html.erb b/app/components/admin/poll/questions/table_actions_component.html.erb index 736eda7af..b06979f31 100644 --- a/app/components/admin/poll/questions/table_actions_component.html.erb +++ b/app/components/admin/poll/questions/table_actions_component.html.erb @@ -1,3 +1,3 @@ <%= render Admin::AllowedTableActionsComponent.new(question) do |actions| %> - <%= actions.action(:answers, text: t("admin.polls.show.edit_answers")) %> + <%= actions.action(:options, text: t("admin.polls.show.edit_answers")) %> <% end %> diff --git a/app/components/admin/site_customization/pages/edit_component.html.erb b/app/components/admin/site_customization/pages/edit_component.html.erb index 2cc012275..f408bd9ef 100644 --- a/app/components/admin/site_customization/pages/edit_component.html.erb +++ b/app/components/admin/site_customization/pages/edit_component.html.erb @@ -4,7 +4,7 @@ <%= header do %> <%= render Admin::ActionComponent.new( :destroy, - @page, + page, text: t("admin.site_customization.pages.index.delete"), confirm: true, class: "delete" diff --git a/app/components/admin/tenants/index_component.html.erb b/app/components/admin/tenants/index_component.html.erb index 63bb3504e..cfccdff62 100644 --- a/app/components/admin/tenants/index_component.html.erb +++ b/app/components/admin/tenants/index_component.html.erb @@ -14,7 +14,7 @@ - <% @tenants.each do |tenant| %> + <% tenants.each do |tenant| %> <%= render Admin::Tenants::RowComponent.new(tenant) %> <% end %> diff --git a/app/components/polls/questions/answers_component.html.erb b/app/components/polls/questions/options_component.html.erb similarity index 58% rename from app/components/polls/questions/answers_component.html.erb rename to app/components/polls/questions/options_component.html.erb index c9fc65343..b687ed249 100644 --- a/app/components/polls/questions/answers_component.html.erb +++ b/app/components/polls/questions/options_component.html.erb @@ -1,35 +1,35 @@ -
+
<% if can?(:answer, question) && !question.poll.voted_in_booth?(current_user) %> - <% question_answers.each do |question_answer| %> - <% if already_answered?(question_answer) %> - <%= button_to question_answer.title, - question_answer_path(question, user_answer(question_answer)), + <% question_options.each do |question_option| %> + <% if already_answered?(question_option) %> + <%= button_to question_option.title, + question_answer_path(question, user_answer(question_option)), method: :delete, remote: true, - title: t("poll_questions.show.voted", answer: question_answer.title), + title: t("poll_questions.show.voted", answer: question_option.title), class: "button answered", "aria-pressed": true %> <% else %> - <%= button_to question_answer.title, - answer_question_path(question, answer: question_answer.title), + <%= button_to question_option.title, + answer_question_path(question, answer: question_option.title), remote: true, - title: t("poll_questions.show.vote_answer", answer: question_answer.title), + title: t("poll_questions.show.vote_answer", answer: question_option.title), class: "button secondary hollow", "aria-pressed": false, - disabled: disable_answer?(question_answer) %> + disabled: disable_option?(question_option) %> <% end %> <% end %> <% elsif !user_signed_in? %> - <% question_answers.each do |question_answer| %> - <%= link_to question_answer.title, new_user_session_path, class: "button secondary hollow" %> + <% question_options.each do |question_option| %> + <%= link_to question_option.title, new_user_session_path, class: "button secondary hollow" %> <% end %> <% elsif !current_user.level_two_or_three_verified? %> - <% question_answers.each do |question_answer| %> - <%= link_to question_answer.title, verification_path, class: "button secondary hollow" %> + <% question_options.each do |question_option| %> + <%= link_to question_option.title, verification_path, class: "button secondary hollow" %> <% end %> <% else %> - <% question_answers.each do |question_answer| %> - <%= question_answer.title %> + <% question_options.each do |question_option| %> + <%= question_option.title %> <% end %> <% end %>
diff --git a/app/components/polls/questions/answers_component.rb b/app/components/polls/questions/options_component.rb similarity index 50% rename from app/components/polls/questions/answers_component.rb rename to app/components/polls/questions/options_component.rb index cebfbc235..25875cd6e 100644 --- a/app/components/polls/questions/answers_component.rb +++ b/app/components/polls/questions/options_component.rb @@ -1,4 +1,4 @@ -class Polls::Questions::AnswersComponent < ApplicationComponent +class Polls::Questions::OptionsComponent < ApplicationComponent attr_reader :question use_helpers :can?, :current_user, :user_signed_in? @@ -6,19 +6,19 @@ class Polls::Questions::AnswersComponent < ApplicationComponent @question = question end - def already_answered?(question_answer) - user_answer(question_answer).present? + def already_answered?(question_option) + user_answer(question_option).present? end - def question_answers - question.question_answers + def question_options + question.question_options end - def user_answer(question_answer) - user_answers.find_by(answer: question_answer.title) + def user_answer(question_option) + user_answers.find_by(answer: question_option.title) end - def disable_answer?(question_answer) + def disable_option?(question_option) question.multiple? && user_answers.count == question.max_votes end diff --git a/app/components/polls/questions/question_component.html.erb b/app/components/polls/questions/question_component.html.erb index ac675a889..46563a87b 100644 --- a/app/components/polls/questions/question_component.html.erb +++ b/app/components/polls/questions/question_component.html.erb @@ -9,14 +9,14 @@ <% end %> -
- <%= render Polls::Questions::AnswersComponent.new(question) %> +
+ <%= render Polls::Questions::OptionsComponent.new(question) %>
- <% if question.answers_with_read_more? %> + <% if question.options_with_read_more? %>

<%= t("poll_questions.read_more_about") %>

-

<%= answers_read_more_links %>

+

<%= options_read_more_links %>

<% end %>
diff --git a/app/components/polls/questions/question_component.rb b/app/components/polls/questions/question_component.rb index 09b8cacd9..ba52796b5 100644 --- a/app/components/polls/questions/question_component.rb +++ b/app/components/polls/questions/question_component.rb @@ -5,9 +5,9 @@ class Polls::Questions::QuestionComponent < ApplicationComponent @question = question end - def answers_read_more_links - safe_join(question.answers_with_read_more.map do |answer| - link_to answer.title, "#answer_#{answer.id}" + def options_read_more_links + safe_join(question.options_with_read_more.map do |option| + link_to option.title, "#option_#{option.id}" end, ", ") end end diff --git a/app/components/polls/questions/read_more_component.html.erb b/app/components/polls/questions/read_more_component.html.erb index e3672ddc4..90d4e382e 100644 --- a/app/components/polls/questions/read_more_component.html.erb +++ b/app/components/polls/questions/read_more_component.html.erb @@ -1,52 +1,52 @@

<%= question.title %>

-<% question.answers_with_read_more.each do |answer| %> -
" id="answer_<%= answer.id %>"> -

<%= answer.title %>

+<% question.options_with_read_more.each do |option| %> +
" id="option_<%= option.id %>"> +

<%= option.title %>

- <% if answer.description.present? %> -
- <%= wysiwyg(answer.description) %> + <% if option.description.present? %> +
+ <%= wysiwyg(option.description) %>
- -
<% end %> - <% if answer.images.any? %> - <%= render "polls/gallery", answer: answer %> + <% if option.images.any? %> + <%= render "polls/gallery", option: option %> <% end %> - <% if answer.documents.present? %> + <% if option.documents.present? %> <% end %> - <% if answer.videos.present? %> + <% if option.videos.present? %>