decidim-forms 0.17.2 → 0.18.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 24554bddfaa48fecc6358c915f8b0591bfd4f50099a1b6107b65055c3ef8978e
4
- data.tar.gz: 725c58ef7f1b7a7c926109bf21119e2459fc8c03caca8ffc045d2abc1f144920
3
+ metadata.gz: d354b6d1272004fbe129e57e706ecb2bce8f7f37e5a2f32c530d8df96d862e98
4
+ data.tar.gz: 8cb45ad3b2d7b7fa4518720215d4fa89428345e1fb4825dd4ad6768f967a11d9
5
5
  SHA512:
6
- metadata.gz: b3d8b91cd7f5630ede91f048b83b3480aa8cd33673f593c7c9bdde3948f019596d0aa53d784a7f989d3f55505c4c47f6a12f19836c82cf57f6e9e47215ec4804
7
- data.tar.gz: ae40beb4dca8385feefc34b5ba32d117cf7ccb1425acf31f721a0f7ad5f9d3d1e0a9eaa8406053234f667b619c4fe9adf132cb2a2d101b2431832276cbe2bbea
6
+ metadata.gz: 253ca5e79fc6adedad3512672df12413dd3eba8c7e26b75b0bf0e984b99c04694485361040c84f06370793fc54e8d8d802ab886fd75e60955ffcfb94bc421d72
7
+ data.tar.gz: 3e73bed78008ffaa519a264948234aa8af20b3c4279e16076214454c8453988f9f4ebf2f92b1d6d7b6a659e5f9a967f25b4c03126ae3a8aa339ea3f9a3b2ae2e
@@ -13,6 +13,7 @@ module Decidim
13
13
  extend ActiveSupport::Concern
14
14
 
15
15
  included do
16
+ helper Decidim::Forms::ApplicationHelper
16
17
  include FormFactory
17
18
 
18
19
  helper_method :questionnaire_for, :questionnaire, :allow_answers?, :update_url
@@ -5,6 +5,7 @@ module Decidim
5
5
  # This class holds a Form to answer a questionnaire from Decidim's public page.
6
6
  class QuestionnaireForm < Decidim::Form
7
7
  attribute :answers, Array[AnswerForm]
8
+ attribute :user_group_id, Integer
8
9
 
9
10
  attribute :tos_agreement, Boolean
10
11
  validates :tos_agreement, allow_nil: false, acceptance: true
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Forms
5
+ # Custom helpers, scoped to the forms engine.
6
+ module ApplicationHelper
7
+ # Show cell for selected models
8
+ def show_represent_user_group?
9
+ model_name = questionnaire_for.model_name.element
10
+
11
+ permited_models.include?(model_name)
12
+ end
13
+
14
+ def permited_models
15
+ %(meeting)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -5,6 +5,7 @@ module Decidim
5
5
  # The data store for an Answer in the Decidim::Forms
6
6
  class Answer < Forms::ApplicationRecord
7
7
  include Decidim::DataPortability
8
+ include Decidim::NewsletterParticipant
8
9
 
9
10
  belongs_to :user, class_name: "Decidim::User", foreign_key: "decidim_user_id"
10
11
  belongs_to :questionnaire, class_name: "Questionnaire", foreign_key: "decidim_questionnaire_id"
@@ -30,6 +31,17 @@ module Decidim
30
31
  Decidim::Forms::DataPortabilityUserAnswersSerializer
31
32
  end
32
33
 
34
+ def self.newsletter_participant_ids(component)
35
+ surveys = Decidim::Surveys::Survey.joins(:component, :questionnaire).where(component: component)
36
+ questionnaires = Decidim::Forms::Questionnaire.includes(:questionnaire_for)
37
+ .where(questionnaire_for_type: Decidim::Surveys::Survey.name, questionnaire_for_id: surveys.pluck(:id))
38
+
39
+ answers = Decidim::Forms::Answer.joins(:questionnaire)
40
+ .where(questionnaire: questionnaires)
41
+
42
+ answers.pluck(:decidim_user_id).flatten.compact.uniq
43
+ end
44
+
33
45
  private
