Module: Decidim::CheckBoxesTreeHelper
- Includes:
- SanitizeHelper
- Included in:
- Assemblies::FilterAssembliesHelper, Budgets::ApplicationHelper, Debates::ApplicationHelper, Initiatives::ApplicationHelper, Meetings::ApplicationHelper, Meetings::Directory::ApplicationHelper, ParticipatoryProcesses::ParticipatoryProcessHelper, Proposals::ApplicationHelper
- Defined in:
- decidim-core/app/helpers/decidim/check_boxes_tree_helper.rb
Overview
This helper include some methods for rendering a checkboxes tree input.
Defined Under Namespace
Instance Method Summary collapse
-
#check_boxes_tree_options(value, label, **options) ⇒ Object
This method returns a hash with the options for the checkbox and its label used in filters that uses checkboxes trees.
-
#filter_areas_values ⇒ Object
pending initiatives removal.
-
#filter_global_scopes_values ⇒ Object
pending initiatives removal.
-
#filter_origin_values ⇒ Object
Overwrite this method in your component helper to define origin values.
- #filter_taxonomy_values_children(children) ⇒ Object
- #filter_taxonomy_values_for(taxonomy_filter) ⇒ Object
- #filter_text_for(translation, id: nil) ⇒ Object
- #filter_tree_from_array(array) ⇒ Object
- #flat_filter_values(*types, **options) ⇒ Object
Methods included from SanitizeHelper
#decidim_escape_translated, #decidim_html_escape, #decidim_rich_text, #decidim_sanitize, #decidim_sanitize_admin, #decidim_sanitize_editor, #decidim_sanitize_editor_admin, #decidim_sanitize_newsletter, #decidim_sanitize_translated, #decidim_url_escape, included
Instance Method Details
#check_boxes_tree_options(value, label, **options) ⇒ Object
This method returns a hash with the options for the checkbox and its label used in filters that uses checkboxes trees
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'decidim-core/app/helpers/decidim/check_boxes_tree_helper.rb', line 10 def (value, label, **) parent_id = .delete(:parent_id) || "" object = .delete(:object) = { value:, label:, multiple: true, include_hidden: false, label_options: { "data-children-checkbox": parent_id, value:, for: "#{[:namespace]}_#{[:id]}" } } .merge!() # as taxonomies work with a nested array of values, we need to manually check if the value is checked matches = [:id]&.match(/^with_any_taxonomies_([0-9]+)__taxonomy-([0-9_]+)/) if matches.present? && object.respond_to?(:with_any_taxonomies) && object.with_any_taxonomies&.dig(matches[1]).is_a?(Array) [:checked] = object.with_any_taxonomies[matches[1]].include?(value.to_s) end if .delete(:is_root_check_box) == true [:label_options].merge!("data-global-checkbox": "") [:label_options].delete(:"data-children-checkbox") end end |
#filter_areas_values ⇒ Object
pending initiatives removal
86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'decidim-core/app/helpers/decidim/check_boxes_tree_helper.rb', line 86 def filter_areas_values areas_or_types = areas_for_select(current_organization) areas_values = if areas_or_types.first.is_a?(Decidim::Area) filter_areas(areas_or_types) else filter_areas_and_types(areas_or_types) end TreeNode.new( TreePoint.new("", t("decidim.core.application_helper.filter_area_values.all")), areas_values ) end |
#filter_global_scopes_values ⇒ Object
pending initiatives removal
81 82 83 |
# File 'decidim-core/app/helpers/decidim/check_boxes_tree_helper.rb', line 81 def filter_global_scopes_values filter_scopes_values_from(current_organization.scopes.top_level) end |
#filter_origin_values ⇒ Object
Overwrite this method in your component helper to define origin values.
59 60 61 |
# File 'decidim-core/app/helpers/decidim/check_boxes_tree_helper.rb', line 59 def filter_origin_values raise StandardError, "Not implemented" end |
#filter_taxonomy_values_children(children) ⇒ Object
71 72 73 74 75 76 77 78 |
# File 'decidim-core/app/helpers/decidim/check_boxes_tree_helper.rb', line 71 def filter_taxonomy_values_children(children) children.map do |id, hash| TreeNode.new( TreePoint.new(id, decidim_escape_translated(hash[:taxonomy].name).html_safe), filter_taxonomy_values_children(hash[:children]) ) end end |
#filter_taxonomy_values_for(taxonomy_filter) ⇒ Object
63 64 65 66 67 68 69 |
# File 'decidim-core/app/helpers/decidim/check_boxes_tree_helper.rb', line 63 def filter_taxonomy_values_for(taxonomy_filter) taxonomies = filter_taxonomy_values_children(taxonomy_filter.taxonomies) TreeNode.new( TreePoint.new(taxonomy_filter.root_taxonomy_id, t("decidim.core.application_helper.filter_taxonomy_values.all"), true), taxonomies ) end |
#filter_text_for(translation, id: nil) ⇒ Object
120 121 122 |
# File 'decidim-core/app/helpers/decidim/check_boxes_tree_helper.rb', line 120 def filter_text_for(translation, id: nil) content_tag(:span, translation, id:).html_safe + content_tag(:span) end |
#filter_tree_from_array(array) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 |
# File 'decidim-core/app/helpers/decidim/check_boxes_tree_helper.rb', line 101 def filter_tree_from_array(array) root_point = if array.first[0].blank? TreePoint.new(*array.shift) else TreePoint.new("", t("decidim.core.application_helper.filter_scope_values.all")) end TreeNode.new( root_point, array.map { |values| TreePoint.new(*values) } ) end |
#flat_filter_values(*types, **options) ⇒ Object
113 114 115 116 117 118 |
# File 'decidim-core/app/helpers/decidim/check_boxes_tree_helper.rb', line 113 def flat_filter_values(*types, **) scope = [:scope] types.map do |type| [type, t(type, scope:)] end end |