archive module: sort for backend/frontend. move get_sorted_and_filtered from orbit_backend_controller.rb to application_controller.rb

This commit is contained in:
iCross committed 2013-06-06 19:20:21 +08:00
1 parent dd206437d8
commit c63ac751ea
15 files changed
+352 -286

No files matched your search

+34
View File
@@ -0,0 +1,34 @@
module Mongoid
module Sortable
extend ActiveSupport::Concern
included do
field :sort_number, type: Integer
after_initialize :set_sort_number
end
module ClassMethods
def default_sort(sorted = true)
if !sorted
asc(:sort_number)
else
asc
end
end
end
private
def set_sort_number
if self.sort_number.nil?
last_record = self.class.desc(:sort_number).first
if last_record
self.sort_number = (last_record.sort_number + 10) / 10 * 10
else
self.sort_number = 10
end
end
end
end
end