class ActiveadminDraggable::DraggableListItem
Public Class Methods
move(klass, id, left_id)
click to toggle source
method that given any resource class changes possition of an item according to params passed by javascript sorting action
# File lib/activeadmin_draggable/draggable_list_item.rb, line 7 def self.move(klass, id, left_id) left_id = left_id.to_i dropped_item = klass.find(id) if left_id != 0 item_to_insert_at = klass.find(left_id) else item_to_insert_at = nil end item = DraggableListItem.new(dropped_item) item.move_to(item_to_insert_at) end
new(dropped_item)
click to toggle source
# File lib/activeadmin_draggable/draggable_list_item.rb, line 22 def initialize(dropped_item) @dropped_item = dropped_item end
Public Instance Methods
move_to(item_to_insert_at)
click to toggle source
# File lib/activeadmin_draggable/draggable_list_item.rb, line 26 def move_to(item_to_insert_at) if item_to_insert_at @item_to_insert_at = item_to_insert_at if moving_up? @dropped_item.insert_at(@item_to_insert_at.position) @dropped_item.increment_position else @dropped_item.insert_at(@item_to_insert_at.position) end else @dropped_item.move_to_top end end
Private Instance Methods
moving_up?()
click to toggle source
# File lib/activeadmin_draggable/draggable_list_item.rb, line 42 def moving_up? @item_to_insert_at.position < @dropped_item.position end