Module: JquerySortableTreeController::DefineVariablesMethod

Included in:
ExpandNode, Rebuild
Defined in:
app/controllers/jquery_sortable_tree_controller.rb

Instance Method Summary collapse

Instance Method Details

#idObject



15
16
17
# File 'app/controllers/jquery_sortable_tree_controller.rb', line 15

def id
  @id ||= params[:id].to_i
end

#move_toObject



61
62
63
# File 'app/controllers/jquery_sortable_tree_controller.rb', line 61

def move_to
  send("move_to_#{prev_next_parent}")
end

#move_to_nextObject



39
40
41
# File 'app/controllers/jquery_sortable_tree_controller.rb', line 39

def move_to_next
  @move_to_next ||= params[:tree_sort] == 'reversed' ? :move_to_right_of : :move_to_left_of
end

#move_to_nowhere?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'app/controllers/jquery_sortable_tree_controller.rb', line 51

def move_to_nowhere?
  parent_id.zero? && prev_id.zero? && next_id.zero?
end

#move_to_parentObject



43
44
45
# File 'app/controllers/jquery_sortable_tree_controller.rb', line 43

def move_to_parent
  :move_to_child_of
end

#move_to_prevObject



35
36
37
# File 'app/controllers/jquery_sortable_tree_controller.rb', line 35

def move_to_prev
  @move_to_prev ||= params[:tree_sort] == 'reversed' ? :move_to_left_of : :move_to_right_of
end

#next_idObject



31
32
33
# File 'app/controllers/jquery_sortable_tree_controller.rb', line 31

def next_id
  @next_id ||= params[:next_id].to_i
end

#nodeObject



69
70
71
# File 'app/controllers/jquery_sortable_tree_controller.rb', line 69

def node
  sortable_model.find(node_id)
end

#node_idObject



65
66
67
# File 'app/controllers/jquery_sortable_tree_controller.rb', line 65

def node_id
  send("#{prev_next_parent}_id")
end

#object_to_rebuildObject



47
48
49
# File 'app/controllers/jquery_sortable_tree_controller.rb', line 47

def object_to_rebuild
  self.sortable_model.find(id)
end

#parent_idObject



19
20
21
# File 'app/controllers/jquery_sortable_tree_controller.rb', line 19

def parent_id
  @parent_id ||= params[:parent_id].to_i
end

#prev_idObject



27
28
29
# File 'app/controllers/jquery_sortable_tree_controller.rb', line 27

def prev_id
  @prev_id ||= params[:prev_id].to_i
end

#prev_next_parentObject



55
56
57
58
59
# File 'app/controllers/jquery_sortable_tree_controller.rb', line 55

def prev_next_parent
  return 'prev' unless prev_id.zero?
  return 'next' unless next_id.zero?
  return 'parent' unless parent_id.zero?
end

#sortObject



23
24
25
# File 'app/controllers/jquery_sortable_tree_controller.rb', line 23

def sort
  @sort ||= params[:tree_sort] == 'reversed' ? 'reversed_nested_set' : 'nested_set'
end

#sortable_collectionObject



7
8
9
# File 'app/controllers/jquery_sortable_tree_controller.rb', line 7

def sortable_collection
  @sortable_collection ||= self.class.to_s.split(':').last.sub(/Controller/,'').underscore.downcase
end

#sortable_modelObject



3
4
5
# File 'app/controllers/jquery_sortable_tree_controller.rb', line 3

def sortable_model
  @sortable_model ||= self.class.to_s.split(':').last.sub(/Controller/, '').singularize.constantize
end

#the_define_common_variablesObject



11
12
13
# File 'app/controllers/jquery_sortable_tree_controller.rb', line 11

def the_define_common_variables
  ["@#{sortable_collection.singularize}", sortable_collection, sortable_model]
end