Sha256: 46c888626d7b42343e7f8f502e6dd54be8eaae015a756d65733bda9344cd40bf

Contents?: true

Size: 941 Bytes

Versions: 13

Compression:

Stored size: 941 Bytes

Contents

module Admin::Resources::DataTypes::TreeHelper

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

  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 => raw(expand_tree_into_select_field(@resource.roots, "parent_id")) }

    render "admin/templates/tree", locals
  end

  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

end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
brainsome_typus-4.0.0.beta13 app/helpers/admin/resources/data_types/tree_helper.rb
brainsome_typus-4.0.0.beta12 app/helpers/admin/resources/data_types/tree_helper.rb
brainsome_typus-4.0.0.beta11 app/helpers/admin/resources/data_types/tree_helper.rb
brainsome_typus-4.0.0.beta10 app/helpers/admin/resources/data_types/tree_helper.rb
brainsome_typus-4.0.0.beta9 app/helpers/admin/resources/data_types/tree_helper.rb
brainsome_typus-4.0.0.beta8 app/helpers/admin/resources/data_types/tree_helper.rb
brainsome_typus-4.0.0.beta7 app/helpers/admin/resources/data_types/tree_helper.rb
brainsome_typus-4.0.0.beta6 app/helpers/admin/resources/data_types/tree_helper.rb
brainsome_typus-4.0.0.beta5 app/helpers/admin/resources/data_types/tree_helper.rb
brainsome_typus-4.0.0.beta4 app/helpers/admin/resources/data_types/tree_helper.rb
brainsome_typus-4.0.0.beta3 app/helpers/admin/resources/data_types/tree_helper.rb
brainsome_typus-4.0.0.beta2 app/helpers/admin/resources/data_types/tree_helper.rb
brainsome_typus-4.0.0.beta1 app/helpers/admin/resources/data_types/tree_helper.rb