Module: Spree::Billing::SortableTreeHelper

Defined in:
app/helpers/spree/billing/sortable_tree_helper.rb

Instance Method Summary collapse

Instance Method Details

#build_sortable_tree(parent_resource, child_resource) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/helpers/spree/billing/sortable_tree_helper.rb', line 9

def build_sortable_tree(parent_resource, child_resource)
  child_resource_name = child_resource.class.name.demodulize.underscore
  descendants = []

  unless child_resource.leaf?
    child_resource.children.each do |child_item|
      descendants << build_sortable_tree(parent_resource, child_item) unless child_resource.leaf?
    end
  end

  row = sortable_tree_bar(parent_resource, child_resource)
  container = (:div, raw(descendants.join), data: { sortable_tree_parent_id_value: child_resource.id }) # rubocop:disable Rails/OutputSafety

  (:div, row + container,
              class: 'sortable-tree-item draggable removable-dom-element',
              data: {
                sortable_tree_resource_name_value: child_resource_name.singularize,
                sortable_tree_update_url_value: "/api/v2/platform/#{child_resource_name.pluralize}/#{child_resource.id}/reposition"
              }
  )
end

#sortable_tree_bar(parent_resource, child_resource) ⇒ Object



4
5
6
7
# File 'app/helpers/spree/billing/sortable_tree_helper.rb', line 4

def sortable_tree_bar(parent_resource, child_resource)
  partial_name = parent_resource.class.name.demodulize.underscore
  render "spree/billing/shared/sortable_tree/#{partial_name}", parent_resource: parent_resource, child_resource: child_resource
end