34
46
 
35
47
  def user_questionnaire_same_organization
@@ -0,0 +1,7 @@
1
+ <% question = form.object %>
2
+
3
+ <script type="text/template" class="decidim-template" id="<%= template_id %>">
4
+ <%= fields_for "questionnaire[questions][#{question.to_param}][answer_options][]", blank_answer_option do |answer_option_form| %>
5
+ <%= render "decidim/forms/admin/questionnaires/answer_option", form: answer_option_form, question: question, editable: editable %>
6
+ <% end %>
7
+ </script>
@@ -22,11 +22,12 @@
22
22
 
23
23
  <div class="questionnaire-questions">
24
24
  <% if questionnaire.questions_editable? %>
25
- <template>
26
- <%= fields_for "questionnaire[questions][#{blank_question.to_param}]", blank_question do |question_form| %>
27
- <%= render "decidim/forms/admin/questionnaires/question", form: question_form, id: tabs_id_for_question(blank_question), editable: questionnaire.questions_editable? %>
28
- <% end %>
29
- </template>
25
+ <%= fields_for "questionnaire[questions][#{blank_question.to_param}]", blank_question do |question_form| %>
26
+ <script type="text/template" class="decidim-template">
27
+ <%= render "decidim/forms/admin/questionnaires/question", form: question_form, id: tabs_id_for_question(blank_question), editable: questionnaire.questions_editable?, child_template_selector: "#answer-option-template-dummy" %>
28
+ </script>
29
+ <%= render "decidim/forms/admin/questionnaires/answer_option_template", form: question_form, editable: questionnaire.questions_editable?, template_id: "answer-option-template-dummy" %>
30
+ <% end %>
30
31
  <% else %>
31
32
  <div class="callout warning">
32
33
  <%= t(".already_answered_warning") %>
@@ -34,9 +35,10 @@
34
35
  <% end %>
35
36
 
36
37
  <div class="questionnaire-questions-list">
37
- <% @form.questions.each do |question| %>
38
+ <% @form.questions.each_with_index do |question, index| %>
38
39
  <%= fields_for "questionnaire[questions][]", question do |question_form| %>
39
- <%= render "decidim/forms/admin/questionnaires/question", form: question_form, id: tabs_id_for_question(question), editable: questionnaire.questions_editable? %>
40
+ <%= render "decidim/forms/admin/questionnaires/question", form: question_form, id: tabs_id_for_question(question), editable: questionnaire.questions_editable?, child_template_selector: "#answer-option-template-#{index}" %>
41
+ <%= render "decidim/forms/admin/questionnaires/answer_option_template", form: question_form, editable: questionnaire.questions_editable?, template_id: "answer-option-template-#{index}" %>
40
42
  <% end %>
41
43
  <% end %>
42
44
  </div>
@@ -81,13 +81,7 @@
81
81
  <%= form.hidden_field :position, value: question.position || 0, disabled: !editable %>
82
82
  <%= form.hidden_field :deleted, disabled: !editable %>
83
83
 
84
- <div class="questionnaire-question-answer-options">
85
- <template>
86
- <%= fields_for "questionnaire[questions][#{question.to_param}][answer_options][]", blank_answer_option do |answer_option_form| %>
87
- <%= render "decidim/forms/admin/questionnaires/answer_option", form: answer_option_form, question: question, editable: editable %>
88
- <% end %>
89
- </template>
90
-
84
+ <div class="questionnaire-question-answer-options" data-template="<%= child_template_selector %>">
91
85
  <div class="questionnaire-question-answer-options-list">
92
86
  <% question.answer_options.each do |answer_option| %>
93
87
  <%= fields_for "questionnaire[questions][#{question.to_param}][answer_options][]", answer_option do |answer_option_form| %>
@@ -47,6 +47,12 @@
47
47
  </div>
48
48
  <% end %>
49
49
 
50
+ <% if show_represent_user_group? %>
51
+ <div class="row column represent-user-group">
52
+ <%= cell("decidim/represent_user_group", form) %>
53
+ </div>
54
+ <% end %>
55
+
50
56
  <div class="row column tos-agreement">
