Modifications for design, pages, page_parts…

Move orbit_bar out of kernel.js
This commit is contained in:
Christophe Vilayphiou 2012-02-16 19:14:16 +08:00
parent 5da75161c4
commit 9cd3cbc478
11 changed files with 25 additions and 34 deletions

View File

@ -0,0 +1,4 @@
$(document).ready(function() {
$('body').prepend("<div id='orbit_bar'/>");
ajax_load_proc($('#orbit_bar'), '/load_orbit_bar');
});

View File

@ -38,8 +38,6 @@ class Admin::PagesController < ApplicationController
def create def create
@item = Page.new(params[:page]) @item = Page.new(params[:page])
if @item.save if @item.save
@item.create_parts
@item.save
flash.now[:notice] = t('admin.create_success_page') flash.now[:notice] = t('admin.create_success_page')
respond_to do |format| respond_to do |format|
format.html { format.html {

View File

@ -15,7 +15,7 @@ class Design
embeds_many :themes, :cascade_callbacks => true embeds_many :themes, :cascade_callbacks => true
embeds_many :javascripts, :cascade_callbacks => true embeds_many :javascripts, :cascade_callbacks => true
embeds_many :images, :cascade_callbacks => true embeds_many :images, :cascade_callbacks => true
embeds_many :custom_images, :class_name => 'Image', :cascade_callbacks => true # embeds_many :custom_images, :class_name => 'Image', :cascade_callbacks => true
validates_presence_of :title validates_presence_of :title
validates_presence_of :author validates_presence_of :author

View File

@ -7,7 +7,7 @@ class Layout < DesignFile
embedded_in :design embedded_in :design
embeds_many :layout_parts embeds_many :layout_parts
after_save :parse_layout before_save :parse_layout
def content def content
self.file.read.force_encoding("UTF-8") rescue '' self.file.read.force_encoding("UTF-8") rescue ''

View File

@ -4,15 +4,7 @@ class LayoutPart
include Mongoid::Timestamps include Mongoid::Timestamps
field :name field :name
field :id_tag
field :editable, :type => Boolean
field :class_tag
field :content
embedded_in :layout embedded_in :layout
def editable?
self.editable
end
end end

View File

@ -9,17 +9,21 @@ class Page < Item
has_many :page_parts, :autosave => true, :dependent => :destroy has_many :page_parts, :autosave => true, :dependent => :destroy
accepts_nested_attributes_for :page_parts, :allow_destroy => true accepts_nested_attributes_for :page_parts, :allow_destroy => true
# embeds_many :custom_images, :class_name => 'Image', as: :design_image before_save :create_parts
def create_parts # embeds_many :custom_images, :class_name => 'Image', as: :design_image
page_design = self.design
page_design.layout.layout_parts.each do |p|
self.page_parts.create( :name => p.name, :i18n_variable => I18nVariable.create, :kind => 'text' ) if p.editable?
end
end
def is_home? def is_home?
self.parent ? false : true self.parent ? false : true
end end
protected
def create_parts
page_design = self.design
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)}
end
end
end end

View File

@ -40,8 +40,8 @@ module ParserBackEnd
res res
end end
c.define_tag 'image' do |tag| c.define_tag 'image' do |tag|
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
image = page.design.images.detect{|image| image.name.eql?(tag.attr['name']) } unless image image = page.design.images.detect{|image| image.name.eql?(tag.attr['name']) } unless image
if image if image
res = "<img src=#{image.file.url} " res = "<img src=#{image.file.url} "

View File

@ -72,6 +72,7 @@ module ParserFrontEnd
res << "<script type='text/javascript' src='/static/jquery.js'></script>" res << "<script type='text/javascript' src='/static/jquery.js'></script>"
res << "<script type='text/javascript' src='/static/jquery.cycle.all.latest.js'></script>" res << "<script type='text/javascript' src='/static/jquery.cycle.all.latest.js'></script>"
res << "<script type='text/javascript' src='/static/kernel.js'></script>" res << "<script type='text/javascript' src='/static/kernel.js'></script>"
res << "<script type='text/javascript' src='/assets/orbit_bar.js'></script>"
page.design.javascripts.each do |js| page.design.javascripts.each do |js|
res << "<script type='text/javascript' src='#{js.file.url}'></script>" res << "<script type='text/javascript' src='#{js.file.url}'></script>"
end end
@ -98,8 +99,8 @@ module ParserFrontEnd
res res
end end
c.define_tag 'image' do |tag| c.define_tag 'image' do |tag|
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
image = page.design.images.detect{|image| image.name.eql?(tag.attr['name']) } unless image image = page.design.images.detect{|image| image.name.eql?(tag.attr['name']) } unless image
if image if image
res = "<img src=#{image.file.url} " res = "<img src=#{image.file.url} "

