Rename HTML attributes referencing poll options

Since now poll question answers have been renamed to poll question
options, using HTML IDs, classes and data attributes named `answer` was
confusing.
This commit is contained in:
Javi Martín
2024-06-13 14:48:03 +02:00
parent 8997ed316c
commit 5fa6db2226
31 changed files with 58 additions and 58 deletions

View File

@@ -19,7 +19,7 @@
return max_order; return max_order;
}, },
nestedOptions: function() { nestedOptions: function() {
$(".js-answers").each(function(index, options) { $(".js-options").each(function(index, options) {
App.Options.initializeOptions(options); App.Options.initializeOptions(options);
}); });
}, },

View File

@@ -4,19 +4,19 @@
initialize: function() { initialize: function() {
$(".zoom-link").on("click", function(event) { $(".zoom-link").on("click", function(event) {
var option; var option;
option = $(event.target).closest("div.answer"); option = $(event.target).closest("div.option");
if ($(option).hasClass("medium-6")) { if ($(option).hasClass("medium-6")) {
$(option).removeClass("medium-6"); $(option).removeClass("medium-6");
$(option).addClass("answer-divider"); $(option).addClass("option-divider");
if (!$(option).hasClass("first")) { if (!$(option).hasClass("first")) {
$(option).insertBefore($(option).prev("div.answer")); $(option).insertBefore($(option).prev("div.option"));
} }
} else { } else {
$(option).addClass("medium-6"); $(option).addClass("medium-6");
$(option).removeClass("answer-divider"); $(option).removeClass("option-divider");
if (!$(option).hasClass("first")) { if (!$(option).hasClass("first")) {
$(option).insertAfter($(option).next("div.answer")); $(option).insertAfter($(option).next("div.option"));
} }
} }
}); });

View File

@@ -3,7 +3,7 @@
App.Questions = { App.Questions = {
nestedQuestions: function() { nestedQuestions: function() {
$(".js-questions").on("cocoon:after-insert", function(e, new_question) { $(".js-questions").on("cocoon:after-insert", function(e, new_question) {
App.Options.initializeOptions($(new_question).find(".js-answers")); App.Options.initializeOptions($(new_question).find(".js-options"));
}); });
}, },
initialize: function() { initialize: function() {

View File

@@ -6,7 +6,7 @@
update: function() { update: function() {
var new_order; var new_order;
new_order = $(this).sortable("toArray", { new_order = $(this).sortable("toArray", {
attribute: "data-answer-id" attribute: "data-option-id"
}); });
$.ajax({ $.ajax({
url: $(this).data("js-url"), url: $(this).data("js-url"),

View File

@@ -423,7 +423,7 @@
margin-bottom: $line-height; margin-bottom: $line-height;
} }
.answer-fields { .option-fields {
background: #fbfbfb; background: #fbfbfb;
border: 1px solid $border; border: 1px solid $border;
margin-bottom: $line-height; margin-bottom: $line-height;

View File

@@ -1597,7 +1597,7 @@ $font-awesome-icons: (
} }
.configure-link, .configure-link,
.answers-link { .options-link {
@include has-fa-icon(tools, solid); @include has-fa-icon(tools, solid);
} }

View File

@@ -1400,7 +1400,7 @@
} }
.poll-more-info, .poll-more-info,
.poll-more-info-answers { .poll-more-info-options {
.read-more { .read-more {
margin-bottom: $line-height; margin-bottom: $line-height;
@@ -1416,7 +1416,7 @@
border-top: 1px solid #eee; border-top: 1px solid #eee;
} }
.poll-more-info-answers { .poll-more-info-options {
@include full-width-background; @include full-width-background;
@include full-width-border(top, 1px solid #eee); @include full-width-border(top, 1px solid #eee);
@include full-width-border(bottom, 1px solid #eee); @include full-width-border(bottom, 1px solid #eee);
@@ -1426,14 +1426,14 @@
border-right: 2px solid; border-right: 2px solid;
} }
.answer-divider { .option-divider {
border-bottom: 2px solid; border-bottom: 2px solid;
border-right: 0 !important; border-right: 0 !important;
margin-bottom: $line-height; margin-bottom: $line-height;
padding-bottom: $line-height; padding-bottom: $line-height;
} }
.answer-description { .option-description {
height: 100%; height: 100%;
&.short { &.short {
@@ -1544,7 +1544,7 @@
} }
} }
.poll-question-answers { .poll-question-options {
@include flex-with-gap($line-height * 0.25); @include flex-with-gap($line-height * 0.25);
flex-wrap: wrap; flex-wrap: wrap;

View File

@@ -1,4 +1,4 @@
<div class="poll-question-answers"> <div class="poll-question-options">
<% if can?(:answer, question) && !question.poll.voted_in_booth?(current_user) %> <% if can?(:answer, question) && !question.poll.voted_in_booth?(current_user) %>
<% question_options.each do |question_option| %> <% question_options.each do |question_option| %>
<% if already_answered?(question_option) %> <% if already_answered?(question_option) %>

View File

@@ -9,7 +9,7 @@
</strong> </strong>
<% end %> <% end %>
<div id="<%= dom_id(question) %>_answers" class="padding"> <div id="<%= dom_id(question) %>_options" class="padding">
<%= render Polls::Questions::OptionsComponent.new(question) %> <%= render Polls::Questions::OptionsComponent.new(question) %>
</div> </div>

View File

@@ -7,7 +7,7 @@ class Polls::Questions::QuestionComponent < ApplicationComponent
def options_read_more_links def options_read_more_links
safe_join(question.options_with_read_more.map do |option| safe_join(question.options_with_read_more.map do |option|
link_to option.title, "#answer_#{option.id}" link_to option.title, "#option_#{option.id}"
end, ", ") end, ", ")
end end
end end

View File

@@ -1,21 +1,21 @@
<h2><%= question.title %></h2> <h2><%= question.title %></h2>
<% question.options_with_read_more.each do |option| %> <% question.options_with_read_more.each do |option| %>
<div class="small-12 medium-6 column end answer <%= cycle("first", "") %>" id="answer_<%= option.id %>"> <div class="small-12 medium-6 column end option <%= cycle("first", "") %>" id="option_<%= option.id %>">
<h3><%= option.title %></h3> <h3><%= option.title %></h3>
<div class="margin-top"> <div class="margin-top">
<% if option.description.present? %> <% if option.description.present? %>
<div id="answer_description_<%= option.id %>" class="answer-description short" data-toggler="short"> <div id="option_description_<%= option.id %>" class="option-description short" data-toggler="short">
<%= wysiwyg(option.description) %> <%= wysiwyg(option.description) %>
</div> </div>
<div class="read-more"> <div class="read-more">
<button type="button" id="read_more_<%= option.id %>" <button type="button" id="read_more_<%= option.id %>"
data-toggle="answer_description_<%= option.id %> read_more_<%= option.id %> read_less_<%= option.id %>" data-toggle="option_description_<%= option.id %> read_more_<%= option.id %> read_less_<%= option.id %>"
data-toggler="hide"> data-toggler="hide">
<%= t("polls.show.read_more", answer: option.title) %> <%= t("polls.show.read_more", answer: option.title) %>
</button> </button>
<button type="button" id="read_less_<%= option.id %>" <button type="button" id="read_less_<%= option.id %>"
data-toggle="answer_description_<%= option.id %> read_more_<%= option.id %> read_less_<%= option.id %>" data-toggle="option_description_<%= option.id %> read_more_<%= option.id %> read_less_<%= option.id %>"
data-toggler="hide" data-toggler="hide"
class="hide"> class="hide">
<%= t("polls.show.read_less", answer: option.title) %> <%= t("polls.show.read_less", answer: option.title) %>

View File

@@ -15,7 +15,7 @@
<tbody> <tbody>
<tr> <tr>
<%- question.question_options.each do |option| %> <%- question.question_options.each do |option| %>
<td id="answer_<%= option.id %>_result" class="<%= option_styles(option) %>"> <td id="option_<%= option.id %>_result" class="<%= option_styles(option) %>">
<%= option.total_votes %> <%= option.total_votes %>
(<%= option.total_votes_percentage.round(2) %>%) (<%= option.total_votes_percentage.round(2) %>%)
</td> </td>

View File

@@ -9,6 +9,6 @@
<%= t("admin.answers.edit.title") %> <%= t("admin.answers.edit.title") %>
</h2> </h2>
<div class="poll-question-answer-form"> <div class="poll-question-option-form">
<%= render "form", form_url: admin_question_option_path(@question, @option) %> <%= render "form", form_url: admin_question_option_path(@question, @option) %>
</div> </div>

View File

@@ -7,6 +7,6 @@
<h2><%= t("admin.answers.new.title") %></h2> <h2><%= t("admin.answers.new.title") %></h2>
<div class="poll-question-answer-form"> <div class="poll-question-option-form">
<%= render "form", form_url: admin_question_options_path %> <%= render "form", form_url: admin_question_options_path %>
</div> </div>

View File

@@ -4,6 +4,6 @@
<%= t("admin.answers.videos.edit.title") %> <%= t("admin.answers.videos.edit.title") %>
</h2> </h2>
<div class="poll-question-answer-video-form"> <div class="poll-question-option-video-form">
<%= render "form", form_url: admin_option_video_path(@option, @video) %> <%= render "form", form_url: admin_option_video_path(@option, @video) %>
</div> </div>

View File

@@ -29,7 +29,7 @@
<tbody> <tbody>
<% @videos.each do |video| %> <% @videos.each do |video| %>
<tr id="<%= dom_id(video) %>" class="poll_question_answer_video"> <tr id="<%= dom_id(video) %>" class="poll_question_option_video">
<td><%= video.title %></td> <td><%= video.title %></td>
<td><%= link_to video.url, video.url %></td> <td><%= link_to video.url, video.url %></td>
<td> <td>

View File

@@ -4,6 +4,6 @@
<%= t("admin.answers.videos.new.title") %> <%= t("admin.answers.videos.new.title") %>
</h2> </h2>
<div class="poll-question-answer-video-form"> <div class="poll-question-option-video-form">
<%= render "form", form_url: admin_option_videos_path(@option) %> <%= render "form", form_url: admin_option_videos_path(@option) %>
</div> </div>

View File

@@ -72,7 +72,7 @@
<tbody class="sortable" data-js-url="<%= admin_question_options_order_options_path(@question.id) %>"> <tbody class="sortable" data-js-url="<%= admin_question_options_order_options_path(@question.id) %>">
<% @question.question_options.each do |option| %> <% @question.question_options.each do |option| %>
<tr id="<%= dom_id(option) %>" class="poll_question_answer" data-answer-id="<%= option.id %>"> <tr id="<%= dom_id(option) %>" class="poll_question_option" data-option-id="<%= option.id %>">
<td class="align-top"><%= option.title %></td> <td class="align-top"><%= option.title %></td>
<td class="align-top break"><%= wysiwyg(option.description) %></td> <td class="align-top break"><%= wysiwyg(option.description) %></td>
<td class="align-top text-center"> <td class="align-top text-center">

View File

@@ -12,12 +12,12 @@
</div> </div>
</div> </div>
<div class="js-answers"> <div class="js-options">
<%= f.fields_for :question_options do |option_form| %> <%= f.fields_for :question_options do |option_form| %>
<%= render "question_option_fields", f: option_form %> <%= render "question_option_fields", f: option_form %>
<% end %> <% end %>
<div class="answer-links links row expanded"> <div class="option-links links row expanded">
<div class="small-12 column"> <div class="small-12 column">
<%= link_to_add_association t("dashboard.polls.question_fields.add_answer"), <%= link_to_add_association t("dashboard.polls.question_fields.add_answer"),
f, :question_options, class: "button hollow" %> f, :question_options, class: "button hollow" %>

View File

@@ -1,5 +1,5 @@
<div class="nested-fields nested-answers small-12 medium-6 column"> <div class="nested-fields nested-options small-12 medium-6 column">
<div class="answer-fields"> <div class="option-fields">
<%= f.hidden_field :given_order %> <%= f.hidden_field :given_order %>
<div class="row expanded"> <div class="row expanded">
<div class="small-12 medium-9 column"> <div class="small-12 medium-9 column">

View File

@@ -1,5 +1,5 @@
<div class="orbit margin-bottom" role="region" aria-label="<%= option.title %>" data-orbit data-auto-play="false" data-use-m-u-i="false"> <div class="orbit margin-bottom" role="region" aria-label="<%= option.title %>" data-orbit data-auto-play="false" data-use-m-u-i="false">
<button type="button" data-toggle="answer_<%= option.id %> zoom_<%= option.id %>" class="zoom-link hide-for-small-only"> <button type="button" data-toggle="option_<%= option.id %> zoom_<%= option.id %>" class="zoom-link hide-for-small-only">
<span id="zoom_<%= option.id %>" class="icon-search-plus" data-toggler="icon-search-plus icon-search-minus"></span> <span id="zoom_<%= option.id %>" class="icon-search-plus" data-toggler="icon-search-plus icon-search-minus"></span>
<span class="show-for-sr"><%= t("polls.show.zoom_plus") %></span> <span class="show-for-sr"><%= t("polls.show.zoom_plus") %></span>
</button> </button>

View File

@@ -1 +1 @@
$("#<%= dom_id(@question) %>_answers").html("<%= j render Polls::Questions::OptionsComponent.new(@question) %>"); $("#<%= dom_id(@question) %>_options").html("<%= j render Polls::Questions::OptionsComponent.new(@question) %>");

View File

@@ -44,7 +44,7 @@
</div> </div>
</div> </div>
<div id="poll_more_info_answers" class="expanded poll-more-info-answers"> <div id="poll_more_info_options" class="expanded poll-more-info-options">
<div class="row padding"> <div class="row padding">
<%= render Polls::Questions::ReadMoreComponent.with_collection(@questions) %> <%= render Polls::Questions::ReadMoreComponent.with_collection(@questions) %>
</div> </div>

View File

@@ -11,8 +11,8 @@ describe Polls::Questions::QuestionComponent do
poll_question = page.find("#poll_question_#{question.id}") poll_question = page.find("#poll_question_#{question.id}")
expect(poll_question).to have_content("Read more about") expect(poll_question).to have_content("Read more about")
expect(poll_question).to have_link("Answer A", href: "#answer_#{option_a.id}") expect(poll_question).to have_link("Answer A", href: "#option_#{option_a.id}")
expect(poll_question).to have_link("Answer B", href: "#answer_#{option_b.id}") expect(poll_question).to have_link("Answer B", href: "#option_#{option_b.id}")
expect(poll_question).to have_content("Answer A, Answer B") expect(poll_question).to have_content("Answer A, Answer B")
end end
end end

View File

@@ -2,7 +2,7 @@ module Polls
def vote_for_poll_via_web(poll, question, option) def vote_for_poll_via_web(poll, question, option)
visit poll_path(poll) visit poll_path(poll)
within("#poll_question_#{question.id}_answers") do within("#poll_question_#{question.id}_options") do
click_button option click_button option
expect(page).to have_button("You have voted #{option}") expect(page).to have_button("You have voted #{option}")

View File

@@ -174,7 +174,7 @@ describe "Polls" do
click_link "Edit survey" click_link "Edit survey"
end end
within ".js-questions .js-answers" do within ".js-questions .js-options" do
expect(page).to have_css ".nested-fields", count: 2 expect(page).to have_css ".nested-fields", count: 2
within first(".nested-fields") do within first(".nested-fields") do
click_link class: "delete" click_link class: "delete"
@@ -188,7 +188,7 @@ describe "Polls" do
visit edit_proposal_dashboard_poll_path(proposal, poll) visit edit_proposal_dashboard_poll_path(proposal, poll)
within ".js-questions .js-answers" do within ".js-questions .js-options" do
expect(page).to have_css ".nested-fields", count: 1 expect(page).to have_css ".nested-fields", count: 1
end end
end end

View File

@@ -206,7 +206,7 @@ describe "Polls" do
login_as user login_as user
visit poll_path(poll) visit poll_path(poll)
within("#poll_question_#{question.id}_answers") do within("#poll_question_#{question.id}_options") do
click_button "Vote Yes" click_button "Vote Yes"
expect(page).to have_button "You have voted Yes" expect(page).to have_button "You have voted Yes"
@@ -223,7 +223,7 @@ describe "Polls" do
login_as user login_as user
visit poll_path(poll) visit poll_path(poll)
within("#poll_question_#{question.id}_answers") do within("#poll_question_#{question.id}_options") do
click_button "Yes" click_button "Yes"
expect(page).to have_button "You have voted Yes" expect(page).to have_button "You have voted Yes"
@@ -266,7 +266,7 @@ describe "Polls" do
login_as user login_as user
visit poll_path(poll) visit poll_path(poll)
within("#poll_question_#{question.id}_answers") do within("#poll_question_#{question.id}_options") do
click_button "Yes" click_button "Yes"
expect(page).to have_button "You have voted Yes" expect(page).to have_button "You have voted Yes"
@@ -301,7 +301,7 @@ describe "Polls" do
expect(page).to have_content "You have already participated in a physical booth. " \ expect(page).to have_content "You have already participated in a physical booth. " \
"You can not participate again." "You can not participate again."
within("#poll_question_#{question.id}_answers") do within("#poll_question_#{question.id}_options") do
expect(page).to have_content("Yes") expect(page).to have_content("Yes")
expect(page).to have_content("No") expect(page).to have_content("No")

View File

@@ -18,7 +18,7 @@ describe "Poll Questions" do
visit poll_path(poll) visit poll_path(poll)
within "#poll_more_info_answers" do within "#poll_more_info_options" do
expect(page).to have_content "Pedestrian road" expect(page).to have_content "Pedestrian road"
expect(page).to have_css "img[alt='Trees on both sides of the road']" expect(page).to have_css "img[alt='Trees on both sides of the road']"
end end

View File

@@ -39,14 +39,14 @@ describe "Poll Results" do
expect(page).to have_content(question2.title) expect(page).to have_content(question2.title)
within("#question_#{question1.id}_results_table") do within("#question_#{question1.id}_results_table") do
expect(find("#answer_#{option1.id}_result")).to have_content("2 (66.67%)") expect(find("#option_#{option1.id}_result")).to have_content("2 (66.67%)")
expect(find("#answer_#{option2.id}_result")).to have_content("1 (33.33%)") expect(find("#option_#{option2.id}_result")).to have_content("1 (33.33%)")
end end
within("#question_#{question2.id}_results_table") do within("#question_#{question2.id}_results_table") do
expect(find("#answer_#{option3.id}_result")).to have_content("1 (33.33%)") expect(find("#option_#{option3.id}_result")).to have_content("1 (33.33%)")
expect(find("#answer_#{option4.id}_result")).to have_content("1 (33.33%)") expect(find("#option_#{option4.id}_result")).to have_content("1 (33.33%)")
expect(find("#answer_#{option5.id}_result")).to have_content("1 (33.33%)") expect(find("#option_#{option5.id}_result")).to have_content("1 (33.33%)")
end end
end end

View File

@@ -17,7 +17,7 @@ describe "Poll Votation Type" do
expect(page).to have_button("Vote Yes") expect(page).to have_button("Vote Yes")
expect(page).to have_button("Vote No") expect(page).to have_button("Vote No")
within "#poll_question_#{question.id}_answers" do within "#poll_question_#{question.id}_options" do
click_button "Yes" click_button "Yes"
expect(page).to have_button("You have voted Yes") expect(page).to have_button("You have voted Yes")
@@ -40,7 +40,7 @@ describe "Poll Votation Type" do
expect(page).to have_button("Vote Answer B") expect(page).to have_button("Vote Answer B")
expect(page).to have_button("Vote Answer C") expect(page).to have_button("Vote Answer C")
within "#poll_question_#{question.id}_answers" do within "#poll_question_#{question.id}_options" do
click_button "Vote Answer A" click_button "Vote Answer A"
expect(page).to have_button("You have voted Answer A") expect(page).to have_button("You have voted Answer A")

View File

@@ -20,7 +20,7 @@ describe "Voter" do
login_as user login_as user
visit poll_path(poll) visit poll_path(poll)
within("#poll_question_#{question.id}_answers") do within("#poll_question_#{question.id}_options") do
click_button "Vote Yes" click_button "Vote Yes"
expect(page).to have_button("You have voted Yes") expect(page).to have_button("You have voted Yes")
@@ -44,7 +44,7 @@ describe "Voter" do
expect(page).to have_content("You have already participated in this poll.") expect(page).to have_content("You have already participated in this poll.")
expect(page).to have_content("If you vote again it will be overwritten") expect(page).to have_content("If you vote again it will be overwritten")
within("#poll_question_#{question.id}_answers") do within("#poll_question_#{question.id}_options") do
click_button "You have voted Yes" click_button "You have voted Yes"
expect(page).to have_button("Vote Yes") expect(page).to have_button("Vote Yes")
@@ -63,7 +63,7 @@ describe "Voter" do
login_as user login_as user
visit poll_path(poll) visit poll_path(poll)
within("#poll_question_#{question.id}_answers") do within("#poll_question_#{question.id}_options") do
expect(page).to have_link("Yes", href: verification_path) expect(page).to have_link("Yes", href: verification_path)
expect(page).to have_link("No", href: verification_path) expect(page).to have_link("No", href: verification_path)
end end
@@ -171,7 +171,7 @@ describe "Voter" do
login_as user login_as user
visit poll_path(poll) visit poll_path(poll)
within("#poll_question_#{question.id}_answers") do within("#poll_question_#{question.id}_options") do
expect(page).not_to have_button("Yes") expect(page).not_to have_button("Yes")
end end
expect(page).to have_content "You have already participated in a physical booth. " \ expect(page).to have_content "You have already participated in a physical booth. " \
@@ -211,7 +211,7 @@ describe "Voter" do
visit poll_path(poll) visit poll_path(poll)
within("#poll_question_#{question.id}_answers") do within("#poll_question_#{question.id}_options") do
expect(page).not_to have_button("Yes") expect(page).not_to have_button("Yes")
end end