Add sub_menu to children
This commit is contained in:
parent
49e2eb0187
commit
26a50cc862
|
@ -43,8 +43,8 @@ class Admin::PagePartsController < ApplicationController
|
|||
def update
|
||||
@part = PagePart.find(params[:id])
|
||||
if @part.update_attributes(params[:page_part])
|
||||
set_children_sub_menu(@part) if @part.public_r_tag && @part.public_r_tag.eql?('sub_menu')
|
||||
flash.now[:notice] = t('admin.update_success_content')
|
||||
@part.save
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
redirect_to admin_page_url( @part.page )
|
||||
|
@ -87,4 +87,13 @@ class Admin::PagePartsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def set_children_sub_menu(part)
|
||||
part.page.children.each do |child|
|
||||
child_part = child.page_parts.detect{ |x| x.name.eql?(part.name) } rescue nil
|
||||
child_part.update_attributes(:kind => part.kind, :public_r_tag => part.public_r_tag, :public_r_tag_object_id => part.public_r_tag_object_id) rescue nil
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -28,8 +28,20 @@ class Page < Item
|
|||
|
||||
def create_parts
|
||||
page_design = self.design
|
||||
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)}
|
||||
page_design.layout.layout_parts.each do |layout_part|
|
||||
self.page_parts.new(:name => layout_part.name) unless self.page_parts.detect{|page_part| page_part.name.eql?(layout_part.name)}
|
||||
current_part = self.page_parts.detect{|page_part| page_part.name.eql?(layout_part.name)}
|
||||
current_part = self.page_parts.build(:name => layout_part.name) unless current_part
|
||||
if menu_part && current_part.name.eql?(menu_part.name)
|
||||
if current_part.new_record?
|
||||
current_part.kind = menu_part.kind
|
||||
current_part.public_r_tag = menu_part.public_r_tag
|
||||
current_part.public_r_tag_object_id = menu_part.public_r_tag_object_id
|
||||
else
|
||||
current_part.update_attributes(:kind => menu_part.kind, :public_r_tag => menu_part.public_r_tag, :public_r_tag_object_id => menu_part.public_r_tag_object_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ class PagePart
|
|||
field :kind
|
||||
field :public_r_tag
|
||||
field :public_r_tag_object_id, :default => nil
|
||||
field :public_r_tag_option, :default => nil
|
||||
field :widget_path
|
||||
|
||||
has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
|
||||
<span id='name_list'>
|
||||
<% if @r_tag.eql?('sub_menu') %>
|
||||
<%= f.select :public_r_tag_object_id, options_for_select([t(:horizontal), t(:vertical)], t(:horizontal)) %>
|
||||
<%= f.hidden_field :public_r_tag_object_id, :value => @part.page.id %>
|
||||
<%#= f.select :public_r_tag_object_id, options_for_select([t(:horizontal), t(:vertical)], t(:horizontal)) %>
|
||||
<% else %>
|
||||
<%= f.select :public_r_tag_object_id, options_from_collection_for_select(@tag_objects, :id, :title, :selected => @part.public_r_tag_object_id) %>
|
||||
<% end %>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<% if @r_tag.eql?('sub_menu') %>
|
||||
$('#name_list select').html("<%= j options_for_select(t(:horizontal) => :horizontal, t(:vertical) => :vertical) %>")
|
||||
// $('#name_list select').html("<%= j options_for_select(t(:horizontal) => :horizontal, t(:vertical) => :vertical) %>")
|
||||
<% else %>
|
||||
$('#name_list select').html("<%= j options_from_collection_for_select(@tag_objects, :id, :title) %>")
|
||||
<% end %>
|
|
@ -32,7 +32,7 @@ module ParserBackEnd
|
|||
parse_sub_menu(body, page, true)
|
||||
|
||||
public_r_tags.each do |tag|
|
||||
send("parse_#{tag}s", body, page,id)
|
||||
send("parse_#{tag}s", body, page, id, true)
|
||||
end
|
||||
|
||||
body.to_html
|
||||
|
|
|
@ -36,7 +36,7 @@ module ParserCommon
|
|||
end
|
||||
|
||||
# ad_banners
|
||||
def parse_ad_banners(body = nil, page = nil, id = nil)
|
||||
def parse_ad_banners(body = nil, page = nil, id = nil, edit=nil)
|
||||
body.css('ad_banner').each do |banner|
|
||||
res = ''
|
||||
ad_banner = AdBanner.find(banner["id"]) rescue nil
|
||||
|
@ -71,7 +71,7 @@ module ParserCommon
|
|||
end
|
||||
|
||||
# page_images
|
||||
def parse_images(body, page)
|
||||
def parse_images(body, page, id = nil, edit=nil)
|
||||
body.css('.page_image').each do |page_image|
|
||||
# image = page.custom_images.detect{|image| image.name.eql?(tag.attr['name']) }
|
||||
# image = page.design.custom_images.detect{|image| image.name.eql?(tag.attr['name']) } unless image
|
||||
|
@ -98,15 +98,16 @@ module ParserCommon
|
|||
end
|
||||
|
||||
# sub_menus
|
||||
def parse_sub_menus(body = nil, page = nil, id = nil)
|
||||
def parse_sub_menus(body = nil, page = nil, id = nil, edit=nil)
|
||||
body.css('sub_menu').each do |sub_menu|
|
||||
menu_page = Page.find(sub_menu['id'])
|
||||
res = ''
|
||||
res << "<div class='category_list'>"
|
||||
res << "<h3 class='h3'>#{page.i18n_variable[I18n.locale]}</h3>"
|
||||
res << "<h3 class='h3'>#{menu_page.i18n_variable[I18n.locale]}</h3>"
|
||||
res << "<ul class='list'>"
|
||||
page.ordered_and_visible_children.each do |child|
|
||||
res << "<li>"
|
||||
res << "<a href='#{child.full_name}'>#{child.i18n_variable[I18n.locale]}</a>"
|
||||
menu_page.ordered_and_visible_children.each do |child|
|
||||
res << "<li class='#{page.id.eql?(child.id) ? 'active' : nil}'>"
|
||||
res << "<a href='#{edit ? admin_page_path(child.id) : child.full_name}'>#{child.i18n_variable[I18n.locale]}</a>"
|
||||
res << "</li>"
|
||||
end
|
||||
res << "</ul>"
|
||||
|
|
Loading…
Reference in New Issue