decidim-forms 0.30.2 → 0.31.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +10 -10
  3. data/app/cells/decidim/forms/matrix_readonly/show.erb +1 -1
  4. data/app/cells/decidim/forms/matrix_readonly_cell.rb +3 -3
  5. data/app/cells/decidim/forms/question_readonly/show.erb +5 -5
  6. data/app/cells/decidim/forms/question_readonly/title_and_description.erb +3 -3
  7. data/app/cells/decidim/forms/response_readonly_cell.rb +9 -0
  8. data/app/cells/decidim/forms/step_navigation/show.erb +3 -3
  9. data/app/cells/decidim/forms/step_navigation_cell.rb +3 -3
  10. data/app/commands/decidim/forms/admin/update_questions.rb +6 -6
  11. data/app/commands/decidim/forms/{answer_questionnaire.rb → response_questionnaire.rb} +35 -35
  12. data/app/controllers/decidim/forms/admin/concerns/has_questionnaire.rb +12 -12
  13. data/app/controllers/decidim/forms/admin/concerns/{has_questionnaire_answers.rb → has_questionnaire_responses.rb} +23 -19
  14. data/app/controllers/decidim/forms/concerns/has_questionnaire.rb +38 -33
  15. data/app/forms/decidim/forms/admin/display_condition_form.rb +14 -14
  16. data/app/forms/decidim/forms/admin/question_form.rb +3 -3
  17. data/app/forms/decidim/forms/admin/{answer_option_form.rb → response_option_form.rb} +3 -3
  18. data/app/forms/decidim/forms/questionnaire_form.rb +8 -9
  19. data/app/forms/decidim/forms/{answer_choice_form.rb → response_choice_form.rb} +5 -5
  20. data/app/forms/decidim/forms/{answer_form.rb → response_form.rb} +9 -9
  21. data/app/helpers/decidim/forms/admin/application_helper.rb +2 -2
  22. data/app/helpers/decidim/forms/admin/concerns/{has_questionnaire_answers_pagination_helper.rb → has_questionnaire_responses_pagination_helper.rb} +4 -4
  23. data/app/helpers/decidim/forms/admin/concerns/{has_questionnaire_answers_url_helper.rb → has_questionnaire_responses_url_helper.rb} +5 -5
  24. data/app/helpers/decidim/forms/admin/questionnaire_responses_helper.rb +32 -0
  25. data/app/helpers/decidim/forms/application_helper.rb +1 -2
  26. data/app/jobs/decidim/forms/{export_questionnaire_answers_job.rb → export_questionnaire_responses_job.rb} +5 -5
  27. data/app/models/decidim/forms/display_condition.rb +20 -20
  28. data/app/models/decidim/forms/question.rb +14 -13
  29. data/app/models/decidim/forms/question_matrix_row.rb +1 -1
  30. data/app/models/decidim/forms/questionnaire.rb +11 -6
  31. data/app/models/decidim/forms/{answer.rb → response.rb} +9 -9
  32. data/app/models/decidim/forms/response_choice.rb +22 -0
  33. data/app/models/decidim/forms/{answer_option.rb → response_option.rb} +5 -5
  34. data/app/packs/entrypoints/decidim_forms_admin.js +3 -3
  35. data/app/packs/src/decidim/forms/admin/collapsible_questions.js +12 -10
  36. data/app/packs/src/decidim/forms/admin/forms.js +35 -35
  37. data/app/packs/src/decidim/forms/admin/{publish_answers_buttons.js → publish_responses_buttons.js} +12 -12
  38. data/app/packs/src/decidim/forms/display_conditions.component.js +12 -12
  39. data/app/packs/src/decidim/forms/forms.js +4 -4
  40. data/app/packs/stylesheets/decidim/forms/forms.scss +2 -2
  41. data/app/presenters/decidim/forms/admin/questionnaire_participant_presenter.rb +13 -13
  42. data/app/presenters/decidim/forms/admin/{questionnaire_answer_presenter.rb → questionnaire_response_presenter.rb} +15 -15
  43. data/app/presenters/decidim/forms/admin_log/question_presenter.rb +3 -3
  44. data/app/presenters/decidim/forms/{answer_option_presenter.rb → response_option_presenter.rb} +2 -2
  45. data/app/queries/decidim/forms/questionnaire_participant.rb +5 -5
  46. data/app/queries/decidim/forms/questionnaire_participants.rb +6 -6
  47. data/app/queries/decidim/forms/questionnaire_user_responses.rb +32 -0
  48. data/app/views/decidim/forms/admin/questionnaires/_display_condition.html.erb +9 -9
  49. data/app/views/decidim/forms/admin/questionnaires/_form.html.erb +2 -2
  50. data/app/views/decidim/forms/admin/questionnaires/_matrix_row.html.erb +3 -3
  51. data/app/views/decidim/forms/admin/questionnaires/_question.html.erb +16 -16
  52. data/app/views/decidim/forms/admin/questionnaires/_questions_form.html.erb +11 -10
  53. data/app/views/decidim/forms/admin/questionnaires/{_answer_option.html.erb → _response_option.html.erb} +7 -7
  54. data/app/views/decidim/forms/admin/questionnaires/_response_option_template.html.erb +7 -0
  55. data/app/views/decidim/forms/admin/questionnaires/_separator.html.erb +10 -7
  56. data/app/views/decidim/forms/admin/questionnaires/_title_and_description.html.erb +7 -7
  57. data/app/views/decidim/forms/admin/questionnaires/edit.html.erb +1 -1
  58. data/app/views/decidim/forms/admin/questionnaires/edit_questions.html.erb +8 -8
  59. data/app/views/decidim/forms/admin/questionnaires/responses/index.html.erb +80 -0
  60. data/app/views/decidim/forms/admin/questionnaires/responses/show.html.erb +43 -0
  61. data/app/views/decidim/forms/questionnaires/_questionnaire.html.erb +22 -26
  62. data/app/views/decidim/forms/questionnaires/_questionnaire_readonly.html.erb +8 -3
  63. data/app/views/decidim/forms/questionnaires/_response.html.erb +61 -0
  64. data/app/views/decidim/forms/questionnaires/edit.html.erb +2 -2
  65. data/app/views/decidim/forms/questionnaires/responses/_files.html.erb +1 -0
  66. data/app/views/decidim/forms/questionnaires/responses/_long_response.html.erb +3 -0
  67. data/app/views/decidim/forms/questionnaires/{answers → responses}/_matrix_multiple.html.erb +16 -15
  68. data/app/views/decidim/forms/questionnaires/{answers → responses}/_matrix_single.html.erb +17 -16
  69. data/app/views/decidim/forms/questionnaires/responses/_multiple_option.html.erb +26 -0
  70. data/app/views/decidim/forms/questionnaires/responses/_separator.html.erb +1 -0
  71. data/app/views/decidim/forms/questionnaires/responses/_short_response.html.erb +3 -0
  72. data/app/views/decidim/forms/questionnaires/responses/_single_option.html.erb +33 -0
  73. data/app/views/decidim/forms/questionnaires/responses/_sorting.html.erb +26 -0
  74. data/app/views/decidim/forms/questionnaires/responses/_title_and_description.html.erb +1 -0
  75. data/app/views/decidim/forms/questionnaires/show.html.erb +10 -10
  76. data/config/assets.rb +2 -2
  77. data/config/locales/ar.yml +0 -22
  78. data/config/locales/bg.yml +3 -36
  79. data/config/locales/ca-IT.yml +73 -73
  80. data/config/locales/ca.yml +73 -73
  81. data/config/locales/cs.yml +72 -75
  82. data/config/locales/de.yml +72 -72
  83. data/config/locales/el.yml +3 -36
  84. data/config/locales/en.yml +83 -83
  85. data/config/locales/es-MX.yml +75 -75
  86. data/config/locales/es-PY.yml +75 -75
  87. data/config/locales/es.yml +73 -73
  88. data/config/locales/eu.yml +71 -71
  89. data/config/locales/fi-plain.yml +71 -71
  90. data/config/locales/fi.yml +69 -69
  91. data/config/locales/fr-CA.yml +70 -67
  92. data/config/locales/fr.yml +70 -67
  93. data/config/locales/ga-IE.yml +0 -7
  94. data/config/locales/gl.yml +0 -22
  95. data/config/locales/hu.yml +0 -22
  96. data/config/locales/id-ID.yml +0 -22
  97. data/config/locales/it.yml +3 -40
  98. data/config/locales/ja.yml +80 -80
  99. data/config/locales/lb.yml +3 -36
  100. data/config/locales/lt.yml +3 -36
  101. data/config/locales/lv.yml +0 -22
  102. data/config/locales/nl.yml +3 -36
  103. data/config/locales/no.yml +3 -36
  104. data/config/locales/pl.yml +3 -36
  105. data/config/locales/pt-BR.yml +3 -36
  106. data/config/locales/pt.yml +3 -36
  107. data/config/locales/ro-RO.yml +22 -51
  108. data/config/locales/ru.yml +0 -9
  109. data/config/locales/sk.yml +0 -22
  110. data/config/locales/sl.yml +0 -5
  111. data/config/locales/sv.yml +82 -54
  112. data/config/locales/tr-TR.yml +3 -36
  113. data/config/locales/zh-CN.yml +3 -36
  114. data/config/locales/zh-TW.yml +3 -36
  115. data/db/migrate/20190315203056_add_session_token_to_decidim_forms_answers.rb +1 -1
  116. data/db/migrate/20250314150250_rename_answer_to_response_in_decidim_forms.rb +30 -0
  117. data/db/migrate/20250319130003_change_question_types_in_questions.rb +14 -0
  118. data/lib/decidim/api/question_matrix_row_type.rb +13 -0
  119. data/lib/decidim/api/question_type.rb +4 -3
  120. data/lib/decidim/api/questionnaire_type.rb +1 -0
  121. data/lib/decidim/api/response_option_type.rb +13 -0
  122. data/lib/decidim/exporters/form_pdf.rb +33 -33
  123. data/lib/decidim/forms/api.rb +2 -1
  124. data/lib/decidim/forms/{download_your_data_user_answers_serializer.rb → download_your_data_user_responses_serializer.rb} +3 -3
  125. data/lib/decidim/forms/engine.rb +2 -2
  126. data/lib/decidim/forms/test/factories.rb +24 -24
  127. data/lib/decidim/forms/test/shared_examples/has_questionnaire.rb +176 -176
  128. data/lib/decidim/forms/test/shared_examples/manage_questionnaire_responses.rb +159 -0
  129. data/lib/decidim/forms/test/shared_examples/manage_questionnaires/add_display_conditions.rb +19 -19
  130. data/lib/decidim/forms/test/shared_examples/manage_questionnaires/add_questions.rb +44 -44
  131. data/lib/decidim/forms/test/shared_examples/manage_questionnaires/update_display_conditions.rb +10 -10
  132. data/lib/decidim/forms/test/shared_examples/manage_questionnaires/update_questions.rb +18 -18
  133. data/lib/decidim/forms/test/shared_examples/manage_questionnaires.rb +4 -4
  134. data/lib/decidim/forms/test.rb +1 -1
  135. data/lib/decidim/forms/user_responses_serializer.rb +110 -0
  136. data/lib/decidim/forms/version.rb +1 -1
  137. data/lib/decidim/forms.rb +2 -2
  138. metadata +48 -45
  139. data/app/cells/decidim/forms/answer_readonly_cell.rb +0 -9
  140. data/app/helpers/decidim/forms/admin/questionnaire_answers_helper.rb +0 -30
  141. data/app/models/decidim/forms/answer_choice.rb +0 -22
  142. data/app/queries/decidim/forms/questionnaire_user_answers.rb +0 -32
  143. data/app/views/decidim/forms/admin/questionnaires/_answer_option_template.html.erb +0 -7
  144. data/app/views/decidim/forms/admin/questionnaires/answers/index.html.erb +0 -49
  145. data/app/views/decidim/forms/admin/questionnaires/answers/show.html.erb +0 -43
  146. data/app/views/decidim/forms/questionnaires/_answer.html.erb +0 -61
  147. data/app/views/decidim/forms/questionnaires/answers/_files.html.erb +0 -1
  148. data/app/views/decidim/forms/questionnaires/answers/_long_answer.html.erb +0 -3
  149. data/app/views/decidim/forms/questionnaires/answers/_multiple_option.html.erb +0 -25
  150. data/app/views/decidim/forms/questionnaires/answers/_separator.html.erb +0 -1
  151. data/app/views/decidim/forms/questionnaires/answers/_short_answer.html.erb +0 -3
  152. data/app/views/decidim/forms/questionnaires/answers/_single_option.html.erb +0 -32
  153. data/app/views/decidim/forms/questionnaires/answers/_sorting.html.erb +0 -26
  154. data/app/views/decidim/forms/questionnaires/answers/_title_and_description.html.erb +0 -1
  155. data/lib/decidim/api/answer_option_type.rb +0 -13
  156. data/lib/decidim/forms/test/shared_examples/manage_questionnaire_answers.rb +0 -149
  157. data/lib/decidim/forms/user_answers_serializer.rb +0 -105
  158. /data/app/cells/decidim/forms/{answer_readonly → response_readonly}/show.erb +0 -0
