Skip to content

Commit

Permalink
Fix multiple page map problems with tooltips and rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
JoonasAapro committed Apr 23, 2024
1 parent c61946c commit f57a97a
Show file tree
Hide file tree
Showing 4 changed files with 187 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,30 @@ $(() => {
event.returnValue = true;
});
}

const callback = (mutationsList) => {
mutationsList.forEach((mutation) => {
if (mutation.type === "attributes") {
const classList = Array.from(mutation.target.classList);
if (!classList.includes("hide")) {
mutation.target.querySelectorAll("[data-decidim-map]").forEach((map) => {
const mapCtrl = $(map).data("map-controller");
mapCtrl.map.invalidateSize();
mapCtrl.start();
mapCtrl.refreshMarkers();
})
}
}
})
};

const observer = new MutationObserver(callback)

const config = { attributes: true }

if ($(".questionnaire-step")) {
$(".questionnaire-step").each((idx, el) => {
observer.observe(el, config);
})
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ class LocationOptionAttachedInputsComponent {
}

_run() {
this.controllerSelector.each((idx, el) => {
this.controllerSelector.each((_idx, el) => {
const $field = $(el);
const enabled = $field.is(":checked");
$field.parents("div.collection-input").find(this.dependentInputSelector).each((idx, element) => {
$field.parents("div.collection-input").find(this.dependentInputSelector).each((_index, element) => {
$(element).prop("disabled", !enabled)
});
});
}

_bindEvent() {
this.controllerSelector.each((idx, el) => {
this.controllerSelector.each((_idx, el) => {
const $field = $(el)
$field.on("change", () => {
this._run();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
<% add_decidim_meta_tags({
title: translated_attribute(questionnaire.title),
description: translated_attribute(questionnaire.description),
}) %>

<% columns = allow_answers? && visitor_can_answer? && @form.responses.map(&:question).any?(&:matrix?) ? 9 : 6 %>

<%= render partial: "decidim/shared/component_announcement" if current_component.manifest_name == "surveys" %>

<div class="row columns">
<h2 class="section-heading"><%= translated_attribute questionnaire.title %></h2>
<div class="row">
<div class="columns large-<%= columns %> medium-centered lead">
<%= decidim_sanitize_editor_admin translated_attribute questionnaire.description %>
</div>
</div>
</div>

<div class="row">
<div class="columns large-<%= columns %> medium-centered">
<div class="card">
<div class="card__content">
<% unless questionnaire_for.try(:component)&.try(:published?) %>
<div class="section">
<div class="callout warning">
<p><%= t(".questionnaire_not_published.body") %></p>
</div>
</div>
<% end %>

<% if allow_answers? %>
<% if visitor_can_answer? %>
<% if visitor_already_answered? %>
<div class="section">
<div class="callout success">
<h3 class="heading5"><%= t(".questionnaire_answered.title") %></h3>
<p><%= t(".questionnaire_answered.body") %></p>
</div>
</div>
<% else %>
<div class="answer-questionnaire">
<noscript>
<div class="section">
<div class="callout warning">
<h3 class="heading5"><%= t(".questionnaire_js_disabled.title") %></h3>
<p><%= t(".questionnaire_js_disabled.body") %></p>
</div>
</div>
</noscript>
<% unless current_participatory_space.can_participate?(current_user) %>
<div class="section">
<div class="callout alert">
<h3 class="heading5"><%= t(".questionnaire_for_private_users.title") %></h3>
<p><%= t(".questionnaire_for_private_users.body") %></p>
</div>
</div>
<% end %>

<%= decidim_form_for(@form, url: update_url, method: :post, html: { multipart: true, class: "form answer-questionnaire" }, data: { "safe-path" => form_path }) do |form| %>
<%= form_required_explanation %>
<%= invisible_captcha %>
<% answer_idx = 0 %>
<% cleaned_answer_idx = 0 %>
<% @form.responses_by_step.each_with_index do |step_answers, step_index| %>
<div id="step-<%= step_index %>" class="<%= step_index.zero? ? "questionnaire-step" : "questionnaire-step hide" %>" data-toggler=".hide">
<% if @form.total_steps > 1 %>
<h3 class="section-heading">
<%= t(".current_step", step: step_index + 1) %>
<span class="answer-questionnaire__steps"><%= t(".of_total_steps", total_steps: @form.total_steps) %></span>
</h3>
<% end %>

<% step_answers.each do |answer| %>
<div class="row column answer question" data-max-choices="<%= answer.question.max_choices %>" data-conditioned="<%= answer.question.display_conditions.any? %>" data-question-id="<%= answer.question.id %>">
<% answer.question.display_conditions.each do |display_condition| %>
<%= content_tag :div, nil, class: "display-condition", data: display_condition.to_html_data %>
<% end %>

<%= fields_for "questionnaire[responses][#{answer_idx}]", answer do |answer_form| %>
<%= render(
"decidim/forms/questionnaires/answer",
answer_form: answer_form,
answer: answer,
answer_idx: answer_idx,
cleaned_answer_idx: cleaned_answer_idx,
disabled: !current_participatory_space.can_participate?(current_user)
) %>
<% end %>
</div>
<% if !(answer.question.separator? || answer.question.title_and_description?) %>
<% cleaned_answer_idx += 1 %>
<% end %>
<% answer_idx += 1 %>
<% end %>

<% if step_index + 1 == @form.total_steps %>
<% if show_represent_user_group? %>
<div class="row column represent-user-group">
<%= cell("decidim/represent_user_group", form) %>
</div>
<% end %>

<% if show_public_participation? %>
<div class="row column public-participation">
<%= cell("decidim/public_participation", form) %>
</div>
<% end %>

<div class="row column tos-agreement">
<%= form.check_box :tos_agreement, label: t(".tos_agreement"), id: "questionnaire_tos_agreement", disabled: !current_participatory_space.can_participate?(current_user) %>
<div class="help-text">
<%= decidim_sanitize_editor translated_attribute questionnaire.tos %>
</div>
</div>
<% end %>

<%= cell(
"decidim/forms/step_navigation",
step_index,
total_steps: @form.total_steps,
button_disabled: !current_participatory_space.can_participate?(current_user),
form: form
) %>

</div>
<% end %>
<% end %>
</div>
<% end %>
<% else %>
<div class="answer-questionnaire">
<h3 class="section-heading"><%= t(".answer_questionnaire.title") %></h3>
<p>
<%= t(".answer_questionnaire.anonymous_user_message", sign_in_link: decidim.new_user_session_path, sign_up_link: decidim.new_user_registration_path).html_safe %>
</p>

<ol>
<%= cell("decidim/forms/question_readonly", collection: @questionnaire.questions.not_conditioned) %>
</ol>
</div>
<% end %>
<% else %>
<div class="section">
<div class="callout warning">
<h3 class="heading4"><%= t(".questionnaire_closed.title") %></h3>
<p><%= t(".questionnaire_closed.body") %></p>
</div>
</div>
<% end %>
</div>
</div>
</div>
</div>

<% content_for :js_content do %>
<%= javascript_pack_tag "decidim_forms" %>
<% end %>
1 change: 1 addition & 0 deletions decidim-module-forms_locations/config/assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
decidim_forms_locations: "#{base_path}/app/packs/entrypoints/decidim_forms_locations.js",
decidim_forms_admin: "#{base_path}/app/packs/entrypoints/decidim_forms_admin.js"
)

Decidim::Webpacker.register_stylesheet_import("stylesheets/decidim/forms_locations/forms_locations", group: :admin)

0 comments on commit f57a97a

Please sign in to comment.