Class: Puffer::TreeBase
- Inherits:
-
Base
- Object
- ApplicationController
- Base
- Puffer::TreeBase
show all
- Defined in:
- lib/puffer/backends/controllers/tree_base.rb
Instance Method Summary
collapse
Methods inherited from Base
#create, #destroy, #edit, #event, #new, #show, #update
Instance Method Details
#collapse ⇒ Object
40
41
42
43
44
45
46
|
# File 'lib/puffer/backends/controllers/tree_base.rb', line 40
def collapse
@parent = resource.member
session[:expanded] ||= []
session[:expanded].delete params[:id]
@records = resource.model.to_adapter.filter(resource.collection_scope.where(:id => [@parent.id]), tree_fields).arrange
render 'toggle'
end
|
#expand ⇒ Object
31
32
33
34
35
36
37
38
|
# File 'lib/puffer/backends/controllers/tree_base.rb', line 31
def expand
@parent = resource.member
session[:expanded] ||= []
session[:expanded].push params[:id] if @parent
session[:expanded].uniq!
@records = resource.model.to_adapter.filter(@parent.self_and_descendants.where(:parent_id => [@parent.parent_id] + session[:expanded]), tree_fields).arrange
render 'toggle'
end
|
#index ⇒ Object
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/puffer/backends/controllers/tree_base.rb', line 8
def index
return super if puffer_filters.any?
@records = resource.collection_scope
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
|
#inherit ⇒ Object
25
26
27
28
29
|
# File 'lib/puffer/backends/controllers/tree_base.rb', line 25
def inherit
@parent = resource.member
@record = @parent.children.new
render 'new'
end
|