@@ -1,7 +1,7 @@
1
1
  <% add_decidim_page_title(t("decidim.forms.admin.questionnaires.edit.title")) %>
2
2
 
3
3
  <% if templates_defined? && choose_template? %>
4
- <%= render partial: "decidim/templates/admin/questionnaire_templates/choose", locals: { target: questionnaire, form_title: t("decidim.forms.admin.questionnaires.edit.title") } %>
4
+ <%= render partial: "decidim/templates/admin/questionnaire_templates/choose", locals: { target: questionnaire, form_title: t("decidim.forms.admin.questionnaires.edit.title"), show_buttons: true } %>
5
5
  <% else %>
6
6
 
7
7
  <div class="questionnaire-questions">
@@ -11,20 +11,20 @@
11
11
 
12
12
  <% unless template? questionnaire.questionnaire_for %>
13
13
  <% if questionnaire.questions_editable? %>
14
- <button class="button button__sm button__secondary add-question"><%= t(".add_question") %></button>
15
- <button class="button button__sm button__secondary add-separator"><%= t(".add_separator") %></button>
16
- <button class="button button__sm button__secondary add-title-and-description"><%= t(".add_title_and_description") %></button>
14
+ <button class="button button__sm button__transparent-secondary add-question"><%= t(".add_question") %></button>
15
+ <button class="button button__sm button__transparent-secondary add-separator"><%= t(".add_separator") %></button>
16
+ <button class="button button__sm button__transparent-secondary add-title-and-description"><%= t(".add_title_and_description") %></button>
17
17
  <% end %>
