Changes into page_part edition.

Can choose between 'text', 'public_r_tag' and 'widget'
This commit is contained in:
Christophe Vilayphiou 2012-02-16 12:16:27 +08:00
parent 7ea1745f73
commit e0accbecaa
25 changed files with 119 additions and 179 deletions

View File

@ -19,3 +19,12 @@ $("#page_module_app_id").live('change', function() {
$("#app_page_url").children().remove(); $("#app_page_url").children().remove();
} }
}); });
$("#module_app_list select").live('change', function() {
$.getScript($(this).attr('rel') + '/' + $(this).val() + '/reload_widgets');
});
$('.part_kind').live('click', function() {
$('.part_kind_partial').hide();
$('#part_' + $(this).attr('value')).show();
});

View File

@ -22,15 +22,10 @@ class Admin::PagePartsController < ApplicationController
def edit def edit
@part = PagePart.find(params[:id]) @part = PagePart.find(params[:id])
case @part.kind @module_apps = ModuleApp.all(:conditions => {:enable_frontend => true})
when 'text' @module_app = @part.module_app ? @part.module_app : @module_apps[0]
@i18n_variable = @part.i18n_variable @r_tag = @part.public_r_tag.blank? ? LIST[:public_r_tags][0] : @part.public_r_tag
@partial = 'edit_text' @tag_objects = @r_tag.classify.constantize.all
@part_locale = params[:part_locale] || I18n.locale.to_s
when 'module'
@plugins=[{:module=>"Blog",:widgets=>[{:name=>"Blog",:path=>"panel/new_blog/widget_latest_post"},{:name=>"Blog",:path=>"panel/new_blog/widget_index"}]}]
when 'snippet'
end
end end
def create def create
@ -41,7 +36,6 @@ class Admin::PagePartsController < ApplicationController
@part = PagePart.find(params[:id]) @part = PagePart.find(params[:id])
if @part.update_attributes(params[:page_part]) if @part.update_attributes(params[:page_part])
flash.now[:notice] = t('admin.update_success_content') flash.now[:notice] = t('admin.update_success_content')
@part.build_content(@site_valid_locales)
@part.save @part.save
respond_to do |format| respond_to do |format|
format.html { format.html {
@ -59,9 +53,14 @@ class Admin::PagePartsController < ApplicationController
def destroy def destroy
@item = Page.find(params[:id]) @item = Page.find(params[:id])
@item.destroy @item.destroy
@item.destroy_i18n_variable
redirect_to admin_items_url( :parent_id => @item.parent_id ) redirect_to admin_items_url( :parent_id => @item.parent_id )
end end
def reload_widgets
@module_app = ModuleApp.find(params[:id])
respond_to do |format|
format.js {}
end
end
end end

View File

@ -1,7 +1,8 @@
class Theme < Stylesheet class Theme < Stylesheet
embedded_in :design
field :name field :name
embedded_in :design
before_save :set_name before_save :set_name
protected protected

View File

@ -5,7 +5,6 @@ class Item
field :name, :index => true field :name, :index => true
field :full_name, :index => true field :full_name, :index => true
field :i18n_variable_id, :type => BSON::ObjectId
field :parent_id, :index => true field :parent_id, :index => true
field :parent_name field :parent_name
field :position, :type => Integer field :position, :type => Integer
@ -17,15 +16,11 @@ class Item
validates_presence_of :name, :full_name, :position, :is_published validates_presence_of :name, :full_name, :position, :is_published
belongs_to :parent, :class_name => "Item" belongs_to :parent, :class_name => "Item"
has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy
has_many :children, :class_name => "Item", :as => 'parent' has_many :children, :class_name => "Item", :as => 'parent'
before_validation :setup_default_value before_validation :setup_default_value
# Destroy the i18n_variable
def destroy_i18n_variable
self.i18n_variable.destroy rescue nil
end
def self.find_by_name(item_name) def self.find_by_name(item_name)
Item.first(:conditions => { :name => item_name, :is_published => true }) Item.first(:conditions => { :name => item_name, :is_published => true })
end end
@ -37,22 +32,6 @@ class Item
nodes.reverse nodes.reverse
end end
# Update or create the i18n_variable record
def i18n_variable=(attr)
if self.i18n_variable_id
self.i18n_variable.update_attributes(attr) rescue nil
else
var = I18nVariable.new(attr.merge({:key => self.name, :document_class => self.class}))
var.save
self.i18n_variable_id = var.id
end
end
# Get the i18n_variable
def i18n_variable
@i18n_variable ||= I18nVariable.find(self.i18n_variable_id) rescue nil
end
# Build the url from the array of ancestors # Build the url from the array of ancestors
def url def url
urls = ancestors.map{ |a| a.name } << self.name urls = ancestors.map{ |a| a.name } << self.name

View File

@ -10,7 +10,7 @@ class ModuleApp
field :intro field :intro
field :update_info field :update_info
field :create_date field :create_date
field :enable_frontend,type: Boolean field :enable_frontend, type: Boolean, :default => true
field :app_pages ,type: Array field :app_pages ,type: Array
field :widgets ,type: Array field :widgets ,type: Array
@ -19,6 +19,8 @@ class ModuleApp
has_many :sub_managers,as: :sub_managing_app ,:class_name => "AppManager"#, :dependent => :destroy,:foreign_key => "sub_managing_app_id",:inverse_of => :sub_managing_app has_many :sub_managers,as: :sub_managing_app ,:class_name => "AppManager"#, :dependent => :destroy,:foreign_key => "sub_managing_app_id",:inverse_of => :sub_managing_app
has_many :tags has_many :tags
has_many :page_parts
has_many :pages
has_one :app_auth,dependent: :delete has_one :app_auth,dependent: :delete

View File

@ -5,23 +5,16 @@ class Page < Item
field :theme_id, :type => BSON::ObjectId, :default => nil field :theme_id, :type => BSON::ObjectId, :default => nil
belongs_to :design belongs_to :design
has_many :page_parts
belongs_to :module_app belongs_to :module_app
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 # embeds_many :custom_images, :class_name => 'Image', as: :design_image
def create_parts def create_parts
page_design = self.design page_design = self.design
page_design.layout.layout_parts.each do |p| page_design.layout.layout_parts.each do |p|
self.page_parts.create( :name => p.name, :i18n_variable_id => I18nVariable.create.id, :kind => 'text' ) if p.editable? self.page_parts.create( :name => p.name, :i18n_variable => I18nVariable.create, :kind => 'text' ) if p.editable?
end
end
# Destroy the page_parts
def destroy_page_parts
self.page_parts.each do |part|
part.destroy_i18n_variable
part.destroy
end end
end end

View File

@ -6,41 +6,13 @@ class PagePart
field :name field :name
field :content field :content
field :kind field :kind
field :i18n_variable_id, :type => BSON::ObjectId field :public_r_tag
field :public_r_tag_object_id, :type => BSON::ObjectId, :default => nil
field :widget_path
has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy
belongs_to :page belongs_to :page
belongs_to :module_app
# Get the i18n_variable
def i18n_variable
@i18n_variable ||= I18nVariable.find(self.i18n_variable_id) rescue nil
end
# Update or create the i18n_variable record
def i18n_variable=(attr)
if self.i18n_variable_id
self.i18n_variable.update_attributes(attr)
else
var = I18nVariable.new(attr.merge({:key => self.name, :document_class => self.class, :parent_id => self.page.i18n_variable_id}))
var.save
self.i18n_variable_id = var.id
end
end
def destroy_i18n_variable
self.i18n_variable.destroy rescue nil
end
# Build the content from the i18n_variable
def build_content(locales)
res = ''
res << "<r:multi_lang i18n_id='#{i18n_variable.id}'>"
locales.each do |locale|
res << "<r:lang name='#{locale.to_s}'>"
res << i18n_variable[locale.to_s]
res << "</r:lang>"
end
res << "</r:multi_lang>"
self.content = res
end
end end

View File

@ -1 +1 @@
<%= f.select :module_app_id, @apps.collect { |t| [t.title.capitalize, t.id] }, {:include_blank => true} ,{:rel => admin_module_apps_path } %> <%= f.select :module_app_id, @apps.collect { |t| [t.title.capitalize, t.id] }, {}, {:rel => admin_module_apps_path } %>

View File

@ -1,17 +0,0 @@
<%= flash_messages %>
<%= render 'language_bar' %>
<%= form_for @part, :url => admin_page_part_path(@part), :html => { :class => 'form' } do |f| %>
<%= fields_for "page_part[i18n_variable]", @i18n_variable, :index => nil do |f| %>
<% @site_valid_locales.each do |locale| %>
<div class="ckeditor_locale" style="display:<%= @part_locale.eql?(locale) ? 'block' : 'none' %>">
<%= render :partial => "admin/page_parts/form", :locals => { :f => f, :locale => locale } %>
</div>
<% end %>
<% end %>
<p>
<%= f.submit t(:update) %> <%= link_back %>
</p>
<% end %>

View File

@ -1,3 +0,0 @@
<%= f.error_messages %>
<%= f.cktext_area locale, :toolbar=>'Full', :width=>'700px', :height=>'200px'%>

View File

@ -2,4 +2,4 @@
<%= render 'admin/items/site_map_left_bar' %> <%= render 'admin/items/site_map_left_bar' %>
<% end -%> <% end -%>
<%= render @partial %> <%= render 'edit' %>

View File

@ -1 +1 @@
$('#back_main').html("<%= escape_javascript(render(:partial => @partial)) %>"); $('#back_main').html("<%= j render(:partial => 'edit') %>");

View File

@ -6,6 +6,7 @@ require "action_controller/railtie"
require "action_mailer/railtie" require "action_mailer/railtie"
require "active_resource/railtie" require "active_resource/railtie"
require "rails/test_unit/railtie" require "rails/test_unit/railtie"
require 'sprockets/railtie'
# If you have a Gemfile, require the default gems, the ones in the # If you have a Gemfile, require the default gems, the ones in the
# current environment and also include :assets gems if in development # current environment and also include :assets gems if in development

View File

@ -6,3 +6,11 @@ forbidden_item_names:
markups: markups:
- text_field - text_field
- select - select
public_r_tags:
- ad_banner
page_part_kinds:
- text
- public_r_tag
- module_widget

View File

@ -66,7 +66,11 @@ PrototypeR4::Application.routes.draw do
get 'reload_frontend_pages' get 'reload_frontend_pages'
end end
end end
resources :page_parts resources :page_parts do
member do
get 'reload_widgets'
end
end
resources :purchases do resources :purchases do
collection do collection do
get 'install_app' get 'install_app'

View File

@ -18,19 +18,17 @@
<!-- example --> <!-- example -->
<div id="header_top" class="header"> <div id="header_top" class="header">
This is the first level of header This is the first level of header
<r:adbanner name='banner_1'> <r:content name='content_2'>
</r:adbanner> </r:content>
</div> </div>
<div id="header_bottom" class="header"> <div id="header_bottom" class="header">
This is the second level of header This is the second level of header
</div> </div>
<div id="main_content" class="content"> <div id="main_content" class="content">
<r:content name='content_1' main='true'> <r:content name='content_1' main='true'/>
</r:content> <r:content name='content_3'/>
<div class="dymanic_load" path="/panel/new_blog/widget/latest_post"></div> <r:content name='content_4'/>
<div class="dymanic_load" path="/panel/new_blog/widget/"></div>
<div class="dymanic_load" path="/panel/announcement/widget/"></div>
</div> </div>
<div id="footer" class="footer"> <div id="footer" class="footer">

View File

@ -31,12 +31,6 @@ module ParserBackEnd
end end
}.join(' | ') }.join(' | ')
end end
c.define_tag 'multi_lang' do |tag|
tag.expand
end
c.define_tag 'multi_lang:lang' do |tag|
tag.expand if tag.attr['name'].eql?(I18n.locale.to_s)
end
c.define_tag 'css' do |tag| c.define_tag 'css' do |tag|
assets = Asset.any_in(:filename => tag.attr['name'].split(',').map(&:strip)) assets = Asset.any_in(:filename => tag.attr['name'].split(',').map(&:strip))
res = '' res = ''
@ -75,26 +69,24 @@ module ParserBackEnd
end end
res res
end end
c.define_tag 'adbanner' do |tag| c.define_tag 'ad_banner' do |tag|
res = '' res = ''
ad_banner = AdBanner.first(conditions:{title: tag.attr["name"]}) ad_banner = AdBanner.find(tag.attr["id"]) rescue nil
res << "<script type='text/javascript'> if ad_banner
$(document).ready(function(){ $('#slideshow-#{ad_banner.title}').cycle({after: onAfter,timeout:1 ,fx: '#{ad_banner.ad_fx.nil?? 'fade': ad_banner.ad_fx}' }); }); res << "<script type='text/javascript'>
</script>" $(document).ready(function(){ $('#slideshow-#{ad_banner.title.dehumanize}').cycle({after: onAfter,timeout:1 ,fx: '#{ad_banner.ad_fx.nil?? 'fade': ad_banner.ad_fx}' }); });
</script>"
res << "<div id='slideshow-#{ad_banner.title.dehumanize}'>"
res << "<div id='#{tag.attr['name']}' ad_banner_id='#{ad_banner.id}' class='editable' style='border:solid 1px; margin:5px; padding:5px;'>" ad_banner.ad_images.each do |ad_image|
res << "<div class='edit_link' style='display:none'>" res << "<img src='#{ad_image.file}' "
res << " <a href='#{edit_admin_ad_banner_path(ad_banner.id)}' class='nav'>#{t(:edit)}</a>" res << "alt='#{ad_image.picture_intro || ' '}' "
res << '</div>' res << "time_to_next='#{ad_image.get_delay_time}' "
#================================== res << "link_open='#{ad_image.link_open}' "
res << "<div id='slideshow-#{ad_banner.title}'>" res << "link_url='#{(ad_banner.direct_to_after_click?? ad_image.out_link : ad_banner.context) || ' '}' "
ad_banner.ad_images.each do |ad_image| res << "/>"
res << "<img src='#{ad_image.file}' />"
end end
res << "</div>" res << "</div>"
#================================== end
res << "</div>"
end end
c.define_tag 'layout_part' do |tag| c.define_tag 'layout_part' do |tag|
part = page.page_parts.detect{ |p| p.name.to_s == tag.attr['name'].to_s } part = page.page_parts.detect{ |p| p.name.to_s == tag.attr['name'].to_s }
@ -108,13 +100,22 @@ module ParserBackEnd
if (tag.attributes["main"] == "true" && !page.module_app.nil?) if (tag.attributes["main"] == "true" && !page.module_app.nil?)
ret << "<div id='appfrontend' class='dymanic_load' path='/panel/#{page.module_app.key}/front_end/#{page.app_frontend_url}?inner=true'></div>" ret << "<div id='appfrontend' class='dymanic_load' path='/panel/#{page.module_app.key}/front_end/#{page.app_frontend_url}?inner=true'></div>"
else else
part = page.page_parts.detect{ |p| p.name.to_s == tag.attr['name'].to_s } part = page.page_parts.detect{ |p| p.name.to_s == tag.attr['name'].to_s }
ret << "<div id='#{tag.attr['name']}' part_id='#{part.id}' class='editable' style='border:solid 1px; margin:5px; padding:5px;'>" ret << "<div id='#{tag.attr['name']}' part_id='#{part.id}' class='editable' style='border:solid 1px; margin:5px; padding:5px;'>"
ret << "<div class='edit_link' style='display:none'>" ret << "<div class='edit_link' style='display:none'>"
ret << " <a href='#{edit_admin_page_part_path(part.id)}' class='nav'>#{t(:edit)}</a>" ret << " <a href='#{edit_admin_page_part_path(part.id)}' class='nav'>#{t(:edit)}</a>"
ret << '</div>' ret << '</div>'
ret << part.i18n_variable[I18n.locale.to_s] rescue '' case part.kind
ret << '</div>' when 'text'
ret << part.i18n_variable[I18n.locale] rescue ''
when 'module_widget'
ret << "<div class='dymanic_load' path='/panel/#{part.module_app.key}/widget/#{part.widget_path}'></div>"
when 'public_r_tag'
ret << "<r:#{part.public_r_tag} id='#{part.public_r_tag_object_id}'/>"
else
''
end
ret << '</div>'
end end
end end
c.define_tag 'link' do |tag| c.define_tag 'link' do |tag|

