Module: Decidim::Templates::Admin::TemplatesHelper

Defined in:
decidim-templates/app/helpers/decidim/templates/admin/templates_helper.rb

Overview

Custom helpers, scoped to the templates engine.

Instance Method Summary collapse

Instance Method Details

#select_template(form, templates) ⇒ Object


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'decidim-templates/app/helpers/decidim/templates/admin/templates_helper.rb', line 9

def select_template(form, templates)
  prompt_options = {
    url: decidim_admin_templates.questionnaire_templates_url(format: :json),
    change_url: decidim_admin_templates.preview_questionnaire_templates_url(format: :js),
    placeholder: t("placeholder", scope: "decidim.templates.admin.questionnaire_templates.choose")
  }

  default_options = templates.last(5).map { |questionnaire_template| { value: questionnaire_template.id, label: translated_attribute(questionnaire_template.name) } }

  form.autocomplete_select(
    :questionnaire_template_id,
    false,
    {
      multiple: false,
      label: t("label", scope: "decidim.templates.admin.questionnaire_templates.choose"),
      default_options: default_options
    },
    prompt_options
  )
end