Module: TheSortableTreeController::ReversedRebuild

Includes:
DefineVariablesMethod
Defined in:
app/controllers/the_sortable_tree_controller.rb

Overview

Rebuild

Instance Method Summary collapse

Methods included from DefineVariablesMethod

#the_define_common_variables

Instance Method Details

#rebuildObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/controllers/the_sortable_tree_controller.rb', line 44

def rebuild
  id        = !params[:id].nil? ? params[:id].sub("_menuitem","") : ""
  parent_id = !params[:parent_id].nil? ? params[:parent_id].sub("_menuitem","") : ""
  prev_id   = !params[:prev_id].nil? ? params[:prev_id].sub("_menuitem","") : ""
  next_id   = !params[:next_id].nil? ? params[:next_id].sub("_menuitem","") : ""

  render :text => "Do nothing" and return if parent_id.empty? && prev_id.empty? && next_id.empty?

  variable, collection, klass = self.the_define_common_variables
  variable = self.instance_variable_set(variable, klass.find(id))

  if prev_id.empty? && next_id.empty?
    variable.move_to_child_of klass.find(parent_id)
  elsif !prev_id.empty?
    variable.move_to_left_of klass.find(prev_id)
  elsif !next_id.empty?
    variable.move_to_right_of klass.find(next_id)
  end

  render(:nothing => true)
end