Module: Concerns::Sortable

Extended by:
ActiveSupport::Concern
Included in:
Attachment, ContentColumn, ContentRow, EmailTemplate, FormField, Image, NavigationItem, Page
Defined in:
app/models/concerns/sortable.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#set_position(new_position, parent_id = nil) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'app/models/concerns/sortable.rb', line 19

def set_position(new_position, parent_id = nil)
  if respond_to?(:draggable?) && !draggable? || position == new_position.to_i
    return false
  end

  if respond_to?(:parentable?) && parentable?
    update_attribute :parent_id, parent_id
  end

  set_list_position new_position
end