Sha256: 7257fc79ce030f2519db88f0b335c8169ff1dbe17914ff905d3af63193fbee01

Contents?: true

Size: 739 Bytes

Versions: 65

Compression:

Stored size: 739 Bytes

Contents

# If you want to use this concern, you need to add an integer field 'position'
# to the model.
module Concerns
  module Sortable
    extend ActiveSupport::Concern

    included do
      acts_as_list
      default_scope ->{ order(:position) }
    end

    module ClassMethods
      def sortable(*args)
        acts_as_list *args
      end
    end

    # TODO (Dave) - https://github.com/udongo/udongo/issues/20
    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
  end
end

Version data entries

65 entries across 65 versions & 1 rubygems

Version Path
udongo-7.9.0 app/models/concerns/sortable.rb
udongo-7.8.1 app/models/concerns/sortable.rb
udongo-7.8.0 app/models/concerns/sortable.rb
udongo-7.7.2 app/models/concerns/sortable.rb
udongo-7.7.1 app/models/concerns/sortable.rb
udongo-7.7.0 app/models/concerns/sortable.rb
udongo-7.6.2 app/models/concerns/sortable.rb
udongo-7.6.1 app/models/concerns/sortable.rb
udongo-7.6.0 app/models/concerns/sortable.rb
udongo-7.5.1 app/models/concerns/sortable.rb
udongo-7.5.0 app/models/concerns/sortable.rb
udongo-7.4.2 app/models/concerns/sortable.rb
udongo-7.4.1 app/models/concerns/sortable.rb
udongo-7.4.0 app/models/concerns/sortable.rb
udongo-7.3.5 app/models/concerns/sortable.rb
udongo-7.3.4 app/models/concerns/sortable.rb
udongo-7.3.3 app/models/concerns/sortable.rb
udongo-7.3.2 app/models/concerns/sortable.rb
udongo-7.3.1 app/models/concerns/sortable.rb
udongo-7.2.1 app/models/concerns/sortable.rb