decidim-templates 0.27.9 → 0.28.0.rc4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE-AGPLv3.txt +661 -0
- data/app/commands/decidim/templates/admin/apply_questionnaire_template.rb +1 -1
- data/app/commands/decidim/templates/admin/copy_proposal_answer_template.rb +21 -0
- data/app/commands/decidim/templates/admin/copy_questionnaire_template.rb +3 -33
- data/app/commands/decidim/templates/admin/copy_template.rb +43 -0
- data/app/commands/decidim/templates/admin/create_block_user_template.rb +15 -0
- data/app/commands/decidim/templates/admin/create_proposal_answer_template.rb +47 -0
- data/app/commands/decidim/templates/admin/create_questionnaire_template.rb +6 -19
- data/app/commands/decidim/templates/admin/create_template.rb +54 -0
- data/app/commands/decidim/templates/admin/destroy_questionnaire_template.rb +22 -0
- data/app/commands/decidim/templates/admin/update_proposal_answer_template.rb +51 -0
- data/app/commands/decidim/templates/admin/update_template.rb +6 -0
- data/app/controllers/decidim/templates/admin/application_controller.rb +0 -8
- data/app/controllers/decidim/templates/admin/block_user_templates_controller.rb +124 -0
- data/app/controllers/decidim/templates/admin/concerns/templatable.rb +1 -1
- data/app/controllers/decidim/templates/admin/proposal_answer_templates_controller.rb +173 -0
- data/app/controllers/decidim/templates/admin/questionnaire_templates_controller.rb +4 -4
- data/app/forms/decidim/templates/admin/proposal_answer_template_form.rb +23 -0
- data/app/helpers/decidim/templates/admin/application_helper.rb +18 -0
- data/app/models/decidim/templates/template.rb +0 -6
- data/app/packs/entrypoints/decidim_templates_admin.js +2 -0
- data/app/packs/src/decidim/templates/admin/block_user_template_chooser.js +20 -0
- data/app/packs/src/decidim/templates/admin/proposal_answer_template_chooser.js +31 -0
- data/app/packs/stylesheets/decidim/templates/templates.scss +3 -12
- data/app/presenters/decidim/templates/admin_log/template_presenter.rb +2 -2
- data/app/views/decidim/templates/admin/block_user_templates/_form.html.erb +13 -0
- data/app/views/decidim/templates/admin/block_user_templates/_template_chooser.html.erb +12 -0
- data/app/views/decidim/templates/admin/block_user_templates/edit.html.erb +18 -0
- data/app/views/decidim/templates/admin/block_user_templates/index.html.erb +45 -0
- data/app/views/decidim/templates/admin/block_user_templates/new.html.erb +18 -0
- data/app/views/decidim/templates/admin/proposal_answer_templates/_form.html.erb +38 -0
- data/app/views/decidim/templates/admin/proposal_answer_templates/_template_chooser.html.erb +16 -0
- data/app/views/decidim/templates/admin/proposal_answer_templates/edit.html.erb +18 -0
- data/app/views/decidim/templates/admin/proposal_answer_templates/index.html.erb +51 -0
- data/app/views/decidim/templates/admin/proposal_answer_templates/new.html.erb +18 -0
- data/app/views/decidim/templates/admin/questionnaire_templates/_choose.html.erb +35 -35
- data/app/views/decidim/templates/admin/questionnaire_templates/_form.html.erb +9 -12
- data/app/views/decidim/templates/admin/questionnaire_templates/_preview.html.erb +52 -60
- data/app/views/decidim/templates/admin/questionnaire_templates/edit.html.erb +31 -16
- data/app/views/decidim/templates/admin/questionnaire_templates/index.html.erb +6 -8
- data/app/views/decidim/templates/admin/questionnaire_templates/new.html.erb +18 -7
- data/app/views/decidim/templates/admin/questionnaire_templates/preview.js.erb +4 -1
- data/app/views/layouts/decidim/admin/templates.html.erb +1 -9
- data/config/assets.rb +2 -1
- data/config/locales/ar.yml +8 -2
- data/config/locales/bg.yml +0 -73
- data/config/locales/ca.yml +47 -8
- data/config/locales/cs.yml +47 -8
- data/config/locales/de.yml +47 -8
- data/config/locales/en.yml +47 -8
- data/config/locales/es-MX.yml +47 -8
- data/config/locales/es-PY.yml +47 -8
- data/config/locales/es.yml +47 -8
- data/config/locales/eu.yml +47 -8
- data/config/locales/fi-plain.yml +47 -8
- data/config/locales/fi.yml +47 -8
- data/config/locales/fr-CA.yml +33 -8
- data/config/locales/fr.yml +47 -8
- data/config/locales/ga-IE.yml +6 -2
- data/config/locales/gl.yml +6 -10
- data/config/locales/hu.yml +6 -10
- data/config/locales/it.yml +6 -10
- data/config/locales/ja.yml +28 -8
- data/config/locales/kaa.yml +4 -1
- data/config/locales/lt.yml +18 -8
- data/config/locales/nl.yml +6 -11
- data/config/locales/no.yml +6 -10
- data/config/locales/pl.yml +6 -24
- data/config/locales/pt-BR.yml +6 -16
- data/config/locales/pt.yml +6 -10
- data/config/locales/ro-RO.yml +18 -8
- data/config/locales/sv.yml +8 -20
- data/config/locales/tr-TR.yml +8 -10
- data/config/locales/zh-CN.yml +6 -11
- data/config/locales/zh-TW.yml +18 -8
- data/db/migrate/20221006055954_add_field_values_and_target_to_decidim_templates.rb +21 -0
- data/db/seeds.rb +6 -6
- data/lib/decidim/templates/admin_engine.rb +22 -17
- data/lib/decidim/templates/engine.rb +4 -0
- data/lib/decidim/templates/menu.rb +48 -0
- data/lib/decidim/templates/test/factories.rb +23 -15
- data/lib/decidim/templates/test/shared_examples/copies_all_questionnaire_contents_examples.rb +3 -3
- data/lib/decidim/templates/test/shared_examples/uses_questionnaire_templates.rb +10 -8
- data/lib/decidim/templates/version.rb +1 -1
- metadata +49 -61
- data/config/locales/he-IL.yml +0 -1
- data/decidim-templates.gemspec +0 -34
@@ -19,7 +19,7 @@ module Decidim
|
|
19
19
|
# Executes the command. Broadcasts these events:
|
20
20
|
#
|
21
21
|
# - :ok when everything is valid.
|
22
|
-
# - :invalid if the form
|
22
|
+
# - :invalid if the form was not valid and we could not proceed.
|
23
23
|
#
|
24
24
|
# Returns nothing.
|
25
25
|
def call
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Templates
|
5
|
+
# A command with all the business logic when duplicating a proposal's answer template
|
6
|
+
module Admin
|
7
|
+
class CopyProposalAnswerTemplate < CopyTemplate
|
8
|
+
def copy_template
|
9
|
+
@copied_template = Template.create!(
|
10
|
+
organization: @template.organization,
|
11
|
+
name: @template.name,
|
12
|
+
description: @template.description,
|
13
|
+
target: :proposal_answer,
|
14
|
+
field_values: @template.field_values,
|
15
|
+
templatable: @template.templatable
|
16
|
+
)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -4,46 +4,15 @@ module Decidim
|
|
4
4
|
module Templates
|
5
5
|
# A command with all the business logic when duplicating a questionnaire template
|
6
6
|
module Admin
|
7
|
-
class CopyQuestionnaireTemplate <
|
7
|
+
class CopyQuestionnaireTemplate < CopyTemplate
|
8
8
|
include Decidim::Templates::Admin::QuestionnaireCopier
|
9
9
|
|
10
|
-
# Public: Initializes the command.
|
11
|
-
#
|
12
|
-
# template - A template we want to duplicate
|
13
|
-
def initialize(template, user)
|
14
|
-
@template = template
|
15
|
-
@user = user
|
16
|
-
end
|
17
|
-
|
18
|
-
# Executes the command. Broadcasts these events:
|
19
|
-
#
|
20
|
-
# - :ok when everything is valid.
|
21
|
-
# - :invalid if the form wasn't valid and we couldn't proceed.
|
22
|
-
#
|
23
|
-
# Returns nothing.
|
24
|
-
def call
|
25
|
-
return broadcast(:invalid) unless @template.valid?
|
26
|
-
|
27
|
-
Decidim.traceability.perform_action!("duplicate", @template, @user) do
|
28
|
-
Template.transaction do
|
29
|
-
copy_template
|
30
|
-
copy_questionnaire_questions(@template.templatable, @copied_template.templatable)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
broadcast(:ok, @copied_template)
|
35
|
-
end
|
36
|
-
|
37
10
|
private
|
38
11
|
|
39
12
|
attr_reader :form
|
40
13
|
|
41
14
|
def copy_template
|
42
|
-
|
43
|
-
organization: @template.organization,
|
44
|
-
name: @template.name,
|
45
|
-
description: @template.description
|
46
|
-
)
|
15
|
+
super
|
47
16
|
@resource = Decidim::Forms::Questionnaire.create!(
|
48
17
|
@template.templatable.dup.attributes.merge(
|
49
18
|
questionnaire_for: @copied_template
|
@@ -51,6 +20,7 @@ module Decidim
|
|
51
20
|
)
|
52
21
|
|
53
22
|
@copied_template.update!(templatable: @resource)
|
23
|
+
copy_questionnaire_questions(@template.templatable, @copied_template.templatable)
|
54
24
|
end
|
55
25
|
end
|
56
26
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Templates
|
5
|
+
module Admin
|
6
|
+
class CopyTemplate < Decidim::Command
|
7
|
+
def initialize(template, user)
|
8
|
+
@template = template
|
9
|
+
@user = user
|
10
|
+
end
|
11
|
+
|
12
|
+
# Executes the command. Broadcasts these events:
|
13
|
+
#
|
14
|
+
# - :ok when everything is valid.
|
15
|
+
# - :invalid if the form was not valid and we could not proceed.
|
16
|
+
#
|
17
|
+
# Returns nothing.
|
18
|
+
def call
|
19
|
+
return broadcast(:invalid) unless @template.valid?
|
20
|
+
|
21
|
+
Decidim.traceability.perform_action!("duplicate", @template, @user) do
|
22
|
+
Template.transaction do
|
23
|
+
copy_template
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
broadcast(:ok, @copied_template)
|
28
|
+
end
|
29
|
+
|
30
|
+
def copy_template
|
31
|
+
@copied_template = Template.create!(
|
32
|
+
organization: @template.organization,
|
33
|
+
name: @template.name,
|
34
|
+
description: @template.description,
|
35
|
+
target: @template.target,
|
36
|
+
field_values: @template.field_values,
|
37
|
+
templatable: @template.templatable
|
38
|
+
)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Templates
|
5
|
+
module Admin
|
6
|
+
class CreateProposalAnswerTemplate < Decidim::Command
|
7
|
+
# Initializes the command.
|
8
|
+
#
|
9
|
+
# form - The source for this ProposalAnswerTemplate.
|
10
|
+
def initialize(form)
|
11
|
+
@form = form
|
12
|
+
end
|
13
|
+
|
14
|
+
def call
|
15
|
+
return broadcast(:invalid) unless @form.valid?
|
16
|
+
|
17
|
+
@template = Decidim.traceability.create!(
|
18
|
+
Template,
|
19
|
+
@form.current_user,
|
20
|
+
name: @form.name,
|
21
|
+
description: @form.description,
|
22
|
+
organization: @form.current_organization,
|
23
|
+
field_values: { internal_state: @form.internal_state },
|
24
|
+
target: :proposal_answer
|
25
|
+
)
|
26
|
+
|
27
|
+
@template.update!(templatable: identify_templateable_resource)
|
28
|
+
|
29
|
+
broadcast(:ok, @template)
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def identify_templateable_resource
|
35
|
+
resource = @form.current_organization
|
36
|
+
if @form.component_constraint.present?
|
37
|
+
found_component = Decidim::Component.find_by(id: @form.component_constraint, manifest_name: "proposals")
|
38
|
+
if found_component.present?
|
39
|
+
resource = found_component&.participatory_space&.decidim_organization_id == @form.current_organization.id ? found_component : nil
|
40
|
+
end
|
41
|
+
end
|
42
|
+
resource
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -4,29 +4,16 @@ module Decidim
|
|
4
4
|
module Templates
|
5
5
|
module Admin
|
6
6
|
# Creates a QuestionnaireTemplate.
|
7
|
-
class CreateQuestionnaireTemplate <
|
8
|
-
|
9
|
-
#
|
10
|
-
# form - The source for this QuestionnaireTemplate.
|
11
|
-
def initialize(form)
|
12
|
-
@form = form
|
13
|
-
end
|
14
|
-
|
15
|
-
def call
|
16
|
-
return broadcast(:invalid) unless @form.valid?
|
17
|
-
|
18
|
-
@template = Decidim.traceability.create!(
|
19
|
-
Template,
|
20
|
-
@form.current_user,
|
21
|
-
name: @form.name,
|
22
|
-
description: @form.description,
|
23
|
-
organization: @form.current_organization
|
24
|
-
)
|
7
|
+
class CreateQuestionnaireTemplate < CreateTemplate
|
8
|
+
protected
|
25
9
|
|
10
|
+
def assign_template!
|
26
11
|
@questionnaire = Decidim::Forms::Questionnaire.create!(questionnaire_for: @template)
|
27
12
|
@template.update!(templatable: @questionnaire)
|
13
|
+
end
|
28
14
|
|
29
|
-
|
15
|
+
def target
|
16
|
+
:questionnaire
|
30
17
|
end
|
31
18
|
end
|
32
19
|
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Templates
|
5
|
+
module Admin
|
6
|
+
class CreateTemplate < Decidim::Command
|
7
|
+
# Initializes the command.
|
8
|
+
#
|
9
|
+
# form - The source for this generic Template.
|
10
|
+
def initialize(form)
|
11
|
+
@form = form
|
12
|
+
end
|
13
|
+
|
14
|
+
# Executes the command. Broadcasts these events:
|
15
|
+
#
|
16
|
+
# - :ok when everything is valid.
|
17
|
+
# - :invalid if the form was not valid and we could not proceed.
|
18
|
+
#
|
19
|
+
# Returns nothing.
|
20
|
+
def call
|
21
|
+
return broadcast(:invalid) unless @form.valid?
|
22
|
+
|
23
|
+
@template = Decidim.traceability.create!(
|
24
|
+
Template,
|
25
|
+
@form.current_user,
|
26
|
+
name: @form.name,
|
27
|
+
description: @form.description,
|
28
|
+
organization: @form.current_organization,
|
29
|
+
field_values:,
|
30
|
+
target:
|
31
|
+
)
|
32
|
+
|
33
|
+
assign_template!
|
34
|
+
|
35
|
+
broadcast(:ok, @template)
|
36
|
+
end
|
37
|
+
|
38
|
+
protected
|
39
|
+
|
40
|
+
def assign_template!
|
41
|
+
@template.update!(templatable: @form.current_organization)
|
42
|
+
end
|
43
|
+
|
44
|
+
def field_values
|
45
|
+
{}
|
46
|
+
end
|
47
|
+
|
48
|
+
def target
|
49
|
+
raise "Not implemented"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Templates
|
5
|
+
module Admin
|
6
|
+
class DestroyQuestionnaireTemplate < DestroyTemplate
|
7
|
+
protected
|
8
|
+
|
9
|
+
def destroy_template
|
10
|
+
Decidim.traceability.perform_action!(
|
11
|
+
:delete,
|
12
|
+
template,
|
13
|
+
current_user
|
14
|
+
) do
|
15
|
+
template.destroy!
|
16
|
+
template.templatable.destroy
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Templates
|
5
|
+
module Admin
|
6
|
+
class UpdateProposalAnswerTemplate < Decidim::Command
|
7
|
+
# Initializes the command.
|
8
|
+
#
|
9
|
+
# template - The Template to update.
|
10
|
+
# form - The form object containing the data to update.
|
11
|
+
# user - The user that updates the template.
|
12
|
+
def initialize(template, form, user)
|
13
|
+
@template = template
|
14
|
+
@form = form
|
15
|
+
@user = user
|
16
|
+
end
|
17
|
+
|
18
|
+
def call
|
19
|
+
return broadcast(:invalid) unless @form.valid?
|
20
|
+
return broadcast(:invalid) unless @user.organization == @template.organization
|
21
|
+
|
22
|
+
@template = Decidim.traceability.update!(
|
23
|
+
@template,
|
24
|
+
@user,
|
25
|
+
name: @form.name,
|
26
|
+
description: @form.description,
|
27
|
+
field_values: { internal_state: @form.internal_state },
|
28
|
+
target: :proposal_answer
|
29
|
+
)
|
30
|
+
|
31
|
+
@template.update!(templatable: identify_templateable_resource)
|
32
|
+
|
33
|
+
broadcast(:ok, @template)
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def identify_templateable_resource
|
39
|
+
resource = @form.current_organization
|
40
|
+
if @form.component_constraint.present?
|
41
|
+
found_component = Decidim::Component.find_by(id: @form.component_constraint, manifest_name: "proposals")
|
42
|
+
if found_component.present?
|
43
|
+
resource = found_component&.participatory_space&.decidim_organization_id == @form.current_organization.id ? found_component : nil
|
44
|
+
end
|
45
|
+
end
|
46
|
+
resource
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -16,6 +16,12 @@ module Decidim
|
|
16
16
|
@user = user
|
17
17
|
end
|
18
18
|
|
19
|
+
# Executes the command. Broadcasts these events:
|
20
|
+
#
|
21
|
+
# - :ok when everything is valid.
|
22
|
+
# - :invalid if the form was not valid and we could not proceed.
|
23
|
+
#
|
24
|
+
# Returns nothing.
|
19
25
|
def call
|
20
26
|
return broadcast(:invalid) unless @form.valid?
|
21
27
|
return broadcast(:invalid) unless @user.organization == @template.organization
|
@@ -13,8 +13,6 @@ module Decidim
|
|
13
13
|
class ApplicationController < Decidim::Admin::ApplicationController
|
14
14
|
layout "decidim/admin/templates"
|
15
15
|
|
16
|
-
helper_method :template_types
|
17
|
-
|
18
16
|
register_permissions(::Decidim::Templates::Admin::ApplicationController,
|
19
17
|
::Decidim::Templates::Admin::Permissions,
|
20
18
|
::Decidim::Admin::Permissions)
|
@@ -22,12 +20,6 @@ module Decidim
|
|
22
20
|
def permission_class_chain
|
23
21
|
::Decidim.permissions_registry.chain_for(::Decidim::Templates::Admin::ApplicationController)
|
24
22
|
end
|
25
|
-
|
26
|
-
def template_types
|
27
|
-
@template_types ||= {
|
28
|
-
I18n.t("template_types.questionnaires", scope: "decidim.templates") => decidim_admin_templates.questionnaire_templates_path
|
29
|
-
}
|
30
|
-
end
|
31
23
|
end
|
32
24
|
end
|
33
25
|
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Templates
|
5
|
+
module Admin
|
6
|
+
class BlockUserTemplatesController < Decidim::Templates::Admin::ApplicationController
|
7
|
+
include Decidim::TranslatableAttributes
|
8
|
+
include Decidim::Paginable
|
9
|
+
|
10
|
+
def fetch
|
11
|
+
enforce_permission_to(:read, :template, template:)
|
12
|
+
|
13
|
+
response_object = {
|
14
|
+
template: translated_attribute(template.description)
|
15
|
+
}
|
16
|
+
|
17
|
+
respond_to do |format|
|
18
|
+
format.json do
|
19
|
+
render json: response_object.to_json
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def copy
|
25
|
+
enforce_permission_to :copy, :template
|
26
|
+
|
27
|
+
CopyTemplate.call(template, current_user) do
|
28
|
+
on(:ok) do
|
29
|
+
flash[:notice] = I18n.t("templates.copy.success", scope: "decidim.admin")
|
30
|
+
redirect_to action: :index
|
31
|
+
end
|
32
|
+
|
33
|
+
on(:invalid) do
|
34
|
+
flash[:alert] = I18n.t("templates.copy.error", scope: "decidim.admin")
|
35
|
+
redirect_to action: :index
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def destroy
|
41
|
+
enforce_permission_to(:destroy, :template, template:)
|
42
|
+
|
43
|
+
DestroyTemplate.call(template, current_user) do
|
44
|
+
on(:ok) do
|
45
|
+
flash[:notice] = I18n.t("templates.destroy.success", scope: "decidim.admin")
|
46
|
+
redirect_to action: :index
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def update
|
52
|
+
enforce_permission_to(:update, :template, template:)
|
53
|
+
@form = form(TemplateForm).from_params(params)
|
54
|
+
UpdateTemplate.call(template, @form, current_user) do
|
55
|
+
on(:ok) do
|
56
|
+
flash[:notice] = I18n.t("templates.update.success", scope: "decidim.admin")
|
57
|
+
redirect_to action: :index
|
58
|
+
end
|
59
|
+
|
60
|
+
on(:invalid) do |template|
|
61
|
+
@template = template
|
62
|
+
flash.now[:error] = I18n.t("templates.update.error", scope: "decidim.admin")
|
63
|
+
render action: :edit
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def edit
|
69
|
+
enforce_permission_to(:update, :template, template:)
|
70
|
+
@form = form(TemplateForm).from_model(template)
|
71
|
+
end
|
72
|
+
|
73
|
+
def create
|
74
|
+
enforce_permission_to :create, :template
|
75
|
+
|
76
|
+
@form = form(TemplateForm).from_params(params)
|
77
|
+
|
78
|
+
CreateBlockUserTemplate.call(@form) do
|
79
|
+
on(:ok) do
|
80
|
+
flash[:notice] = I18n.t("templates.create.success", scope: "decidim.admin")
|
81
|
+
redirect_to action: :index
|
82
|
+
end
|
83
|
+
|
84
|
+
on(:invalid) do
|
85
|
+
flash.now[:alert] = I18n.t("templates.create.error", scope: "decidim.admin")
|
86
|
+
render :new
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def new
|
92
|
+
enforce_permission_to :create, :template
|
93
|
+
@form = form(TemplateForm).instance
|
94
|
+
end
|
95
|
+
|
96
|
+
def index
|
97
|
+
enforce_permission_to :index, :templates
|
98
|
+
@templates = paginate(collection)
|
99
|
+
|
100
|
+
respond_to do |format|
|
101
|
+
format.html { render :index }
|
102
|
+
format.json do
|
103
|
+
term = params[:term]
|
104
|
+
|
105
|
+
@templates = search(term)
|
106
|
+
|
107
|
+
render json: @templates.map { |t| { value: t.id, label: translated_attribute(t.name) } }
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
private
|
113
|
+
|
114
|
+
def template
|
115
|
+
@template ||= collection.find(params[:id])
|
116
|
+
end
|
117
|
+
|
118
|
+
def collection
|
119
|
+
@collection ||= current_organization.templates.where(target: :user_block)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
@@ -14,7 +14,7 @@ module Decidim
|
|
14
14
|
helper_method :templates, :choose_template?
|
15
15
|
|
16
16
|
def templates
|
17
|
-
@templates = current_organization.templates.where(templatable_type:
|
17
|
+
@templates = current_organization.templates.where(templatable_type:)
|
18
18
|
@templates = @templates.where.not(id: params[:id]) if templates_path?
|
19
19
|
@templates
|
20
20
|
end
|