Skip to content

Commit

Permalink
fix: Scopes can't be updated in BO (#640)
Browse files Browse the repository at this point in the history
Co-authored-by: Lucie Grau <[email protected]>
  • Loading branch information
AyakorK and luciegrau authored Nov 28, 2024
1 parent cfe65a9 commit 3271771
Showing 1 changed file with 2 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ module Decidim
module SimpleProposal
module ScopesHelperOverride
extend ActiveSupport::Concern

included do
def scopes_picker_field(form, name, root: false, options: { checkboxes_on_top: true, sort_by_weight: true })
def scopes_picker_field(form, name, root: false, options: { checkboxes_on_top: true })
options.merge!(selected: selected_scope(form)) if selected_scope(form)
form.select(name, simple_scope_options(root: root, options: options), include_blank: t("decidim.scopes.prompt"))
end
Expand All @@ -23,11 +22,9 @@ def selected_scope(form)
def simple_scope_options(root: false, options: {})
scopes_array = []
roots = root ? root.children : ancestors

roots.sort_by { |ancestor| ancestor.weight || 0 }.each do |ancestor|
children_after_parent(ancestor, scopes_array, "")
end

selected = options.has_key?(:selected) ? options[:selected] : params.dig(:filter, :decidim_scope_id)
options_for_select(scopes_array, selected)
end
Expand All @@ -37,7 +34,7 @@ def ancestors
end

def children_after_parent(ancestor, array, prefix)
array << ["#{prefix} #{translated_attribute(ancestor.name)}", ancestor.id, ancestor.weight]
array << ["#{prefix} #{translated_attribute(ancestor.name)}", ancestor.id]
ancestor.children.sort_by { |child| child.weight || 0 }.each do |child|
children_after_parent(child, array, "#{prefix}-")
end
Expand Down

0 comments on commit 3271771

Please sign in to comment.