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
- #ordered_scopes_descendants(root = nil) ⇒ Object
- #ordered_scopes_descendants_for_select(root = nil) ⇒ Object
-
#scopes_select_field(form, name, root: false, options: {}, html_options: {}) ⇒ Object
Renders a scopes select field in a form.
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| [" #{" " * 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: {}) = .merge(include_blank: I18n.t("decidim.scopes.prompt")) unless .has_key?(:include_blank) form.select( name, ordered_scopes_descendants_for_select(root), , ) end |