18
18
  <% if allowed_to? :preview, :questionnaire %>
19
19
  <%= link_to t("preview", scope: "decidim.forms.admin.questionnaires.form"), public_url, class: "button button__sm button__transparent-secondary", target: :_blank, data: { "external-link": false } %>
20
20
  <% end %>
21
- <% if questionnaire.answers.any? %>
22
- <%= export_dropdown(current_component, questionnaire.id) if allowed_to? :export_answers, :questionnaire %>
23
- <% if allowed_to? :show, :questionnaire_answers %>
21
+ <% if questionnaire.responses.any? %>
22
+ <%= export_dropdown(current_component, questionnaire.id) if allowed_to? :export_responses, :questionnaire %>
23
+ <% if allowed_to? :show, :questionnaire_responses %>
24
24
  <%= link_to t("actions.show", scope: "decidim.forms.admin.questionnaires"), questionnaire_participants_url, class: "button button__sm button__secondary new whitespace-nowrap" %>
25
25
  <% end %>
26
26
  <% else %>
27
- <button class="button button__sm button__secondary whitespace-nowrap" disabled><%= t("empty", scope: "decidim.forms.admin.questionnaires.answers") %></button>
27
+ <button class="button button__sm button__secondary whitespace-nowrap" disabled><%= t("empty", scope: "decidim.forms.admin.questionnaires.responses") %></button>
28
28
  <% end %>
29
29
  <% end %>
30
30
  </h1>
