From 9cd3cbc478b3d46bab04e65fd636fb904426dc53 Mon Sep 17 00:00:00 2001 From: Christophe Vilayphiou Date: Thu, 16 Feb 2012 19:14:16 +0800 Subject: [PATCH] =?UTF-8?q?Modifications=20for=20design,=20pages,=20page?= =?UTF-8?q?=5Fparts=E2=80=A6=20Move=20orbit=5Fbar=20out=20of=20kernel.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/assets/javascripts/orbit_bar.js | 4 ++++ app/controllers/admin/pages_controller.rb | 2 -- app/models/design/design.rb | 2 +- app/models/design/layout.rb | 2 +- app/models/design/layout_part.rb | 8 -------- app/models/page.rb | 18 +++++++++++------- lib/parsers/parser_back_end.rb | 4 ++-- lib/parsers/parser_front_end.rb | 5 +++-- lib/parsers/parser_layout.rb | 5 ++--- lib/tasks/dev.rake | 6 +----- public/static/kernel.js | 3 --- 11 files changed, 25 insertions(+), 34 deletions(-) create mode 100644 app/assets/javascripts/orbit_bar.js diff --git a/app/assets/javascripts/orbit_bar.js b/app/assets/javascripts/orbit_bar.js new file mode 100644 index 00000000..3c0c6cb3 --- /dev/null +++ b/app/assets/javascripts/orbit_bar.js @@ -0,0 +1,4 @@ +$(document).ready(function() { + $('body').prepend("
"); + ajax_load_proc($('#orbit_bar'), '/load_orbit_bar'); +}); \ No newline at end of file diff --git a/app/controllers/admin/pages_controller.rb b/app/controllers/admin/pages_controller.rb index a6f0373e..f3183548 100644 --- a/app/controllers/admin/pages_controller.rb +++ b/app/controllers/admin/pages_controller.rb @@ -38,8 +38,6 @@ class Admin::PagesController < ApplicationController def create @item = Page.new(params[:page]) if @item.save - @item.create_parts - @item.save flash.now[:notice] = t('admin.create_success_page') respond_to do |format| format.html { diff --git a/app/models/design/design.rb b/app/models/design/design.rb index 3a97c9ed..d2ad07aa 100644 --- a/app/models/design/design.rb +++ b/app/models/design/design.rb @@ -15,7 +15,7 @@ class Design embeds_many :themes, :cascade_callbacks => true embeds_many :javascripts, :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 :author diff --git a/app/models/design/layout.rb b/app/models/design/layout.rb index 0b3bf7d9..e13498f3 100644 --- a/app/models/design/layout.rb +++ b/app/models/design/layout.rb @@ -7,7 +7,7 @@ class Layout < DesignFile embedded_in :design embeds_many :layout_parts - after_save :parse_layout + before_save :parse_layout def content self.file.read.force_encoding("UTF-8") rescue '' diff --git a/app/models/design/layout_part.rb b/app/models/design/layout_part.rb index 3b870908..0348094e 100644 --- a/app/models/design/layout_part.rb +++ b/app/models/design/layout_part.rb @@ -4,15 +4,7 @@ class LayoutPart include Mongoid::Timestamps field :name - field :id_tag - field :editable, :type => Boolean - field :class_tag - field :content embedded_in :layout - - def editable? - self.editable - end end diff --git a/app/models/page.rb b/app/models/page.rb index 59f5e691..627eab62 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -9,17 +9,21 @@ class Page < Item has_many :page_parts, :autosave => true, :dependent => :destroy 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 - 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 + # embeds_many :custom_images, :class_name => 'Image', as: :design_image def is_home? self.parent ? false : true 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 diff --git a/lib/parsers/parser_back_end.rb b/lib/parsers/parser_back_end.rb index 6c71b48a..a50a537d 100644 --- a/lib/parsers/parser_back_end.rb +++ b/lib/parsers/parser_back_end.rb @@ -40,8 +40,8 @@ module ParserBackEnd res end c.define_tag 'image' do |tag| - 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.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.images.detect{|image| image.name.eql?(tag.attr['name']) } unless image if image res = "" res << "" res << "" + res << "" page.design.javascripts.each do |js| res << "" end @@ -98,8 +99,8 @@ module ParserFrontEnd res end c.define_tag 'image' do |tag| - 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.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.images.detect{|image| image.name.eql?(tag.attr['name']) } unless image if image res = " 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.save tag.expand end 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 c.define_tag 'image' do |tag| 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 diff --git a/lib/tasks/dev.rake b/lib/tasks/dev.rake index 01d7b5ec..ee344743 100644 --- a/lib/tasks/dev.rake +++ b/lib/tasks/dev.rake @@ -103,11 +103,7 @@ namespace :dev do 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_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 ) + home = Page.create( :i18n_variable => var_10, :design => design_1, :name => 'home', :is_published => true, :theme_id => theme.id ) 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/web_resource/web_resource.json").read).save diff --git a/public/static/kernel.js b/public/static/kernel.js index a922d21c..13d6d3fe 100644 --- a/public/static/kernel.js +++ b/public/static/kernel.js @@ -1,7 +1,4 @@ $(document).ready(function() { - - $('body').prepend("
"); - ajax_load_proc($('#orbit_bar'), '/load_orbit_bar'); $.each($(".dymanic_load"),function(){ if($(this).attr("path")==''){$(this).html("App setting Failed");}