Sha256: d3fa467f6a547af96eaf98eb2e26da18e5e47f00ec34ed4ef2896ce546526cd1

Contents?: true

Size: 936 Bytes

Versions: 12

Compression:

Stored size: 936 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 => 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

12 entries across 12 versions & 1 rubygems

Version Path
typus-3.1.10 app/helpers/admin/resources/data_types/tree_helper.rb
typus-3.1.9 app/helpers/admin/resources/data_types/tree_helper.rb
typus-3.1.8 app/helpers/admin/resources/data_types/tree_helper.rb
typus-3.1.7 app/helpers/admin/resources/data_types/tree_helper.rb
typus-3.1.6 app/helpers/admin/resources/data_types/tree_helper.rb
typus-3.1.5 app/helpers/admin/resources/data_types/tree_helper.rb
typus-3.1.4 app/helpers/admin/resources/data_types/tree_helper.rb
typus-3.1.3 app/helpers/admin/resources/data_types/tree_helper.rb
typus-3.1.2 app/helpers/admin/resources/data_types/tree_helper.rb
typus-3.1.1 app/helpers/admin/resources/data_types/tree_helper.rb
typus-3.1.0 app/helpers/admin/resources/data_types/tree_helper.rb
typus-3.1.0.rc19 app/helpers/admin/resources/data_types/tree_helper.rb