@@ -0,0 +1,80 @@
1
+ <div class="card" id="responses">
2
+ <div class="item_show__header">
3
+ <h1 class="item_show__header-title">
4
+ <%= t ".title", total: @total %>
5
+ <%= link_to t("actions.back", scope: "decidim.forms.admin.questionnaires"), questionnaire_url, class: "button button__sm button__secondary new" %>
6
+ </h1>
7
+ </div>
8
+ <div class="table-stacked">
9
+ <table class="table-list">
10
+ <thead>
11
+ <tr>
12
+ <th>#</th>
13
+ <th><%= first_table_th(@participants.first) %></th>
14
+ <th><%= t("user_status", scope: "decidim.forms.user_responses_serializer") %></th>
15
+ <th><%= t("ip_hash", scope: "decidim.forms.user_responses_serializer") %></th>
16
+ <th><%= t("completion", scope: "decidim.forms.user_responses_serializer") %></th>
17
+ <th><%= t("created_at", scope: "decidim.forms.user_responses_serializer") %></th>
18
+ <th></th>
19
+ </tr>
20
+ </thead>
21
+ <tbody>
22
+ <% @participants.each_with_index do |participant, idx| %>
23
+ <tr>
24
+ <td data-label="#"><%= idx + 1 + page_offset %></td>
25
+ <td data-label="<%= first_table_th(@participants.first) %>">
26
+ <% if allowed_to? :show, :questionnaire_responses %>
27
+ <%= link_to first_table_td(participant), questionnaire_participant_responses_url(participant.session_token) %>
28
+ <% else %>
29
+ <%= first_table_td(participant) %>
30
+ <% end %>
31
+ </td>
32
+ <td data-label="<%= t("user_status", scope: "decidim.forms.user_responses_serializer") %>">
33
+ <%= participant.status %>
34
+ </td>
35
+ <td data-label="<%= t("ip_hash", scope: "decidim.forms.user_responses_serializer") %>">
36
+ <%= participant.ip_hash %>
37
+ </td>
38
+ <td data-label="<%= t("completion", scope: "decidim.forms.user_responses_serializer") %>">
39
+ <%= display_percentage(participant.completion) %>
40
+ </td>
41
+ <td data-label="<%= t("created_at", scope: "decidim.forms.user_responses_serializer") %>">
42
+ <%= l participant.responded_at, format: :short %>
43
+ </td>
44
+ <td data-label="<%= t("actions.actions", scope: "decidim.admin") %>" class="table-list__actions">
45
+ <button type="button" data-controller="dropdown" data-target="actions-participant-<%= participant.id %>"
46
+ aria-label="<%= t("decidim.admin.actions.actions_label", resource: participant.session_token) %>">
47
+ <%= icon "more-fill", class: "text-secondary" %>
48
+ </button>
49
+
50
+ <div class="inline-block relative">
51
+ <ul id="actions-participant-<%= participant.id %>" class="dropdown dropdown__action" aria-hidden="true">
52
+ <% if allowed_to? :show, :questionnaire_responses %>
53
+ <li class="dropdown__item">
54
+ <%= link_to questionnaire_participant_responses_url(participant.session_token), target: "_blank", data: { "external-link": false }, class: "dropdown__button" do %>
55
+ <%= icon "eye-line" %>
56
+ <%= t("actions.show", scope: "decidim.forms.admin.questionnaires.responses") %>
57
+ <% end %>
58
+ </li>
59
+ <% end %>
60
+
61
+ <% if allowed_to? :export_response, :questionnaire_responses %>
62
+ <hr>
63
+
64
+ <li class="dropdown__item">
65
+ <%= link_to questionnaire_export_response_url(participant.session_token), class: "dropdown__button" do %>
66
+ <%= icon "download-line" %>
67
+ <%= t("actions.export", scope: "decidim.forms.admin.questionnaires.responses") %>
68
+ <% end %>
69
+ </li>
70
+ <% end %>
71
+ </ul>
72
+ </div>
73
+ </td>
74
+ </tr>
75
+ <% end %>
76
+ </tbody>
77
+ </table>
78
+ </div>
79
+ </div>
80
+ <%= decidim_paginate @query %>
@@ -0,0 +1,43 @@
1
+ <div class="card" id="responses">
2
+ <div class="item_show__header">
3
+ <h1 class="item_show__header-title">
4
+ <%= t ".title", number: current_idx %>
5
+
6
+ <%= link_to t("actions.next", scope: "decidim.forms.admin.questionnaires.responses").html_safe, next_url, rel: "next", class: "button button__sm button__secondary next" unless last? %>
7
+ <%= link_to t("actions.previous", scope: "decidim.forms.admin.questionnaires.responses").html_safe, prev_url, rel: "prev", class: "button button__sm button__secondary prev" unless first? %>
8
+ <%= link_to t("actions.export", scope: "decidim.forms.admin.questionnaires.responses"), questionnaire_export_response_url(@participant.session_token), class: "button button__sm button__secondary export" %>
9
+ <%= link_to t("actions.back", scope: "decidim.forms.admin.questionnaires.responses"), questionnaire_participants_url, class: "button button__sm button__secondary back" %>
10
+ </h1>
11
+ </div>
12
+ <div class="card-section">
13
+ <div class="table">
14
+ <table class="table-list">
15
+ <thead>
16
+ <tr>
17
+ <th><%= t("session_token", scope: "decidim.forms.user_responses_serializer") %></th>
18
+ <th><%= t("user_status", scope: "decidim.forms.user_responses_serializer") %></th>
19
+ <th><%= t("ip_hash", scope: "decidim.forms.user_responses_serializer") %></th>
20
+ <th><%= t("completion", scope: "decidim.forms.user_responses_serializer") %></th>
21
+ <th><%= t("created_at", scope: "decidim.forms.user_responses_serializer") %></th>
22
+ <th></th>
23
+ </tr>
24
+ </thead>
25
+ <tbody>
26
+ <tr>
27
+ <td><%= @participant.session_token %></td>
28
+ <td><%= @participant.status %></td>
29
+ <td><%= @participant.ip_hash %></td>
30
+ <td><%= display_percentage(@participant.completion) %></td>
31
+ <td><%= l @participant.responded_at, format: :short %></td>
32
+ </tr>
33
+ </tbody>
34
+ </table>
35
+ </div>
36
+ <dl class="p-4 [&_ul]:list-disc [&_ul]:pl-4">
37
+ <% @participant.responses.each do |response| %>
38
+ <dt class="font-semibold"><%= response.question %></dt>
39
+ <dd><%= response.body %></dd>
40
+ <% end %>
41
+ </dl>
42
+ </div>
43
+ </div>
@@ -10,60 +10,56 @@
10
10
  <%= cell("decidim/announcement", translated_attribute(questionnaire_for.announcement), callout_class: "warning") %>
11
11
  <% end %>
12
12
 
13
- <%= decidim_form_for(@form, url: update_url, method: :post, html: { multipart: true, class: "form answer-questionnaire" }, data: { "safe-path" => form_path }) do |form| %>
13
+ <%= decidim_form_for(@form, url: update_url, method: :post, html: { multipart: true, class: "form response-questionnaire" }, data: { "safe-path" => form_path }) do |form| %>
14
14
  <%= form_required_explanation %>
15
15
 
16
- <%= form.hidden_field :allow_editing_answers %>
16
+ <%= form.hidden_field :allow_editing_responses %>
17
17
 
18
18
  <%= invisible_captcha %>
19
- <% answer_idx = 0 %>
20
- <% cleaned_answer_idx = 1 %>
21
- <% @form.responses_by_step.each_with_index do |step_answers, step_index| %>
22
- <div id="step-<%= step_index %>" class="answer-questionnaire__step" <%= "hidden" if !step_index.zero? %>>
19
+ <% response_idx = 0 %>
20
+ <% cleaned_response_idx = 1 %>
21
+ <% @form.responses_by_step.each_with_index do |step_responses, step_index| %>
22
+ <div id="step-<%= step_index %>" class="response-questionnaire__step" <%= "hidden" if !step_index.zero? %>>
23
23
 