View File

@ -51,12 +51,6 @@ module ParserFrontEnd
var.destroy var.destroy
end end
end end
c.define_tag 'multi_lang' do |tag|
tag.expand
end
c.define_tag 'multi_lang:lang' do |tag|
tag.expand if tag.attr['name'].eql?(I18n.locale.to_s)
end
c.define_tag 'css' do |tag| c.define_tag 'css' do |tag|
assets = Asset.any_in(:filename => tag.attr['name'].split(',').map(&:strip)) assets = Asset.any_in(:filename => tag.attr['name'].split(',').map(&:strip))
res = '' res = ''
@ -83,15 +77,14 @@ module ParserFrontEnd
end end
res res
end end
c.define_tag 'adbanner' do |tag| c.define_tag 'ad_banner' do |tag|
res = '' res = ''
ad_banner = AdBanner.first(conditions:{title: tag.attr["name"]}) ad_banner = AdBanner.find(tag.attr["id"]) rescue nil
if ad_banner.display? if ad_banner && ad_banner.display?
res << "<script type='text/javascript'> res << "<script type='text/javascript'>
$(document).ready(function(){ $('#slideshow-#{ad_banner.title}').cycle({after: onAfter,timeout:1 ,fx: '#{ad_banner.ad_fx.nil?? 'fade': ad_banner.ad_fx}' }); }); $(document).ready(function(){ $('#slideshow-#{ad_banner.title.dehumanize}').cycle({after: onAfter,timeout:1 ,fx: '#{ad_banner.ad_fx.nil?? 'fade': ad_banner.ad_fx}' }); });
</script>" </script>"
res << "<div id='slideshow-#{ad_banner.title.dehumanize}'>"
res << "<div id='slideshow-#{ad_banner.title}'>"
ad_banner.ad_images.each do |ad_image| ad_banner.ad_images.each do |ad_image|
res << "<img src='#{ad_image.file}' " res << "<img src='#{ad_image.file}' "
res << "alt='#{ad_image.picture_intro || ' '}' " res << "alt='#{ad_image.picture_intro || ' '}' "
@ -128,7 +121,16 @@ module ParserFrontEnd
ret << "?inner=true'></div>" ret << "?inner=true'></div>"
else else
part = page.page_parts.detect{ |p| p.name.to_s == tag.attr['name'].to_s } rescue nil part = page.page_parts.detect{ |p| p.name.to_s == tag.attr['name'].to_s } rescue nil
ret << part.content rescue nil case part.kind
when 'text'
ret << part.i18n_variable[I18n.locale] rescue ''
when 'module_widget'
ret << "<div class='dymanic_load' path='/panel/#{part.module_app.key}/widget/#{part.widget_path}?inner=true'></div>"
when 'public_r_tag'
ret << "<r:#{part.public_r_tag} id='#{part.public_r_tag_object_id}'/>"
else
''
end
end end
ret ret
end end

