Module: Decidim::Initiatives::ScopesHelper

Includes:
DecidimFormHelper, TranslatableAttributes
Included in:
ApplicationHelper
Defined in:
decidim-initiatives/app/helpers/decidim/initiatives/scopes_helper.rb

Overview

A Helper to render scopes, including a global scope, for forms.

Instance Method Summary collapse

Methods included from TranslatableAttributes

#attachment?, #default_locale?

Methods included from DecidimFormHelper

#areas_for_select, #base_error_messages, #decidim_form_for, #decidim_form_slug_url, #editor_field_tag, #form_field_has_error?, #form_required_explanation, #name_with_locale, #tab_element_class_for, #translated_field_tag

Instance Method Details

#ordered_scopes_descendants(root = nil) ⇒ Object



27
28
29
30
31
32
33
34
# File 'decidim-initiatives/app/helpers/decidim/initiatives/scopes_helper.rb', line 27

def ordered_scopes_descendants(root = nil)
  root = try(:current_participatory_space)&.scope if root == false
  if root.present?
    root.descendants
  else
    current_organization.scopes
  end.sort { |a, b| a.part_of.reverse <=> b.part_of.reverse }
end

#ordered_scopes_descendants_for_select(root = nil) ⇒ Object



36
37
38
39
40
# File 'decidim-initiatives/app/helpers/decidim/initiatives/scopes_helper.rb', line 36

def ordered_scopes_descendants_for_select(root = nil)
  ordered_scopes_descendants(root).map do |scope|
    [" #{"&nbsp;" * 4 * (scope.part_of.count - 1)} #{translated_attribute(scope.name)}".html_safe, scope&.id]
  end
end

#scopes_select_field(form, name, root: false, options: {}, html_options: {}) ⇒ Object

Renders a scopes select field in a form. form - FormBuilder object name - attribute name options - An optional Hash with options:

Returns nothing.



16
17
18
19
20
21
22
23
24
25
# File 'decidim-initiatives/app/helpers/decidim/initiatives/scopes_helper.rb', line 16

def scopes_select_field(form, name, root: false, options: {}, html_options: {})
  options = options.merge(include_blank: I18n.t("decidim.scopes.prompt")) unless options.has_key?(:include_blank)

  form.select(
    name,
    ordered_scopes_descendants_for_select(root),
    options,
    html_options
  )
end