diff --git a/app/controllers/admin/page_parts_controller.rb b/app/controllers/admin/page_parts_controller.rb index 600a289b..7ebcbe44 100644 --- a/app/controllers/admin/page_parts_controller.rb +++ b/app/controllers/admin/page_parts_controller.rb @@ -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 ) @@ -86,5 +86,14 @@ class Admin::PagePartsController < ApplicationController format.js {} 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 diff --git a/app/models/page.rb b/app/models/page.rb index d98f3a4e..df321d04 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -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 diff --git a/app/models/page_part.rb b/app/models/page_part.rb index 42f8b775..8bb1bc72 100644 --- a/app/models/page_part.rb +++ b/app/models/page_part.rb @@ -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 diff --git a/app/views/admin/page_parts/_public_r_tag.html.erb b/app/views/admin/page_parts/_public_r_tag.html.erb index d8422e9d..d2d4d9b9 100644 --- a/app/views/admin/page_parts/_public_r_tag.html.erb +++ b/app/views/admin/page_parts/_public_r_tag.html.erb @@ -4,7 +4,8 @@ <% 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 %> diff --git a/app/views/admin/page_parts/reload_r_tag_options.js.erb b/app/views/admin/page_parts/reload_r_tag_options.js.erb index a2eaf483..550d6127 100644 --- a/app/views/admin/page_parts/reload_r_tag_options.js.erb +++ b/app/views/admin/page_parts/reload_r_tag_options.js.erb @@ -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 %> \ No newline at end of file diff --git a/lib/parsers/parser_back_end.rb b/lib/parsers/parser_back_end.rb index 718cbcb2..f32e8084 100644 --- a/lib/parsers/parser_back_end.rb +++ b/lib/parsers/parser_back_end.rb @@ -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 diff --git a/lib/parsers/parser_common.rb b/lib/parsers/parser_common.rb index 1799ae37..7e0bcf74 100644 --- a/lib/parsers/parser_common.rb +++ b/lib/parsers/parser_common.rb @@ -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 @@ -82,7 +82,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 @@ -109,15 +109,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 << "
" - res << "

#{page.i18n_variable[I18n.locale]}

" + res << "

#{menu_page.i18n_variable[I18n.locale]}

" res << ""