View File

@ -15,7 +15,7 @@ module ParserLayout
end end
c.define_tag 'stylesheets' do |tag| c.define_tag 'stylesheets' do |tag|
end end
c.define_tag 'adbanner' do |tag| c.define_tag 'ad_banner' do |tag|
end end
c.define_tag 'menu' do |tag| c.define_tag 'menu' do |tag|
layout.build_menu(:levels => 0, :values => {}) unless layout.menu layout.build_menu(:levels => 0, :values => {}) unless layout.menu

View File

@ -103,8 +103,11 @@ namespace :dev do
design_1.save design_1.save
home = Page.create!( :i18n_variable_id => var_10.id, :design_id => design_1.id, :name => 'home', :is_published => true, :theme_id => theme.id ) 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 => File.open("#{Rails.root}/lib/template/home.page").read, :kind => 'text', :i18n_variable_id => var_13.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
Post.create(:title=>"1st post",:body=>"Long long time ago.....") Post.create(:title=>"1st post",:body=>"Long long time ago.....")

View File

@ -1,8 +1,2 @@
<r:multi_lang> <r:ad_banner name='banner_1'>
<r:lang name='en'> </r:ad_banner>
<p>This is the homepage</p>
</r:lang>
<r:lang name='zh_tw'>
<p>t這是首頁</p>
</r:lang>
</r:multi_lang>