24
24
  <% if @form.total_steps > 1 %>
25
- <p class="answer-questionnaire__step-counter">
25
+ <p class="response-questionnaire__step-counter">
26
26
  <%= t("decidim.forms.questionnaires.show.current_step", step: step_index + 1) %>&nbsp;<%= t("decidim.forms.questionnaires.show.of_total_steps", total_steps: @form.total_steps) %></span>
27
27
  </p>
28
28
  <% end %>
29
29
 
30
- <% step_answers.each do |answer| %>
31
- <div class="answer question" data-max-choices="<%= answer.question.max_choices %>" data-conditioned="<%= answer.question.display_conditions.any? %>" data-question-id="<%= answer.question.id %>">
32
- <% answer.question.display_conditions.each do |display_condition| %>
30
+ <% step_responses.each do |response| %>
31
+ <div class="response question" data-max-choices="<%= response.question.max_choices %>" data-conditioned="<%= response.question.display_conditions.any? %>" data-question-id="<%= response.question.id %>">
32
+ <% response.question.display_conditions.each do |display_condition| %>
33
33
  <%= content_tag :div, nil, class: "display-condition", data: display_condition.to_html_data %>
34
34
  <% end %>
35
35
 
36
- <%= fields_for "questionnaire[responses][#{answer_idx}]", answer do |answer_form| %>
36
+ <%= fields_for "questionnaire[responses][#{response_idx}]", response do |response_form| %>
37
37
  <%= render(
38
- "decidim/forms/questionnaires/answer",
39
- answer_form:,
40
- answer:,
41
- answer_idx:,
42
- cleaned_answer_idx:,
38
+ "decidim/forms/questionnaires/response",
39
+ response_form:,
40
+ response:,
41
+ response_idx:,
42
+ cleaned_response_idx:,
43
43
  disabled: !current_participatory_space.can_participate?(current_user)
44
44
  ) %>
45
45
  <% end %>
46
46
  </div>
47
47
 
48
- <% if !(answer.question.separator? || answer.question.title_and_description?) %>
49
- <% cleaned_answer_idx += 1 %>
48
+ <% if !(response.question.separator? || response.question.title_and_description?) %>
49
+ <% cleaned_response_idx += 1 %>
50
50
  <% end %>
51
51
 
52
- <% answer_idx += 1 %>
52
+ <% response_idx += 1 %>
53
53
 
54
54
  <% end %>
55
55
 
56
- <div class="answer-questionnaire__footer">
56
+ <div class="response-questionnaire__footer">
57
57
  <% if step_index + 1 == @form.total_steps %>
58
- <% if show_represent_user_group? %>
59
- <%= cell("decidim/represent_user_group", form) %>
60
- <% end %>
61
-
62
58
  <% if show_public_participation? %>
63
59
  <%= cell("decidim/public_participation", form) %>
64
60
  <% end %>
65
61
 
66
- <div class="answer-questionnaire__tos">
62
+ <div class="response-questionnaire__tos">
67
63
  <%= form.check_box :tos_agreement, label: t("decidim.forms.questionnaires.show.tos_agreement"), id: "questionnaire_tos_agreement", disabled: !current_participatory_space.can_participate?(current_user) %>
68
64
  <div>
69
65
  <%= decidim_sanitize_editor translated_attribute questionnaire.tos %>
@@ -77,7 +73,7 @@
77
73
  total_steps: @form.total_steps,
78
74
  button_disabled: !current_participatory_space.can_participate?(current_user),
79
75
  form:,
80
- allow_editing_answers: questionnaire_for.try(:allow_editing_answers?)
76
+ allow_editing_responses: questionnaire_for.try(:allow_editing_responses?)
81
77
  ) %>
82
78
  </div>
83
79
  </div>
@@ -1,7 +1,12 @@
1
- <%= render partial: "decidim/devise/shared/login_boxes", locals: { scope: "decidim.forms.questionnaires.show.answer_questionnaire" } %>
1
+ <%# i18n-tasks-use t("decidim.forms.questionnaires.show.response_questionnaire.already_have_an_account?") %>
2
+ <%# i18n-tasks-use t("decidim.forms.questionnaires.show.response_questionnaire.are_you_new?") %>
3
+ <%# i18n-tasks-use t("decidim.forms.questionnaires.show.response_questionnaire.sign_in_description") %>
4
+ <%# i18n-tasks-use t("decidim.forms.questionnaires.show.response_questionnaire.sign_up_description") %>
5
+ <%# i18n-tasks-use t("decidim.forms.questionnaires.show.response_questionnaire.title") %>
6
+ <%= render partial: "decidim/devise/shared/login_boxes", locals: { scope: "decidim.forms.questionnaires.show.response_questionnaire" } %>
2
7
 
