module RailsAdminNestable::Helper

Public Instance Methods

nested_family(tree_nodes = []) click to toggle source
# File lib/rails_admin_nestable/helper.rb, line 21
def nested_family(tree_nodes = [])
  return if tree_nodes.nil?
  tree_nodes.map do |tree_node, sub_tree_nodes|
    li_classes = 'dd-item dd3-item'

    content_tag :li, class: li_classes, data: { id: tree_node.id, 'dragable': 'false' } do
      output = content_tag :div, 'drag', class: 'dd-handle dd3-handle'
      output += content_tag :div, class: 'dd3-content' do
        content = link_to @model_config.with(object: tree_node).object_label, edit_path(@abstract_model, tree_node.id)
        content += content_tag :div, action_links(@abstract_model, tree_node), class: 'pull-right links'
      end

      child_output = ""
      card_children = @child_model.where(@foreign_key => tree_node.id.to_s)
      card_children.each do |card|
        child_output += content_tag :li, class: 'dd-item dd3-item', data: { id: card.id, 'group': card.id  } do
          levelone = content_tag :div, 'drag', class: 'dd-handle dd3-handle'
          levelone += content_tag :div, class: 'dd3-content' do
            card_abstract = RailsAdmin::AbstractModel.new(to_model_name(@child_model.name))
            # resize with dragonfly
            if !card.thumbnail.nil?
              thumbnail_tag = image_tag(card.thumbnail.thumb('25x25>').url)
            else
              thumbnail_tag = ""
            end
            content = link_to thumbnail_tag + card.punchline, edit_path(card_abstract, card.id)
            content += content_tag :div, action_links(card_abstract, card), class: 'pull-right links'
          end
        end
      end

      output+= content_tag :ol, child_output.html_safe, class: 'dd-list' if !child_output.empty?
      output
    end
  end.join.html_safe
end
nested_tree_nodes(tree_nodes = []) click to toggle source
# File lib/rails_admin_nestable/helper.rb, line 5
def nested_tree_nodes(tree_nodes = [])
  tree_nodes.map do |tree_node, sub_tree_nodes|
    li_classes = 'dd-item dd3-item'
    content_tag :li, class: li_classes, :'data-id' => tree_node.id do
      output = content_tag :div, 'drag', class: 'dd-handle dd3-handle'
      output += content_tag :div, class: 'dd3-content' do
        content = link_to @model_config.with(object: tree_node).object_label, edit_path(@abstract_model, tree_node.id)
        content += content_tag :div, action_links(tree_node), class: 'pull-right links'
      end

      output+= content_tag :ol, nested_tree_nodes(sub_tree_nodes), class: 'dd-list' if sub_tree_nodes && sub_tree_nodes.any?
      output
    end
  end.join.html_safe
end
to_model_name(param) click to toggle source
# File lib/rails_admin_nestable/helper.rb, line 64
def to_model_name(param)
  param.split('~').collect(&:camelize).join('::')
end
tree_max_depth() click to toggle source
# File lib/rails_admin_nestable/helper.rb, line 68
def tree_max_depth
  @nestable_conf.options[:max_depth] || 'false'
end