View File

@ -7,5 +7,6 @@
"update_info": "Some info", "update_info": "Some info",
"create_date": "11-11-2011", "create_date": "11-11-2011",
"app_pages": ["bulletins"], "app_pages": ["bulletins"],
"widgets": ["bulletins"],
"enable_frontend": true "enable_frontend": true
} }

View File

@ -1,5 +1,4 @@
Rails.application.routes.draw do Rails.application.routes.draw do
namespace :panel do namespace :panel do
namespace :announcement do namespace :announcement do
namespace :back_end do namespace :back_end do
@ -15,9 +14,8 @@ Rails.application.routes.draw do
resources :bulletins resources :bulletins
end end
namespace :widget do namespace :widget do
root :to => "bulletins#index" match "bulletins" => "bulletins#index"
end end
end end
end end
match "/appfront/*path" => redirect("/panel/*path")
end end

View File

@ -1,5 +1,4 @@
Rails.application.routes.draw do Rails.application.routes.draw do
namespace :panel do namespace :panel do
namespace :new_blog do namespace :new_blog do
namespace :back_end do namespace :back_end do
@ -13,13 +12,9 @@ Rails.application.routes.draw do
resources :comments resources :comments
end end
namespace :widget do namespace :widget do
root :to => "posts#index" match "posts" => "posts#index"
match "latest_post" => "posts#latest_post" match "latest_post" => "posts#latest_post"
end end
end end
end end
# match "appfront/blog/front_end/show/:id" => "posts#frontend_show" ,:as => :appfront_blog_show
match "/appfront/*path" => redirect("/panel/*path")
end end

View File

@ -7,6 +7,6 @@
"update_info": "Some info", "update_info": "Some info",
"create_date": "11-11-2011", "create_date": "11-11-2011",
"app_pages": ["posts"], "app_pages": ["posts"],
"widgets": ["/latest_post","/"], "widgets": ["latest_post","posts"],
"enable_frontend": true "enable_frontend": true
} }