3
- <div class="answer-questionnaire mt-12">
4
- <ol class="answer-questionnaire__step">
8
+ <div class="response-questionnaire mt-12">
9
+ <ol class="response-questionnaire__step">
5
10
  <%= cell(
6
11
  "decidim/forms/question_readonly",
7
12
  collection: @questionnaire.questions.not_conditioned.not_separator,
@@ -0,0 +1,61 @@
1
+ <% field_id = "questionnaire_responses_#{response_idx}" %>
2
+
3
+ <% if response.question.separator? %>
4
+
5
+ <%= render partial: "decidim/forms/questionnaires/responses/#{response.question.question_type}", locals: { response:, response_form:, response_idx:, field_id:, disabled: } %>
6
+ <%= response_form.hidden_field :question_id %>
7
+
8
+ <% elsif response.question.title_and_description? %>
9
+
10
+ <div class="response-questionnaire__step-heading">
11
+ <h3 class="h3"><%= translated_attribute(response.question.body) %></h3>
12
+ <% if translated_attribute(response.question.description).present? %>
13
+ <div>
14
+ <%= decidim_sanitize_editor_admin translated_attribute(response.question.description) %>
15
+ </div>
16
+ <% end %>
17
+ </div>
18
+
19
+ <%= render partial: "decidim/forms/questionnaires/responses/#{response.question.question_type}", locals: { response:, response_form:, response_idx:, field_id:, disabled: } %>
20
+ <%= response_form.hidden_field :question_id %>
21
+
22
+ <% else %>
23
+
24
+ <div class="response-questionnaire__question">
25
+ <%
26
+ label_options = {
27
+ class: "response-questionnaire__question-label questionnaire-question",
28
+ data: { "response-idx": cleaned_response_idx }
29
+ }
30
+ label_options[:for] = nil if %w(matrix_single matrix_multiple single_option multiple_option).include?(response.question.question_type)
31
+ %>
32
+
33
+ <%= label_tag field_id, **label_options do %>
34
+ <%= translated_attribute(response.question.body) %>
35
+ <% if response.question.mandatory? %>
36
+ <%= response_form.send(:required_indicator) %>
37
+ <% end %>
38
+ <% if response.question.max_choices %>
39
+ <%= " (#{response.send(:max_choices_label)})" %>
40
+ <% end %>
41
+ <% end %>
42
+
43
+ <% if translated_attribute(response.question.description).present? %>
44
+ <div class="response-questionnaire__question-description">
45
+ <%= decidim_sanitize_editor_admin translated_attribute(response.question.description) %>
46
+ </div>
47
+ <% end %>
48
+
49
+ <% if response.question.max_choices %>
50
+ <small class="form-error max-choices-alert"><%= t(".max_choices_alert") %></small>
51
+ <% end %>
52
+
53
+ <% %w(short_answer long_answer).exclude?(response&.question&.question_type) && response.errors.full_messages.each do |msg| %>
54
+ <small class="form-error is-visible"><%= msg %></small>
55
+ <% end %>
56
+
57
+ <%= render partial: "decidim/forms/questionnaires/responses/#{response.question.question_type}", locals: { response:, response_form:, response_idx:, field_id:, disabled:, maxlength: (response.question.max_characters if response.question.max_characters.positive?) } %>
58
+ <%= response_form.hidden_field :question_id %>
59
+ </div>
60
+
61
+ <% end %>
@@ -29,8 +29,8 @@
29
29
  <% end %>
30
30
 
31
31
  <section>
32
- <% if allow_answers? %>
33
- <% if visitor_can_answer? %>
32
+ <% if allow_responses? %>
33
+ <% if visitor_can_respond? %>
34
34
  <% if @form.responses_by_step.flatten.empty? %>
35
35
  <%= cell("decidim/announcement", t("decidim.forms.questionnaires.show.empty")) %>
36
36
  <% else %>
@@ -0,0 +1 @@
1
+ <%= response_form.upload :add_documents, attachments: response.documents, label: false, multiple: true, id: field_id, disabled:, button_class: "button button__lg button__transparent-secondary w-full" %>
@@ -0,0 +1,3 @@
1
+ <div>
2
+ <%= response_form.text_area :body, label: false, id: field_id, rows: 10, disabled:, maxlength:, class: "w-full", required: false, data: { controller: "character-counter" } %>
3
+ </div>
@@ -1,40 +1,41 @@
1
- <div class="answer-questionnaire__multiple-matrix">
1
+ <div class="response-questionnaire__multiple-matrix">
2
2
  <table>
3
3
  <thead>
4
4
  <tr>
5
5
  <td></td>
6
- <% answer.question.answer_options.each_with_index do |answer_option, idx| %>
7
- <th><%= translated_attribute(answer_option.body) %></th>
6
+ <% response.question.response_options.each_with_index do |response_option, idx| %>
7
+ <th><%= translated_attribute(response_option.body) %></th>
8
8
  <% end %>
9
9
  </tr>
10
10
  </thead>
11
11
  <tbody>
12
- <% answer.question.matrix_rows.by_position.each_with_index do |row, row_idx| %>
12
+ <% response.question.matrix_rows.by_position.each_with_index do |row, row_idx| %>
13
13
  <tr class="js-check-box-collection">
14
14
  <td><%= translated_attribute row.body %></td>
15
- <% answer.question.answer_options.each_with_index do |answer_option, idx| %>
16
- <% choice = answer.selected_choices.find { |choice| choice.answer_option_id == answer_option.id && choice.matrix_row_id == row.id } %>
15
+ <% response.question.response_options.each_with_index do |response_option, idx| %>
16
+ <% choice = response.selected_choices.find { |choice| choice.response_option_id == response_option.id && choice.matrix_row_id == row.id } %>
17
17
  <% choice_id = "#{field_id}_matrix_row_#{row_idx}_choice_#{idx}" %>
18
18
  <td>
19
19
  <div class="js-collection-input">
20
- <%= check_box_tag "questionnaire[responses][#{answer_idx}][choices][][body]",
21
- translated_attribute(answer_option.body),
20
+ <%= check_box_tag "questionnaire[responses][#{response_idx}][choices][][body]",
21
+ translated_attribute(response_option.body),
22
22
  choice.present?,
23
- "aria-label": translated_attribute(answer_option.body),
23
+ "aria-label": translated_attribute(response_option.body),
24
24
  id: "#{choice_id}_body", disabled: %>
25
- <%= hidden_field_tag "questionnaire[responses][#{answer_idx}][choices][][answer_option_id]",
26
- answer_option.id,
27
- id: "#{choice_id}_answer_option",
25
+ <%= hidden_field_tag "questionnaire[responses][#{response_idx}][choices][][response_option_id]",
26
+ response_option.id,
27
+ id: "#{choice_id}_response_option",
28
28
  disabled: true %>
29
- <%= hidden_field_tag "questionnaire[responses][#{answer_idx}][choices][][matrix_row_id]",
29
+ <%= hidden_field_tag "questionnaire[responses][#{response_idx}][choices][][matrix_row_id]",
30
30
  row.id,
31
31
  id: "#{choice_id}_matrix_row",
32
32
  disabled: true %>
33
- <% if answer_option.free_text %>
34
- <%= text_field_tag "questionnaire[responses][#{answer_idx}][choices][][custom_body]",
33
+ <% if response_option.free_text %>
34
+ <%= text_field_tag "questionnaire[responses][#{response_idx}][choices][][custom_body]",
35
35
  choice.try(:custom_body),
36
36
  id: "#{choice_id}_custom_body",
37
37
  disabled: true,
38
+ data: { controller: "character-counter" },
38
39
  maxlength: %>
39
40
  <% end %>
40
41
  </div>
@@ -1,40 +1,41 @@
1
- <div class="answer-questionnaire__single-matrix">
1
+ <div class="response-questionnaire__single-matrix">
2
2
  <table>
3
3
  <thead>
4
4
  <tr>
5
5
  <td></td>
6
- <% answer.question.answer_options.each_with_index do |answer_option, idx| %>
7
- <th><%= translated_attribute(answer_option.body) %></th>
6
+ <% response.question.response_options.each_with_index do |response_option, idx| %>
7
+ <th><%= translated_attribute(response_option.body) %></th>
8
8
  <% end %>
9
9
  </tr>
10
10
  </thead>
11
11
  <tbody>
12
- <% answer.question.matrix_rows.by_position.each_with_index do |row, row_idx| %>
12
+ <% response.question.matrix_rows.by_position.each_with_index do |row, row_idx| %>
13
13
  <tr class="js-radio-button-collection">
14
14
  <td><%= translated_attribute row.body %></td>
15
- <% answer.question.answer_options.each_with_index do |answer_option, idx| %>
16
- <% choice = answer.choices.find { |choice| choice.answer_option_id == answer_option.id && choice.matrix_row_id == row.id } %>
15
+ <% response.question.response_options.each_with_index do |response_option, idx| %>
16
+ <% choice = response.choices.find { |choice| choice.response_option_id == response_option.id && choice.matrix_row_id == row.id } %>
17
17
  <% choice_id = "#{field_id}_matrix_row_#{row_idx}_choice_#{idx}" %>
18
18
  <td>
19
19
  <div class="js-collection-input">
20
- <%= radio_button_tag "questionnaire[responses][#{answer_idx}][choices][#{row_idx}][body]",
21
- translated_attribute(answer_option.body),
22
- answer_option.id == choice.try(:answer_option_id),
23
- "aria-label": translated_attribute(answer_option.body),
20
+ <%= radio_button_tag "questionnaire[responses][#{response_idx}][choices][#{row_idx}][body]",
21
+ translated_attribute(response_option.body),
22
+ response_option.id == choice.try(:response_option_id),
23
+ "aria-label": translated_attribute(response_option.body),
24
24
  id: "#{choice_id}_body", disabled: %>
25
- <%= hidden_field_tag "questionnaire[responses][#{answer_idx}][choices][#{row_idx}][answer_option_id]",
26
- answer_option.id,
27
- id: "#{choice_id}_answer_option",
25
+ <%= hidden_field_tag "questionnaire[responses][#{response_idx}][choices][#{row_idx}][response_option_id]",
26
+ response_option.id,
27
+ id: "#{choice_id}_response_option",
28
28
  disabled: true %>
29
- <%= hidden_field_tag "questionnaire[responses][#{answer_idx}][choices][#{row_idx}][matrix_row_id]",
29
+ <%= hidden_field_tag "questionnaire[responses][#{response_idx}][choices][#{row_idx}][matrix_row_id]",
30
30
  row.id,
31
31
  id: "#{choice_id}_matrix_row",
32
32
  disabled: true %>
33
- <% if answer_option.free_text %>
34
- <%= text_field_tag "questionnaire[responses][#{answer_idx}][choices][#{row_idx}][custom_body]",
33
+ <% if response_option.free_text %>
34
+ <%= text_field_tag "questionnaire[responses][#{response_idx}][choices][#{row_idx}][custom_body]",
35
35
  choice.try(:custom_body),
36
36
  id: "#{choice_id}_custom_body",
37
37
  disabled: true,
38
+ data: { controller: "character-counter" },
38
39
  maxlength: %>
39
40
  <% end %>
40
41
  </div>
@@ -0,0 +1,26 @@
1
+ <div class="response-questionnaire__single-option js-check-box-collection">
2
+ <% response.question.response_options.each_with_index do |response_option, idx| %>
3
+ <% choice = response.selected_choices.find { |choice| choice.response_option_id == response_option.id } %>
4
+
5
+ <div class="js-collection-input">
6
+ <%= label_tag do %>
7
+ <%= check_box_tag "questionnaire[responses][#{response_idx}][choices][#{idx}][body]",
8
+ translated_attribute(response_option.body),
9
+ choice.present?, disabled: %>
10
+
11
+ <%= translated_attribute(response_option.body) %>
12
+
13
+ <%= hidden_field_tag "questionnaire[responses][#{response_idx}][choices][#{idx}][response_option_id]", response_option.id %>
14
+ <% end %>
15
+
16
+ <% if response_option.free_text %>
17
+ <%= text_field_tag "questionnaire[responses][#{response_idx}][choices][#{idx}][custom_body]",
18
+ choice.try(:custom_body),
19
+ disabled: true,
20
+ data: { controller: "character-counter" },
21
+ maxlength:,
22
+ class: "w-full" %>
23
+ <% end %>
24
+ </div>
25
+ <% end %>
26
+ </div>
@@ -0,0 +1 @@
1
+ <%= response_form.hidden_field :body, value: "separator", id: field_id, disabled: %>
@@ -0,0 +1,3 @@
1
+ <div>
2
+ <%= response_form.text_field :body, label: false, id: field_id, disabled:, maxlength:, class: "w-full", required: false, data: { controller: "character-counter" } %>
3
+ </div>
@@ -0,0 +1,33 @@
1
+ <div class="response-questionnaire__single-option js-radio-button-collection">
2
+ <% choice = response.choices.first %>
3
+
4
+ <% response.question.response_options.each_with_index do |response_option, idx| %>
5
+ <% choice_id = "#{field_id}_choices_#{idx}" %>
6
+
7
+ <div class="js-collection-input">
8
+ <%= label_tag "#{choice_id}_body" do %>
9
+ <%= radio_button_tag "questionnaire[responses][#{response_idx}][choices][][body]",
10
+ translated_attribute(response_option.body),
11
+ response_option.id == choice.try(:response_option_id),
12
+ id: "#{choice_id}_body", disabled: %>
13
+
14
+ <%= translated_attribute(response_option.body) %>
15
+
16
+ <%= hidden_field_tag "questionnaire[responses][#{response_idx}][choices][][response_option_id]",
17
+ response_option.id,
18
+ id: "#{choice_id}_response_option",
19
+ disabled: true %>
20
+ <% end %>
21
+
22
+ <% if response_option.free_text %>
23
+ <%= text_field_tag "questionnaire[responses][#{response_idx}][choices][][custom_body]",
24
+ choice.try(:custom_body),
25
+ id: "#{choice_id}_custom_body",
26
+ disabled: true,
27
+ maxlength:,
28
+ data: { controller: "character-counter" },
29
+ class: "w-full" %>
30
+ <% end %>
31
+ </div>
32
+ <% end %>
33
+ </div>
@@ -0,0 +1,26 @@
1
+ <div class="response-questionnaire__sorting-container js-sortable-check-box-collection">
2
+ <%
3
+ # This is a block that aims to identify the order to the response questions, and if there is an user response, use that
4
+ # to order the date that needs to be displayed. It is done like this to help with edit user response form
5
+ %>
6
+ <% ordering = response.question.response_options.pluck(:id) %>
7
+ <% if response.selected_choices.present? %>
8
+ <% ordering = response.selected_choices.map(&:response_option_id) %>
9
+ <% end %>
10
+
11
+ <% ids_for_order = ordering.map.with_index { |id, index| "#{id}=#{index + 1}" }.join(", ") %>
12
+
13
+ <% response.question.reload.response_options.reorder(Arel.sql("POSITION(id::text in '#{ids_for_order}')")).each_with_index do |response_option, idx| %>
14
+ <% choice = response.selected_choices.find { |choice| choice.response_option_id == response_option.id } %>
15
+
16
+ <div class="response-questionnaire__sorting js-collection-input" role="button">
17
+ <%= translated_attribute(response_option.body) %>
18
+
19
+ <%= icon "drag-move-2-line" %>
20
+
21
+ <%= hidden_field_tag "questionnaire[responses][#{response_idx}][choices][#{idx}][position]", choice.try(:position) %>
22
+ <%= hidden_field_tag "questionnaire[responses][#{response_idx}][choices][#{idx}][body]", translated_attribute(response_option.body) %>
23
+ <%= hidden_field_tag "questionnaire[responses][#{response_idx}][choices][#{idx}][response_option_id]", response_option.id %>
24
+ </div>
25
+ <% end %>
26
+ </div>
@@ -0,0 +1 @@
1
+ <%= response_form.hidden_field :body, value: "title-and-description", id: field_id, disabled: %>
@@ -29,17 +29,17 @@
29
29
  <% end %>
30
30
 
31
31
  <section>
32
- <% if allow_answers? %>
33
- <% if visitor_can_answer? %>
34
- <% if visitor_already_answered? %>
35
- <% if visitor_can_edit_answers? && current_component.manifest_name == "surveys" %>
36
- <% body = t("decidim.forms.questionnaires.show.questionnaire_answered_edit.body",
37
- link: link_to(t("decidim.forms.questionnaires.show.questionnaire_answered_edit.edit"), edit_survey_path(questionnaire_for))
32
+ <% if allow_responses? %>
33
+ <% if visitor_can_respond? %>
34
+ <% if visitor_already_responded? %>
35
+ <% if visitor_can_edit_responses? && current_component.manifest_name == "surveys" %>
36
+ <% body = t("decidim.forms.questionnaires.show.questionnaire_responded_edit.body",
37
+ link: link_to(t("decidim.forms.questionnaires.show.questionnaire_responded_edit.edit"), edit_survey_path(questionnaire_for))
38
38
  ) %>
39
39
  <% else %>
40
- <% body = t("decidim.forms.questionnaires.show.questionnaire_answered.body") %>
40
+ <% body = t("decidim.forms.questionnaires.show.questionnaire_responded.body") %>
41
41
  <% end %>
42
- <%= cell("decidim/announcement", { title: t("decidim.forms.questionnaires.show.questionnaire_answered.title"), body: body }) %>
42
+ <%= cell("decidim/announcement", { title: t("decidim.forms.questionnaires.show.questionnaire_responded.title"), body: body }) %>
43
43
  <% else %>
44
44
  <% if @form.responses_by_step.flatten.empty? %>
45
45
  <%= cell("decidim/announcement", t("decidim.forms.questionnaires.show.empty")) %>
@@ -51,8 +51,8 @@
51
51
  <%= render partial: "decidim/forms/questionnaires/questionnaire_readonly" %>
52
52
  <% end %>
53
53
  <% else %>
54
- <% if questionnaire_for.class.name == "Decidim::Surveys::Survey" && show_published_questions_answers? %>
55
- <%= render partial: "decidim/surveys/surveys/published_questions_answers" %>
54
+ <% if questionnaire_for.class.name == "Decidim::Surveys::Survey" && show_published_questions_responses? %>
55
+ <%= render partial: "decidim/surveys/surveys/published_questions_responses" %>
56
56
  <% else %>
57
57
  <%= cell("decidim/announcement", { title: t("decidim.forms.questionnaires.show.questionnaire_closed.title"), body: t("decidim.forms.questionnaires.show.questionnaire_closed.body") }, callout_class: "warning") %>
58
58
  <% end %>
data/config/assets.rb CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  base_path = File.expand_path("..", __dir__)
4
4
 
5
- Decidim::Webpacker.register_path("#{base_path}/app/packs")
6
- Decidim::Webpacker.register_entrypoints(
5
+ Decidim::Shakapacker.register_path("#{base_path}/app/packs")
6
+ Decidim::Shakapacker.register_entrypoints(
7
7
  decidim_forms: "#{base_path}/app/packs/entrypoints/decidim_forms.js",
8
8
  decidim_forms_admin: "#{base_path}/app/packs/entrypoints/decidim_forms_admin.js"
9
9
  )