Sha256: 9ac375cc809af8612a655b3bfb87bd5e6679de8ac832e815f88496bcfa4c18bd

Contents?: true

Size: 1.34 KB

Versions: 8

Compression:

Stored size: 1.34 KB

Contents

module Puffer
  class TreeBase < Puffer::Base
    unloadable

    helper :puffer_tree

    define_fieldset :tree, :fallbacks => :index

    def index
      return super if params[:search]
      @records = resource.collection_scope.includes(resource.includes)
      if session[:expanded].present?
        @records = @records.where(["depth in (0, 1) or parent_id in (#{session[:expanded].join(', ')})"]).arrange
      else
        @records = @records.with_depth([0, 1]).arrange
      end
      render 'tree'
    end

    member do
      get :inherit, :label => 'inherit'
      get :expand, :display => false
      get :collapse, :display => false
    end

    def inherit
      @parent = resource.member
      @record = @parent.children.new
      render 'new'
    end

    def expand
      @parent = resource.member
      session[:expanded] ||= []
      session[:expanded].push params[:id] if @parent
      session[:expanded].uniq!
      @records = @parent.self_and_descendants.where(:parent_id => [@parent.parent_id] + session[:expanded]).includes(resource.includes).arrange
      render 'toggle'
    end

    def collapse
      @parent = resource.member
      session[:expanded] ||= []
      session[:expanded].delete params[:id]
      @records = resource.collection_scope.where(:id => [@parent.id]).includes(resource.includes).arrange
      render 'toggle'
    end

  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
puffer-0.0.29 app/controllers/puffer/tree_base.rb
puffer-0.0.28 app/controllers/puffer/tree_base.rb
puffer-0.0.26 app/controllers/puffer/tree_base.rb
puffer-0.0.25 app/controllers/puffer/tree_base.rb
puffer-0.0.24 app/controllers/puffer/tree_base.rb
puffer-0.0.23 app/controllers/puffer/tree_base.rb
puffer-0.0.22 app/controllers/puffer/tree_base.rb
puffer-0.0.21 app/controllers/puffer/tree_base.rb