Module: Admin::Resources::DataTypes::TreeHelper

Defined in:
app/helpers/admin/resources/data_types/tree_helper.rb

Instance Method Summary collapse

Instance Method Details

#expand_tree_into_select_field(items, attribute) ⇒ Object



17
18
19
20
21
22
23
24
# File 'app/helpers/admin/resources/data_types/tree_helper.rb', line 17

def expand_tree_into_select_field(items, attribute)
  String.new.tap do |html|
    items.each do |item|
      html << %{<option #{"selected" if @item.send(attribute) == item.id} value="#{item.id}">#{"&nbsp;" * item.ancestors.size * 2} #{item.to_label}</option>\n}
      html << expand_tree_into_select_field(item.children, attribute) unless item.children.empty?
    end
  end
end

#table_tree_field(attribute, item) ⇒ Object



3
4
5
# File 'app/helpers/admin/resources/data_types/tree_helper.rb', line 3

def table_tree_field(attribute, item)
  item.parent ? item.parent.to_label : mdash
end

#typus_tree_field(attribute, form) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'app/helpers/admin/resources/data_types/tree_helper.rb', line 7

def typus_tree_field(attribute, form)
  locals = { :attribute => attribute,
             :attribute_id => "#{@resource.table_name}_#{attribute}",
             :form => form,
             :label_text => @resource.human_attribute_name(attribute),
             :values => expand_tree_into_select_field(@resource.roots, "parent_id") }

  render "admin/templates/tree", locals
end