View File

@ -22,15 +22,14 @@ module ParserLayout
layout.menu.levels = i = tag.attr['level'].to_i layout.menu.levels = i = tag.attr['level'].to_i
layout.menu.values.merge!({'home' => tag.attr['home']}) if i == 1 layout.menu.values.merge!({'home' => tag.attr['home']}) if i == 1
layout.menu.values.merge!({"id_#{i}" => tag.attr['id'], "class_#{i}" => tag.attr['class'], "li_class_#{i}" => tag.attr['li_class'], "li_incremental_#{i}" => tag.attr['li_incremental']}) layout.menu.values.merge!({"id_#{i}" => tag.attr['id'], "class_#{i}" => tag.attr['class'], "li_class_#{i}" => tag.attr['li_class'], "li_incremental_#{i}" => tag.attr['li_incremental']})
layout.menu.save
tag.expand tag.expand
end end
c.define_tag 'content' do |tag| c.define_tag 'content' do |tag|
layout.layout_parts.create(:name => tag.attr['name'], :editable => true) layout.layout_parts.new(:name => tag.attr['name'])
end end
c.define_tag 'image' do |tag| c.define_tag 'image' do |tag|
image = layout.design.images.detect{ |i| i.file_identifier.eql?(parse_html_image(tag.expand)) } image = layout.design.images.detect{ |i| i.file_identifier.eql?(parse_html_image(tag.expand)) }
image.update_attributes(:name => tag.attr['name'], :html_id => tag.attr['id'], :html_class => tag.attr['class']) image.update_attributes(:name => tag.attr['name'], :html_id => tag.attr['id'], :html_class => tag.attr['class']) if image
end end
end end
end end

View File

@ -103,11 +103,7 @@ namespace :dev do
design_1.save design_1.save
home = Page.create!( :i18n_variable => var_10, :design_id => design_1.id, :name => 'home', :is_published => true, :theme_id => theme.id ) home = Page.create( :i18n_variable => var_10, :design => design_1, :name => 'home', :is_published => true, :theme_id => theme.id )
home.page_parts.create!( :name => 'content_1', :content => nil, :kind => nil )
home.page_parts.create!( :name => 'content_2', :content => nil, :kind => nil )
home.page_parts.create!( :name => 'content_3', :content => nil, :kind => 'text', :i18n_variable => var_13 )
home.page_parts.create!( :name => 'content_4', :content => nil, :kind => 'text', :i18n_variable => nil )
ModuleApp.new.from_json(File.open("#{Rails.root}/vendor/built_in_modules/new_blog/new_blog.json").read).save ModuleApp.new.from_json(File.open("#{Rails.root}/vendor/built_in_modules/new_blog/new_blog.json").read).save
ModuleApp.new.from_json(File.open("#{Rails.root}/vendor/built_in_modules/announcement/announcement.json").read).save ModuleApp.new.from_json(File.open("#{Rails.root}/vendor/built_in_modules/announcement/announcement.json").read).save
ModuleApp.new.from_json(File.open("#{Rails.root}/vendor/built_in_modules/web_resource/web_resource.json").read).save ModuleApp.new.from_json(File.open("#{Rails.root}/vendor/built_in_modules/web_resource/web_resource.json").read).save

View File

@ -1,8 +1,5 @@
$(document).ready(function() { $(document).ready(function() {
$('body').prepend("<div id='orbit_bar'/>");
ajax_load_proc($('#orbit_bar'), '/load_orbit_bar');
$.each($(".dymanic_load"),function(){ $.each($(".dymanic_load"),function(){
if($(this).attr("path")==''){$(this).html("App setting Failed");} if($(this).attr("path")==''){$(this).html("App setting Failed");}