-
Notifications
You must be signed in to change notification settings - Fork 2
/
show.html.erb
154 lines (140 loc) · 7.19 KB
/
show.html.erb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<% 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 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").html_safe %></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>
<%= javascript_pack_tag "decidim_forms" %>