Fix order in structure
This commit is contained in:
parent
5b289bc1d2
commit
fa83dbf791
|
@ -47,10 +47,10 @@ class Item
|
||||||
new_parent = Item.find(new_parent)
|
new_parent = Item.find(new_parent)
|
||||||
current_position_sibling = find_by_parent_and_position(new_parent, position.to_i)
|
current_position_sibling = find_by_parent_and_position(new_parent, position.to_i)
|
||||||
if current_position_sibling
|
if current_position_sibling
|
||||||
current_position_sibling.at_bottom? ? move_below(current_position_sibling) : move_above(current_position_sibling)
|
move_above(current_position_sibling)
|
||||||
elsif self.parent != new_parent
|
elsif self.parent != new_parent
|
||||||
self.parent = new_parent
|
self.parent = new_parent
|
||||||
save!
|
save
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -24,14 +24,12 @@ class Page < Item
|
||||||
has_many :page_metas, :autosave => true, :dependent => :destroy
|
has_many :page_metas, :autosave => true, :dependent => :destroy
|
||||||
accepts_nested_attributes_for :page_parts, :allow_destroy => true
|
accepts_nested_attributes_for :page_parts, :allow_destroy => true
|
||||||
|
|
||||||
before_save :delete_empty_frontend_field
|
|
||||||
before_save :create_parts, if: Proc.new { |page| page.new_record? || page.design_id_changed? }
|
before_save :create_parts, if: Proc.new { |page| page.new_record? || page.design_id_changed? }
|
||||||
after_save :generate_html
|
before_save :delete_empty_frontend_field, :generate_html
|
||||||
|
|
||||||
# protected
|
protected
|
||||||
|
|
||||||
def create_parts
|
def create_parts
|
||||||
|
|
||||||
page_design = self.design
|
page_design = self.design
|
||||||
parent = self.parent
|
parent = self.parent
|
||||||
menu_part = parent.page_parts.detect{|page_part| page_part.kind.eql?('public_r_tag') && page_part.public_r_tag.eql?('sub_menu') && page_part.public_r_tag_object_id.eql?(parent.id.to_s)} if parent
|
menu_part = parent.page_parts.detect{|page_part| page_part.kind.eql?('public_r_tag') && page_part.public_r_tag.eql?('sub_menu') && page_part.public_r_tag_object_id.eql?(parent.id.to_s)} if parent
|
||||||
|
@ -73,10 +71,7 @@ class Page < Item
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_html
|
def generate_html
|
||||||
Page.without_callback(:save, :after, :generate_html) do
|
self.content_translations = parse_page_noko(self, Site.first)
|
||||||
self.content_translations = parse_page_noko(self, Site.first)
|
|
||||||
self.save
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -350,4 +350,16 @@ namespace :migrate do
|
||||||
ModuleApp.new.from_json(File.open("#{Rails.root}/vendor/built_in_modules/gallery/gallery.json").read).save
|
ModuleApp.new.from_json(File.open("#{Rails.root}/vendor/built_in_modules/gallery/gallery.json").read).save
|
||||||
end
|
end
|
||||||
|
|
||||||
|
task :reorder_items => :environment do
|
||||||
|
reorder_children(Item.root)
|
||||||
|
end
|
||||||
|
|
||||||
|
def reorder_children(parent)
|
||||||
|
parent.children.each_with_index do |child, i|
|
||||||
|
child.position = i
|
||||||
|
child.save
|
||||||
|
reorder_children(child) if child.children
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue