Fix structure reorder position
This commit is contained in:
parent
ba8da9b6bb
commit
43cf6b70b7
|
@ -27,7 +27,7 @@ class Admin::ItemsController < OrbitBackendController
|
|||
|
||||
def update_position
|
||||
item = Item.find(params[:id])
|
||||
item.shift_to(params[:parent_id], params[:position])
|
||||
item.shift_to(params[:parent_id], params[:position].to_i - 1)
|
||||
render :nothing => true
|
||||
end
|
||||
|
||||
|
|
|
@ -45,9 +45,10 @@ class Item
|
|||
end
|
||||
|
||||
def shift_to(new_parent, position)
|
||||
unless self.parent_id.to_s.eql?(new_parent) && self.position.eql?(position.to_i)
|
||||
position = position.to_i
|
||||
unless self.parent_id.to_s.eql?(new_parent) && self.position == position
|
||||
new_parent = Item.find(new_parent)
|
||||
current_position_sibling = find_by_parent_and_position(new_parent, position.to_i)
|
||||
current_position_sibling = find_by_parent_and_position(new_parent, position)
|
||||
if current_position_sibling
|
||||
move_above(current_position_sibling)
|
||||
elsif self.parent != new_parent
|
||||
|
|
Loading…
Reference in New Issue