51
57
  <%= form.check_box :tos_agreement, label: t(".tos_agreement"), id: "questionnaire_tos_agreement", disabled: !current_participatory_space.can_participate?(current_user) %>
52
58
  <div class="help-text">
@@ -0,0 +1,82 @@
1
+ ar:
2
+ activemodel:
3
+ attributes:
4
+ answer:
5
+ body: إجابة
6
+ question:
7
+ max_choices: أقصى عدد من الخيارات
8
+ question_type: نوع
9
+ questionnaire_question:
10
+ mandatory: إلزامي
11
+ errors:
12
+ models:
13
+ answer:
14
+ attributes:
15
+ choices:
16
+ missing: ليست كاملة
17
+ too_many: كثير جدا
18
+ decidim:
19
+ forms:
20
+ admin:
21
+ models:
22
+ components:
23
+ description: وصف
24
+ tos: شروط الخدمة
25
+ questionnaires:
26
+ answer_option:
27
+ answer_option: خيار الإجابة
28
+ free_text: نص حر
29
+ remove: إزالة
30
+ statement: بيان
31
+ edit:
32
+ save: حفظ
33
+ title: عنوان
34
+ form:
35
+ add_question: أضف سؤال
36
+ already_answered_warning: تمت الإجابة على النموذج من قبل بعض المستخدمين حتى لا تتمكن من تعديل أسئلته.
37
+ question:
38
+ add_answer_option: إضافة خيار الإجابة
39
+ any: أي
40
+ description: وصف
41
+ down: أسفل
42
+ question: سؤال
43
+ remove: إزالة
44
+ statement: بيان
45
+ up: فوق
46
+ update:
47
+ invalid: كانت هناك مشكلة في حفظ النموذج.
48
+ success: تم حفظ النماذج بنجاح.
49
+ errors:
50
+ answer:
51
+ body: لا يمكن أن يكون الجسم فارغًا
52
+ question_types:
53
+ long_answer: اجابة طويلة
54
+ multiple_option: خيار متعدد
55
+ short_answer: اجابة قصيرة
56
+ single_option: خيار واحد
57
+ sorting: فرز
58
+ questionnaires:
59
+ answer:
60
+ invalid: كانت هناك مشكلة في الإجابة على النموذج.
61
+ success: نموذج أجاب بنجاح.
62
+ question:
63
+ max_choices: 'خيارات ماكس: %{n}'
64
+ show:
65
+ answer_questionnaire:
66
+ anonymous_user_message: <a href="%{sign_in_link}">قم بتسجيل الدخول بحسابك</a> أو <a href="%{sign_up_link}">اشترك</a> للإجابة على النموذج
67
+ title: أجب عن النموذج
68
+ are_you_sure: لا يمكن التراجع عن هذا الإجراء ولن تتمكن من تعديل إجاباتك. هل أنت واثق؟
69
+ questionnaire_answered:
70
+ body: لقد أجبت بالفعل على هذا النموذج.
71
+ title: تمت الاجابة مسبقا
72
+ questionnaire_closed:
73
+ body: النموذج مغلق ولا يمكن الرد عليه.
74
+ title: شكل مغلق
75
+ questionnaire_for_private_users:
76
+ body: النموذج متاح فقط للمستخدمين من القطاع الخاص
77
+ title: شكل مغلق
78
+ submit: خضع
79
+ tos_agreement: من خلال المشاركة ، فإنك تقبل شروط الخدمة
80
+ user_answers_serializer:
81
+ created_at: أجاب على
82
+ id: معرف الإجابة
@@ -504,9 +504,9 @@ shared_examples_for "manage questionnaires" do
504
504
  within ".questionnaire-question:last-of-type" do
505
505
  click_button "Up"
506
506
  end
507
-
508
- it_behaves_like "switching questions order"
509
507
  end
508
+
509
+ it_behaves_like "switching questions order"
510
510
  end
511
511
 
512
512
  context "when moving a question down" do
@@ -522,9 +522,9 @@ shared_examples_for "manage questionnaires" do
522
522
  it "properly decides which button to show after adding/removing questions" do
