Add sub_menu to children

This commit is contained in:
Christophe Vilayphiou 2012-05-09 04:15:45 +08:00
parent 49e2eb0187
commit 26a50cc862
7 changed files with 36 additions and 12 deletions

View File

@ -43,8 +43,8 @@ class Admin::PagePartsController < ApplicationController
def update def update
@part = PagePart.find(params[:id]) @part = PagePart.find(params[:id])
if @part.update_attributes(params[:page_part]) 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') flash.now[:notice] = t('admin.update_success_content')
@part.save
respond_to do |format| respond_to do |format|
format.html { format.html {
redirect_to admin_page_url( @part.page ) redirect_to admin_page_url( @part.page )
@ -87,4 +87,13 @@ class Admin::PagePartsController < ApplicationController
end end
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 end

View File

@ -28,8 +28,20 @@ class Page < Item
def create_parts def create_parts
page_design = self.design 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| 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
end end

View File

@ -8,6 +8,7 @@ class PagePart
field :kind field :kind
field :public_r_tag field :public_r_tag
field :public_r_tag_object_id, :default => nil field :public_r_tag_object_id, :default => nil
field :public_r_tag_option, :default => nil
field :widget_path field :widget_path
has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy

View File

@ -4,7 +4,8 @@
<span id='name_list'> <span id='name_list'>
<% if @r_tag.eql?('sub_menu') %> <% 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 %> <% else %>
<%= f.select :public_r_tag_object_id, options_from_collection_for_select(@tag_objects, :id, :title, :selected => @part.public_r_tag_object_id) %> <%= f.select :public_r_tag_object_id, options_from_collection_for_select(@tag_objects, :id, :title, :selected => @part.public_r_tag_object_id) %>
<% end %> <% end %>

View File

@ -1,5 +1,5 @@
<% if @r_tag.eql?('sub_menu') %> <% 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 %> <% else %>
$('#name_list select').html("<%= j options_from_collection_for_select(@tag_objects, :id, :title) %>") $('#name_list select').html("<%= j options_from_collection_for_select(@tag_objects, :id, :title) %>")
<% end %> <% end %>

View File

@ -32,7 +32,7 @@ module ParserBackEnd
parse_sub_menu(body, page, true) parse_sub_menu(body, page, true)
public_r_tags.each do |tag| public_r_tags.each do |tag|
send("parse_#{tag}s", body, page,id) send("parse_#{tag}s", body, page, id, true)
end end
body.to_html body.to_html

View File

@ -36,7 +36,7 @@ module ParserCommon
end end
# ad_banners # 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| body.css('ad_banner').each do |banner|
res = '' res = ''
ad_banner = AdBanner.find(banner["id"]) rescue nil ad_banner = AdBanner.find(banner["id"]) rescue nil
@ -71,7 +71,7 @@ module ParserCommon
end end
# page_images # page_images
def parse_images(body, page) def parse_images(body, page, id = nil, edit=nil)
body.css('.page_image').each do |page_image| body.css('.page_image').each do |page_image|
# image = page.custom_images.detect{|image| image.name.eql?(tag.attr['name']) } # 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 # image = page.design.custom_images.detect{|image| image.name.eql?(tag.attr['name']) } unless image
@ -98,15 +98,16 @@ module ParserCommon
end end
# sub_menus # 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| body.css('sub_menu').each do |sub_menu|
menu_page = Page.find(sub_menu['id'])
res = '' res = ''
res << "<div class='category_list'>" 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'>" res << "<ul class='list'>"
page.ordered_and_visible_children.each do |child| menu_page.ordered_and_visible_children.each do |child|
res << "<li>" res << "<li class='#{page.id.eql?(child.id) ? 'active' : nil}'>"
res << "<a href='#{child.full_name}'>#{child.i18n_variable[I18n.locale]}</a>" res << "<a href='#{edit ? admin_page_path(child.id) : child.full_name}'>#{child.i18n_variable[I18n.locale]}</a>"
res << "</li>" res << "</li>"
end end
res << "</ul>" res << "</ul>"