decidim-surveys 0.10.1 → 0.11.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/app/assets/config/decidim_surveys_manifest.js +1 -0
- data/app/assets/javascripts/decidim/surveys/admin/auto_buttons_by_min_items.component.js.es6 +25 -0
- data/app/assets/javascripts/decidim/surveys/admin/auto_select_options_by_total_items.component.js.es6 +23 -0
- data/app/assets/javascripts/decidim/surveys/admin/surveys.js.es6 +146 -43
- data/app/assets/javascripts/decidim/surveys/autosortable_checkboxes.component.js.es6 +65 -0
- data/app/assets/javascripts/decidim/surveys/option_attached_inputs.component.js.es6 +32 -0
- data/app/assets/javascripts/decidim/surveys/surveys.js.es6 +20 -0
- data/app/assets/stylesheets/decidim/surveys/surveys.scss +20 -3
- data/app/commands/decidim/surveys/admin/update_survey.rb +36 -15
- data/app/commands/decidim/surveys/answer_survey.rb +12 -1
- data/app/commands/decidim/surveys/create_survey.rb +5 -5
- data/app/controllers/decidim/surveys/admin/application_controller.rb +2 -2
- data/app/controllers/decidim/surveys/admin/surveys_controller.rb +3 -3
- data/app/controllers/decidim/surveys/application_controller.rb +2 -2
- data/app/controllers/decidim/surveys/surveys_controller.rb +1 -1
- data/app/forms/decidim/surveys/admin/survey_answer_option_form.rb +23 -0
- data/app/forms/decidim/surveys/admin/survey_form.rb +7 -1
- data/app/forms/decidim/surveys/admin/survey_question_form.rb +12 -2
- data/app/forms/decidim/surveys/survey_answer_choice_form.rb +15 -0
- data/app/forms/decidim/surveys/survey_answer_form.rb +40 -6
- data/app/forms/decidim/surveys/survey_form.rb +1 -1
- data/app/helpers/decidim/surveys/admin/application_helper.rb +3 -19
- data/app/jobs/decidim/surveys/settings_change_job.rb +4 -4
- data/app/models/decidim/surveys/abilities/current_user_ability.rb +8 -8
- data/app/models/decidim/surveys/abilities/participatory_process_admin_ability.rb +1 -1
- data/app/models/decidim/surveys/survey.rb +2 -2
- data/app/models/decidim/surveys/survey_answer.rb +9 -1
- data/app/models/decidim/surveys/survey_answer_choice.rb +15 -0
- data/app/models/decidim/surveys/survey_answer_option.rb +9 -0
- data/app/models/decidim/surveys/survey_question.rb +21 -5
- data/app/views/decidim/surveys/admin/surveys/_answer_option.html.erb +28 -11
- data/app/views/decidim/surveys/admin/surveys/_form.html.erb +18 -14
- data/app/views/decidim/surveys/admin/surveys/_question.html.erb +74 -31
- data/app/views/decidim/surveys/admin/surveys/edit.html.erb +1 -1
- data/app/views/decidim/surveys/surveys/_answer.html.erb +94 -0
- data/app/views/decidim/surveys/surveys/show.html.erb +15 -42
- data/config/locales/ca.yml +33 -13
- data/config/locales/en.yml +33 -13
- data/config/locales/es.yml +33 -13
- data/config/locales/eu.yml +33 -13
- data/config/locales/fi.yml +33 -13
- data/config/locales/fr.yml +33 -13
- data/config/locales/gl.yml +33 -13
- data/config/locales/it.yml +33 -13
- data/config/locales/nl.yml +36 -16
- data/config/locales/pl.yml +33 -13
- data/config/locales/pt-BR.yml +33 -13
- data/config/locales/pt.yml +33 -13
- data/config/locales/ru.yml +0 -6
- data/config/locales/sv.yml +33 -13
- data/config/locales/uk.yml +0 -6
- data/db/migrate/20180305133837_rename_features_to_components_at_surveys.rb +11 -0
- data/db/migrate/20180314225829_add_max_choices_to_survey_questions.rb +7 -0
- data/db/migrate/20180321141024_add_description_to_decidim_survey_questions.rb +7 -0
- data/db/migrate/20180405014929_add_choices_to_decidim_survey_answers.rb +48 -0
- data/db/migrate/20180405015012_create_decidim_survey_answer_options.rb +43 -0
- data/db/migrate/20180405015147_create_decidim_survey_answer_choices.rb +61 -0
- data/db/migrate/20180405015258_add_free_text_to_survey_answer_options.rb +7 -0
- data/db/migrate/20180405015314_add_custom_body_to_survey_answer_choices.rb +7 -0
- data/db/migrate/20180406201818_add_position_to_decidim_survey_answer_choices.rb +7 -0
- data/lib/decidim/surveys.rb +1 -1
- data/lib/decidim/surveys/admin_engine.rb +0 -2
- data/lib/decidim/surveys/{feature.rb → component.rb} +38 -26
- data/lib/decidim/surveys/engine.rb +5 -1
- data/lib/decidim/surveys/test/factories.rb +22 -6
- data/lib/decidim/surveys/version.rb +1 -1
- metadata +33 -30
- data/app/assets/javascripts/decidim/surveys/admin/auto_label_by_position.component.js.es6 +0 -33
- data/app/assets/javascripts/decidim/surveys/admin/dynamic_fields.component.js.es6 +0 -95
- data/app/forms/decidim/surveys/admin/survey_question_answer_option_form.rb +0 -15
@@ -8,7 +8,15 @@ module Decidim
|
|
8
8
|
belongs_to :survey, class_name: "Survey", foreign_key: "decidim_survey_id"
|
9
9
|
belongs_to :question, class_name: "SurveyQuestion", foreign_key: "decidim_survey_question_id"
|
10
10
|
|
11
|
-
|
11
|
+
has_many :choices,
|
12
|
+
class_name: "SurveyAnswerChoice",
|
13
|
+
foreign_key: "decidim_survey_answer_id",
|
14
|
+
dependent: :destroy,
|
15
|
+
inverse_of: :answer
|
16
|
+
|
17
|
+
validates :body, presence: true, if: -> { question.mandatory_body? }
|
18
|
+
validates :choices, presence: true, if: -> { question.mandatory_choices? }
|
19
|
+
|
12
20
|
validate :user_survey_same_organization
|
13
21
|
validate :question_belongs_to_survey
|
14
22
|
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Surveys
|
5
|
+
class SurveyAnswerChoice < Surveys::ApplicationRecord
|
6
|
+
belongs_to :answer,
|
7
|
+
class_name: "SurveyAnswer",
|
8
|
+
foreign_key: "decidim_survey_answer_id"
|
9
|
+
|
10
|
+
belongs_to :answer_option,
|
11
|
+
class_name: "SurveyAnswerOption",
|
12
|
+
foreign_key: "decidim_survey_answer_option_id"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -4,16 +4,32 @@ module Decidim
|
|
4
4
|
module Surveys
|
5
5
|
# The data store for a SurveyQuestion in the Decidim::Surveys component.
|
6
6
|
class SurveyQuestion < Surveys::ApplicationRecord
|
7
|
-
TYPES = %w(short_answer long_answer single_option multiple_option).freeze
|
7
|
+
TYPES = %w(short_answer long_answer single_option multiple_option sorting).freeze
|
8
8
|
|
9
9
|
belongs_to :survey, class_name: "Survey", foreign_key: "decidim_survey_id"
|
10
10
|
|
11
|
+
has_many :answer_options,
|
12
|
+
class_name: "SurveyAnswerOption",
|
13
|
+
foreign_key: "decidim_survey_question_id",
|
14
|
+
dependent: :destroy,
|
15
|
+
inverse_of: :question
|
16
|
+
|
11
17
|
validates :question_type, inclusion: { in: TYPES }
|
12
18
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
19
|
+
def multiple_choice?
|
20
|
+
%w(single_option multiple_option sorting).include?(question_type)
|
21
|
+
end
|
22
|
+
|
23
|
+
def mandatory_body?
|
24
|
+
mandatory? && !multiple_choice?
|
25
|
+
end
|
26
|
+
|
27
|
+
def mandatory_choices?
|
28
|
+
mandatory? && multiple_choice?
|
29
|
+
end
|
30
|
+
|
31
|
+
def number_of_options
|
32
|
+
answer_options.size
|
17
33
|
end
|
18
34
|
end
|
19
35
|
end
|
@@ -1,9 +1,13 @@
|
|
1
|
+
<% answer_option = form.object %>
|
2
|
+
|
1
3
|
<div class="card survey-question-answer-option">
|
2
4
|
<div class="card-divider">
|
3
5
|
<h2 class="card-title">
|
4
6
|
<span><%= t(".answer_option") %></span>
|
5
|
-
<% if
|
6
|
-
<button class="button small alert hollow remove-answer-option button--title"
|
7
|
+
<% if editable %>
|
8
|
+
<button class="button small alert hollow remove-answer-option button--title">
|
9
|
+
<%= t(".remove") %>
|
10
|
+
</button>
|
7
11
|
<% end %>
|
8
12
|
</h2>
|
9
13
|
</div>
|
@@ -11,17 +15,30 @@
|
|
11
15
|
<div class="card-section">
|
12
16
|
<div class="row column">
|
13
17
|
<%=
|
14
|
-
|
15
|
-
:
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
form.translated(
|
19
|
+
:text_field,
|
20
|
+
:body,
|
21
|
+
tabs_id: tabs_id_for_question_answer_option(question, answer_option),
|
22
|
+
label: t(".statement"),
|
23
|
+
disabled: !editable
|
24
|
+
)
|
25
|
+
%>
|
26
|
+
</div>
|
27
|
+
|
28
|
+
<div class="row column">
|
29
|
+
<%=
|
30
|
+
form.check_box(
|
31
|
+
:free_text,
|
32
|
+
label: t(".free_text"),
|
33
|
+
disabled: !survey.questions_editable?
|
23
34
|
)
|
24
35
|
%>
|
25
36
|
</div>
|
26
37
|
</div>
|
38
|
+
|
39
|
+
<% if answer_option.persisted? %>
|
40
|
+
<%= form.hidden_field :id, disabled: !editable %>
|
41
|
+
<% end %>
|
42
|
+
|
43
|
+
<%= form.hidden_field :deleted, disabled: !editable %>
|
27
44
|
</div>
|
@@ -12,36 +12,40 @@
|
|
12
12
|
<%= form.translated :text_field, :title, autofocus: true %>
|
13
13
|
</div>
|
14
14
|
<div class="row column">
|
15
|
-
<%= form.translated :editor, :description, toolbar: :full, lines: 30, label: t("models.components.description", scope: "decidim.surveys.admin")
|
15
|
+
<%= form.translated :editor, :description, toolbar: :full, lines: 30, label: t("models.components.description", scope: "decidim.surveys.admin") %>
|
16
16
|
</div>
|
17
17
|
<div class="row column">
|
18
|
-
<%= form.translated :editor, :tos, toolbar: :full, lines: 10, label: t("models.components.tos", scope: "decidim.surveys.admin")
|
18
|
+
<%= form.translated :editor, :tos, toolbar: :full, lines: 10, label: t("models.components.tos", scope: "decidim.surveys.admin") %>
|
19
19
|
</div>
|
20
20
|
</div>
|
21
21
|
</div>
|
22
22
|
|
23
23
|
<div class="survey-questions">
|
24
24
|
<% if survey.questions_editable? %>
|
25
|
-
<
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
</template>
|
30
|
-
|
31
|
-
<template id="survey-question-answer-option-tmpl">
|
32
|
-
<%= render "answer_option", answer_option: blank_answer_option, question: nil, idx: nil %>
|
25
|
+
<template>
|
26
|
+
<%= fields_for "survey[questions][#{blank_question.to_param}]", blank_question do |question_form| %>
|
27
|
+
<%= render "question", form: question_form, id: tabs_id_for_question(blank_question), editable: survey.questions_editable? %>
|
28
|
+
<% end %>
|
33
29
|
</template>
|
34
30
|
<% else %>
|
35
31
|
<div class="callout warning">
|
36
|
-
<%= t(
|
32
|
+
<%= t(".already_answered_warning") %>
|
37
33
|
</div>
|
38
34
|
<% end %>
|
39
35
|
|
40
36
|
<div class="survey-questions-list">
|
41
|
-
<% @form.questions.
|
42
|
-
<%=
|
37
|
+
<% @form.questions.each do |question| %>
|
38
|
+
<%= fields_for "survey[questions][]", question do |question_form| %>
|
39
|
+
<%= render "question", form: question_form, id: tabs_id_for_question(question), editable: survey.questions_editable? %>
|
40
|
+
<% end %>
|
43
41
|
<% end %>
|
44
42
|
</div>
|
43
|
+
|
44
|
+
<% if survey.questions_editable? %>
|
45
|
+
<button class="button add-question"><%= t(".add_question") %></button>
|
46
|
+
<% end %>
|
45
47
|
</div>
|
46
48
|
|
47
|
-
|
49
|
+
<% if survey.questions_editable? %>
|
50
|
+
<%= javascript_include_tag "decidim/surveys/admin/surveys" %>
|
51
|
+
<% end %>
|
@@ -1,16 +1,28 @@
|
|
1
|
-
|
1
|
+
<% question = form.object %>
|
2
|
+
|
3
|
+
<div class="card survey-question" id="<%= id %>-field">
|
2
4
|
<div class="card-divider question-divider">
|
3
5
|
<h2 class="card-title">
|
4
6
|
<span>
|
5
|
-
<% if
|
7
|
+
<% if editable %>
|
6
8
|
<%== "#{icon("move")} #{t(".question")}" %>
|
7
9
|
<% else %>
|
8
10
|
<%= t(".question") %>
|
9
11
|
<% end %>
|
10
12
|
</span>
|
11
13
|
|
12
|
-
<% if
|
13
|
-
<button class="button small alert hollow
|
14
|
+
<% if editable %>
|
15
|
+
<button class="button small alert hollow move-up-question button--title">
|
16
|
+
<%== "#{icon("arrow-top")} #{t(".up")}" %>
|
17
|
+
</button>
|
18
|
+
|
19
|
+
<button class="button small alert hollow move-down-question button--title">
|
20
|
+
<%== "#{icon("arrow-bottom")} #{t(".down")}" %>
|
21
|
+
</button>
|
22
|
+
|
23
|
+
<button class="button small alert hollow remove-question button--title">
|
24
|
+
<%= t(".remove") %>
|
25
|
+
</button>
|
14
26
|
<% end %>
|
15
27
|
</h2>
|
16
28
|
</div>
|
@@ -18,55 +30,86 @@
|
|
18
30
|
<div class="card-section">
|
19
31
|
<div class="row column">
|
20
32
|
<%=
|
21
|
-
|
22
|
-
:
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
tabs_id: tabs_id_for_question(question),
|
28
|
-
label: t('.statement'),
|
29
|
-
disabled: disabled_for_question(survey, question),
|
30
|
-
enable_tabs: question.persisted?
|
33
|
+
form.translated(
|
34
|
+
:text_field,
|
35
|
+
:body,
|
36
|
+
tabs_id: id,
|
37
|
+
label: t(".statement"),
|
38
|
+
disabled: !editable
|
31
39
|
)
|
32
40
|
%>
|
33
41
|
</div>
|
34
42
|
|
35
43
|
<div class="row column">
|
36
44
|
<%=
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
45
|
+
form.translated(
|
46
|
+
:editor,
|
47
|
+
:description,
|
48
|
+
toolbar: :full,
|
49
|
+
tabs_id: id,
|
50
|
+
label: t(".description"),
|
51
|
+
disabled: !editable
|
43
52
|
)
|
44
53
|
%>
|
45
|
-
<%= label_tag "", t('activemodel.attributes.survey_question.mandatory'), for: mandatory_id_for_question(question) %>
|
46
54
|
</div>
|
47
55
|
|
48
56
|
<div class="row column">
|
49
|
-
<%=
|
50
|
-
|
57
|
+
<%=
|
58
|
+
form.check_box(
|
59
|
+
:mandatory,
|
60
|
+
disabled: !editable,
|
61
|
+
label: t("activemodel.attributes.survey_question.mandatory")
|
62
|
+
)
|
63
|
+
%>
|
64
|
+
</div>
|
65
|
+
|
66
|
+
<div class="row column">
|
67
|
+
<%=
|
68
|
+
form.select(
|
69
|
+
:question_type,
|
70
|
+
options_from_collection_for_select(question_types, :first, :last, question.question_type),
|
71
|
+
{},
|
72
|
+
disabled: !editable
|
73
|
+
)
|
74
|
+
%>
|
51
75
|
</div>
|
52
76
|
|
53
77
|
<% if question.persisted? %>
|
54
|
-
<%=
|
78
|
+
<%= form.hidden_field :id, disabled: !editable %>
|
55
79
|
<% end %>
|
56
80
|
|
57
|
-
<%=
|
58
|
-
<%=
|
81
|
+
<%= form.hidden_field :position, value: question.position || 0, disabled: !editable %>
|
82
|
+
<%= form.hidden_field :deleted, disabled: !editable %>
|
59
83
|
|
60
84
|
<div class="survey-question-answer-options">
|
61
|
-
|
62
|
-
|
63
|
-
|
85
|
+
<template>
|
86
|
+
<%= fields_for "survey[questions][#{question.to_param}][answer_options][]", blank_answer_option do |answer_option_form| %>
|
87
|
+
<%= render "answer_option", form: answer_option_form, question: question, editable: editable %>
|
88
|
+
<% end %>
|
89
|
+
</template>
|
64
90
|
|
65
91
|
<div class="survey-question-answer-options-list">
|
66
|
-
<% question.answer_options.
|
67
|
-
<%=
|
92
|
+
<% question.answer_options.each do |answer_option| %>
|
93
|
+
<%= fields_for "survey[questions][#{question.to_param}][answer_options][]", answer_option do |answer_option_form| %>
|
94
|
+
<%= render "answer_option", form: answer_option_form, question: question, editable: editable %>
|
95
|
+
<% end %>
|
68
96
|
<% end %>
|
69
97
|
</div>
|
98
|
+
|
99
|
+
<% if editable %>
|
100
|
+
<button class="button add-answer-option"><%= t(".add_answer_option") %></button>
|
101
|
+
<% end %>
|
102
|
+
</div>
|
103
|
+
|
104
|
+
<div class="row column survey-question-max-choices">
|
105
|
+
<%=
|
106
|
+
form.select(
|
107
|
+
:max_choices,
|
108
|
+
(2..question.number_of_options),
|
109
|
+
{ prompt: t(".any") },
|
110
|
+
disabled: !editable
|
111
|
+
)
|
112
|
+
%>
|
70
113
|
</div>
|
71
114
|
</div>
|
72
115
|
</div>
|
@@ -1,5 +1,5 @@
|
|
1
1
|
<%= decidim_form_for(@form, url: survey_path, method: :post, html: { class: "form edit_survey" }) do |form| %>
|
2
|
-
<%= render partial:
|
2
|
+
<%= render partial: "form", object: form, locals: { title: t(".title") } %>
|
3
3
|
|
4
4
|
<div class="button--double form-general-submit">
|
5
5
|
<%= form.submit t(".save"), class: "button" %>
|
@@ -0,0 +1,94 @@
|
|
1
|
+
<% field_id = "survey_answers_#{answer_idx}" %>
|
2
|
+
<%= label_tag field_id, answer.label(answer_idx), class: "survey-question" %>
|
3
|
+
|
4
|
+
<% if translated_attribute(answer.question.description).present? %>
|
5
|
+
<div class="help-text">
|
6
|
+
<%= decidim_sanitize translated_attribute(answer.question.description) %>
|
7
|
+
</div>
|
8
|
+
<% end %>
|
9
|
+
|
10
|
+
<% case answer.question.question_type %>
|
11
|
+
<% when "short_answer" %>
|
12
|
+
<%= answer_form.text_field :body, label: false, id: field_id %>
|
13
|
+
<% when "long_answer" %>
|
14
|
+
<%= answer_form.text_area :body, label: false, id: field_id, rows: 10 %>
|
15
|
+
<% when "single_option" %>
|
16
|
+
<div class="radio-button-collection">
|
17
|
+
<% choice = answer.choices.first %>
|
18
|
+
|
19
|
+
<% answer.question.answer_options.each_with_index do |answer_option, idx| %>
|
20
|
+
<% choice_id = "#{field_id}_choices_#{idx}" %>
|
21
|
+
|
22
|
+
<%= label_tag "#{choice_id}_body" do %>
|
23
|
+
<%= radio_button_tag "survey[answers][#{answer_idx}][choices][][body]",
|
24
|
+
translated_attribute(answer_option.body),
|
25
|
+
choice.try(:body),
|
26
|
+
id: "#{choice_id}_body" %>
|
27
|
+
|
28
|
+
<%= translated_attribute(answer_option.body) %>
|
29
|
+
|
30
|
+
<% if answer_option.free_text %>
|
31
|
+
<%= text_field_tag "survey[answers][#{answer_idx}][choices][][custom_body]",
|
32
|
+
choice.try(:custom_body),
|
33
|
+
id: "#{choice_id}_custom_body",
|
34
|
+
disabled: true %>
|
35
|
+
<% end %>
|
36
|
+
|
37
|
+
<%= hidden_field_tag "survey[answers][#{answer_idx}][choices][][answer_option_id]",
|
38
|
+
answer_option.id,
|
39
|
+
id: "#{choice_id}_answer_option",
|
40
|
+
disabled: true %>
|
41
|
+
<% end %>
|
42
|
+
<% end %>
|
43
|
+
</div>
|
44
|
+
<% when "multiple_option" %>
|
45
|
+
<div class="check-box-collection">
|
46
|
+
<% answer.question.answer_options.each_with_index do |answer_option, idx| %>
|
47
|
+
<% choice = answer.selected_choices.find { |choice| choice.answer_option_id == answer_option.id } %>
|
48
|
+
|
49
|
+
<%= label_tag do %>
|
50
|
+
<%= check_box_tag "survey[answers][#{answer_idx}][choices][#{idx}][body]",
|
51
|
+
translated_attribute(answer_option.body),
|
52
|
+
choice.present? %>
|
53
|
+
|
54
|
+
<%= translated_attribute(answer_option.body) %>
|
55
|
+
|
56
|
+
<% if answer_option.free_text %>
|
57
|
+
<%= text_field_tag "survey[answers][#{answer_idx}][choices][#{idx}][custom_body]",
|
58
|
+
choice.try(:custom_body),
|
59
|
+
disabled: true %>
|
60
|
+
<% end %>
|
61
|
+
|
62
|
+
<%= hidden_field_tag "survey[answers][#{answer_idx}][choices][#{idx}][answer_option_id]", answer_option.id %>
|
63
|
+
<% end %>
|
64
|
+
<% end %>
|
65
|
+
</div>
|
66
|
+
<% when "sorting" %>
|
67
|
+
<div class="sortable-check-box-collection">
|
68
|
+
<% answer.question.answer_options.each_with_index do |answer_option, idx| %>
|
69
|
+
<% choice = answer.selected_choices.find { |choice| choice.answer_option_id == answer_option.id } %>
|
70
|
+
|
71
|
+
<%= label_tag do %>
|
72
|
+
<%= check_box_tag "survey[answers][#{answer_idx}][choices][#{idx}][body]",
|
73
|
+
translated_attribute(answer_option.body),
|
74
|
+
choice.present? %>
|
75
|
+
|
76
|
+
<span class="position"><%= choice.try(:position) %></span>
|
77
|
+
|
78
|
+
<%= translated_attribute(answer_option.body) %>
|
79
|
+
|
80
|
+
<%= hidden_field_tag "survey[answers][#{answer_idx}][choices][#{idx}][position]",
|
81
|
+
choice.try(:position),
|
82
|
+
disabled: true %>
|
83
|
+
|
84
|
+
<%= hidden_field_tag "survey[answers][#{answer_idx}][choices][#{idx}][answer_option_id]", answer_option.id %>
|
85
|
+
<% end %>
|
86
|
+
<% end %>
|
87
|
+
</div>
|
88
|
+
<% end %>
|
89
|
+
|
90
|
+
<%= answer_form.hidden_field :question_id %>
|
91
|
+
|
92
|
+
<% answer.errors.full_messages.each do |msg| %>
|
93
|
+
<small class="form-error is-visible"><%= msg %></small>
|
94
|
+
<% end %>
|
@@ -3,7 +3,7 @@
|
|
3
3
|
description: translated_attribute(survey.description),
|
4
4
|
}) %>
|
5
5
|
|
6
|
-
<%= render partial: "decidim/shared/
|
6
|
+
<%= render partial: "decidim/shared/component_announcement" %>
|
7
7
|
|
8
8
|
<div class="row columns">
|
9
9
|
<h2 class="section-heading"><%= translated_attribute survey.title %></h2>
|
@@ -23,8 +23,8 @@
|
|
23
23
|
<% if survey.answered_by?(current_user) %>
|
24
24
|
<div class="section">
|
25
25
|
<div class="callout success">
|
26
|
-
<h5><%= t(
|
27
|
-
<p><%= t(
|
26
|
+
<h5><%= t(".survey_answered.title") %></h5>
|
27
|
+
<p><%= t(".survey_answered.body") %></p>
|
28
28
|
</div>
|
29
29
|
</div>
|
30
30
|
<% else %>
|
@@ -32,71 +32,44 @@
|
|
32
32
|
<%= decidim_form_for(@form, url: answer_survey_path(survey), method: :post, html: { class: "form answer-survey" }) do |form| %>
|
33
33
|
<% @form.answers.each_with_index do |answer, answer_idx| %>
|
34
34
|
<div class="row column">
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
<% case answer.question.question_type %>
|
39
|
-
<% when "short_answer" %>
|
40
|
-
<%= text_field_tag "survey[answers][#{answer_idx}][body][]", answer.body.try(:first), id: field_id, class: "#{'is-invalid-input' unless answer.errors.empty?}" %>
|
41
|
-
<% when "long_answer" %>
|
42
|
-
<%= text_area_tag "survey[answers][#{answer_idx}][body][]", answer.body.try(:first), id: field_id, class: "#{'is-invalid-input' unless answer.errors.empty?}", rows: 10 %>
|
43
|
-
<% when "single_option" %>
|
44
|
-
<div id="<%= field_id %>_answer_options" class="radio-button-collection">
|
45
|
-
<% answer.question.answer_options.each_with_index do |answer_option, idx| %>
|
46
|
-
<%= label_tag "#{field_id}_option_#{idx}" do %>
|
47
|
-
<%= radio_button_tag "survey[answers][#{answer_idx}][body][]", translated_attribute(answer_option["body"]), answer.body.try(:include?, translated_attribute(answer_option["body"])), id: "#{field_id}_option_#{idx}" %>
|
48
|
-
<%= translated_attribute(answer_option["body"]) %>
|
49
|
-
<% end %>
|
50
|
-
<% end %>
|
51
|
-
</div>
|
52
|
-
<% when "multiple_option" %>
|
53
|
-
<div id="<%= field_id %>_answer_options" class="check-box-collection">
|
54
|
-
<% answer.question.answer_options.each_with_index do |answer_option, idx| %>
|
55
|
-
<%= label_tag "#{field_id}_option_#{idx}" do %>
|
56
|
-
<%= check_box_tag "survey[answers][#{answer_idx}][body][]", translated_attribute(answer_option["body"]), answer.body.try(:include?, translated_attribute(answer_option["body"])), id: "#{field_id}_option_#{idx}" %>
|
57
|
-
<%= translated_attribute(answer_option["body"]) %>
|
58
|
-
<% end %>
|
59
|
-
<% end %>
|
60
|
-
</div>
|
61
|
-
<% end %>
|
62
|
-
|
63
|
-
<%= hidden_field_tag "survey[answers][#{answer_idx}][question_id]", answer.question.id %>
|
64
|
-
|
65
|
-
<% answer.errors.full_messages.each do |msg| %>
|
66
|
-
<%= content_tag :small, msg, class: "form-error is-visible" %>
|
35
|
+
<%= fields_for "survey[answers][#{answer_idx}]", answer do |answer_form| %>
|
36
|
+
<%= render "answer", answer_form: answer_form, answer: answer, answer_idx: answer_idx %>
|
67
37
|
<% end %>
|
68
38
|
</div>
|
69
39
|
<% end %>
|
70
40
|
|
71
|
-
<div class="row column">
|
41
|
+
<div class="row column tos-agreement">
|
72
42
|
<%= form.check_box :tos_agreement, label: t(".tos_agreement"), id: "survey_tos_agreement" %>
|
73
|
-
<div class="
|
43
|
+
<div class="help-text">
|
74
44
|
<%= decidim_sanitize translated_attribute survey.tos %>
|
75
45
|
</div>
|
76
46
|
</div>
|
77
47
|
|
78
48
|
<div class="button--double form-general-submit">
|
79
|
-
<%= form.submit t(".submit"), class: "button", data: { confirm: t(
|
49
|
+
<%= form.submit t(".submit"), class: "button", data: { confirm: t(".are_you_sure"), disable: true } %>
|
80
50
|
</div>
|
81
51
|
<% end %>
|
82
52
|
</div>
|
83
53
|
<% end %>
|
84
54
|
<% else %>
|
85
55
|
<div class="answer-survey">
|
86
|
-
<h5 class="section-heading"><%= t(
|
56
|
+
<h5 class="section-heading"><%= t(".answer_survey.title") %></h5>
|
87
57
|
<p>
|
88
|
-
<%= t(
|
58
|
+
<%= t(".answer_survey.anonymous_user_message", sign_in_link: decidim.new_user_session_path, sign_up_link: decidim.new_user_registration_path).html_safe %>
|
89
59
|
</p>
|
90
60
|
</div>
|
91
61
|
<% end %>
|
92
62
|
<% else %>
|
93
63
|
<div class="section">
|
94
64
|
<div class="callout warning">
|
95
|
-
<h5><%= t(
|
96
|
-
<p><%= t(
|
65
|
+
<h5><%= t(".survey_closed.title") %></h5>
|
66
|
+
<p><%= t(".survey_closed.body") %></p>
|
97
67
|
</div>
|
98
68
|
</div>
|
99
69
|
<% end %>
|
70
|
+
</div>
|
100
71
|
</div>
|
101
72
|
</div>
|
102
73
|
</div>
|
74
|
+
|
75
|
+
<%= javascript_include_tag "decidim/surveys/surveys" %>
|