2019-09-05 07:15:45 +00:00
|
|
|
class ArchiveSortOrder
|
|
|
|
include Mongoid::Document
|
|
|
|
field :sort_order, :type => Boolean # true => desc , false => asc
|
2020-02-11 15:38:10 +00:00
|
|
|
after_initialize do |record|
|
|
|
|
if(!record.new_record? && record.sort_order.class != FalseClass && record.sort_order.class != TrueClass)
|
|
|
|
record.sort_order = true
|
|
|
|
record.save
|
|
|
|
elsif(!record.new_record?)
|
|
|
|
@module_app = ModuleApp.where(:key=>'archive').first
|
|
|
|
if !@module_app.nil?
|
|
|
|
@asc = @module_app.asc rescue nil
|
|
|
|
if !@asc.nil?
|
|
|
|
record.sort_order = @asc
|
|
|
|
record.save
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
after_save do |record|
|
|
|
|
@module_app = ModuleApp.where(:key=>'archive').first
|
|
|
|
if !@module_app.nil?
|
|
|
|
@sort_order = record.sort_order rescue nil
|
|
|
|
if !@asc.nil?
|
|
|
|
if !@module_app.attributes[:asc].nil?
|
|
|
|
@module_app.asc = @sort_order
|
|
|
|
@module_app.save
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-09-05 07:15:45 +00:00
|
|
|
end
|