Sha256: b3240dbfd310fb4d7ddc3c8d38b9c3355f0beadbaa3311baef223b02fa60cba7

Contents?: true

Size: 1.5 KB

Versions: 2

Compression:

Stored size: 1.5 KB

Contents

module ViewMixins::Breadcrumb
  def breadcrumb_for(*args)
    # ToDo dodělat caching tohoto, invalidovat budu pokud nastane SAVE u OBJECT
    breadcrumb = []
    args.each do |object|
      if !object.blank?
        if is_tree_node?(object)
          tree_node = object
          unless tree_node.blank?
            bread_crumb_load_tree_recursive(breadcrumb, tree_node)
          end
        elsif object.respond_to?(:tree_nodes)
          if !object.tree_nodes.blank? && !object.tree_nodes.first.blank? && is_tree_node?(object.tree_nodes.first)
            tree_node = object.tree_nodes.first if !object.tree_nodes.blank? && !object.tree_nodes.first.blank?
            unless tree_node.blank?
              bread_crumb_load_tree_recursive(breadcrumb, tree_node)
            end
          end
        elsif object.kind_of?(Hash)
          breadcrumb << object
        elsif object.kind_of?(Array)
          object.each do |o|
            breadcrumb << o
          end
        end
      end
    end
    render :partial => '/helpers/build_breadcrumb', :layout => false, :locals => {:breadcrumb => breadcrumb}
  end

  def bread_crumb_load_tree_recursive(breadcrumb, tree_node)
    unless tree_node.blank?
      if tree_node.parent_node_id > 0
        bread_crumb_load_tree_recursive(breadcrumb, tree_node.parent_node)
      end
      breadcrumb << tree_node
    end
  end

  def is_tree_node?(object)
    false
    #object.kind_of?(Intranet::TreeNode) #|| object.kind_of?(Web::TreeNode) || object.kind_of?(Organizer::TreeNode)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
it-logica-application-backbone-0.1.7 lib/view_mixins/breadcrumb.rb
it-logica-application-backbone-0.1.6 lib/view_mixins/breadcrumb.rb