add change sort_number and sort_order to synchronize with catefory and module_app

This commit is contained in:
BOHUNG 2020-02-11 23:38:10 +08:00
parent 23a955e0d6
commit 32fafce8aa
3 changed files with 57 additions and 0 deletions

View File

@ -2,4 +2,33 @@ class ArchiveCategory
include Mongoid::Document include Mongoid::Document
field :category_id, type: String field :category_id, type: String
field :sort_number, type: Integer field :sort_number, type: Integer
after_initialize do |record|
if(!record.new_record? && record.sort_number.class != Fixnum)
record.sort_number = 0
record.save
elsif(!record.new_record?)
@category = Category.find(record.category_id) rescue nil
if !@category.nil?
@sort_number = @category.sort_number rescue nil
if !@sort_number.nil?
record.sort_number = @sort_number
record.save
end
else
record.destroy
end
end
end
after_save do |record|
@category = Category.find(record.category_id) rescue nil
if !@category.nil?
@sort_number = record.sort_number rescue nil
if !@sort_number.nil?
if !@category.attributes[:sort_number].nil?
@category.sort_number = @sort_number
@category.save
end
end
end
end
end end

View File

@ -1,4 +1,31 @@
class ArchiveSortOrder class ArchiveSortOrder
include Mongoid::Document include Mongoid::Document
field :sort_order, :type => Boolean # true => desc , false => asc field :sort_order, :type => Boolean # true => desc , false => asc
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
end end

View File

@ -41,6 +41,7 @@ $('.category_sort_number_form').ready(function(){
</thead> </thead>
<tbody style='line-height: 4;'> <tbody style='line-height: 4;'>
<% @cats.each do |cat| %> <% @cats.each do |cat| %>
<% next if cat[0].nil?%>
<tr> <tr>
<td style='padding-right: 10px;'> <td style='padding-right: 10px;'>
<% all_locales.each_with_index do |locale,index| %> <% all_locales.each_with_index do |locale,index| %>