523
523
  click_button "Add question"
524
524
 
525
- expect(page.find(".questionnaire-question:nth-child(1)")).to look_like_first_question
526
- expect(page.find(".questionnaire-question:nth-child(2)")).to look_like_intermediate_question
527
- expect(page.find(".questionnaire-question:nth-child(3)")).to look_like_last_question
525
+ expect(page.find(".questionnaire-question:nth-of-type(1)")).to look_like_first_question
526
+ expect(page.find(".questionnaire-question:nth-of-type(2)")).to look_like_intermediate_question
527
+ expect(page.find(".questionnaire-question:nth-of-type(3)")).to look_like_last_question
528
528
 
529
529
  within ".questionnaire-question:first-of-type" do
530
530
  click_button "Remove"
@@ -4,7 +4,7 @@ module Decidim
4
4
  # This holds the decidim-forms version.
5
5
  module Forms
6
6
  def self.version
7
- "0.17.2"
7
+ "0.18.0"
8
8
  end
9
9
  end
10
10
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: decidim-forms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.2
4
+ version: 0.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josep Jaume Rey Peroy
@@ -19,42 +19,42 @@ dependencies:
19
19
  requirements:
20
20
  - - '='
21
21
  - !ruby/object:Gem::Version
22
- version: 0.17.2
22
+ version: 0.18.0
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - '='
28
28
  - !ruby/object:Gem::Version
29
- version: 0.17.2
29
+ version: 0.18.0
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: decidim-admin
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  requirements:
34
34
  - - '='
35
35
  - !ruby/object:Gem::Version
36
- version: 0.17.2
36
+ version: 0.18.0
37
37
  type: :development
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
40
40
  requirements:
41
41
  - - '='
42
42
  - !ruby/object:Gem::Version
43
- version: 0.17.2
43
+ version: 0.18.0
44
44
  - !ruby/object:Gem::Dependency
45
45
  name: decidim-dev
46
46
  requirement: !ruby/object:Gem::Requirement
47
47
  requirements:
48
48
  - - '='
49
49
  - !ruby/object:Gem::Version
50
- version: 0.17.2
50
+ version: 0.18.0
51
51
  type: :development
52
52
  prerelease: false
53
53
  version_requirements: !ruby/object:Gem::Requirement
54
54
  requirements:
55
55
  - - '='
56
56
  - !ruby/object:Gem::Version
57
- version: 0.17.2
57
+ version: 0.18.0
58
58
  description: A forms gem for decidim.
59
59
  email:
60
60
  - josepjaume@gmail.com
@@ -93,6 +93,7 @@ files:
93
93
  - app/forms/decidim/forms/answer_form.rb
94
94
  - app/forms/decidim/forms/questionnaire_form.rb
95
95
  - app/helpers/decidim/forms/admin/application_helper.rb
96
+ - app/helpers/decidim/forms/application_helper.rb
96
97
  - app/models/concerns/decidim/forms/has_questionnaire.rb
97
98
  - app/models/decidim/forms/answer.rb
98
99
  - app/models/decidim/forms/answer_choice.rb
@@ -102,12 +103,14 @@ files:
102
103
  - app/models/decidim/forms/questionnaire.rb
103
104
  - app/queries/decidim/forms/questionnaire_user_answers.rb
104
105
  - app/views/decidim/forms/admin/questionnaires/_answer_option.html.erb
106
+ - app/views/decidim/forms/admin/questionnaires/_answer_option_template.html.erb
105
107
  - app/views/decidim/forms/admin/questionnaires/_form.html.erb
106
108
  - app/views/decidim/forms/admin/questionnaires/_question.html.erb
107
109
  - app/views/decidim/forms/admin/questionnaires/edit.html.erb
108
110
  - app/views/decidim/forms/questionnaires/_answer.html.erb
109
111
  - app/views/decidim/forms/questionnaires/show.html.erb
110
112
  - config/locales/ar-SA.yml
113
+ - config/locales/ar.yml
111
114
  - config/locales/ca.yml
112
115
  - config/locales/cs-CZ.yml
113
116
  - config/locales/cs.yml