fix i18n,reload problems

This commit is contained in:
Fu Matthew 2013-02-18 15:13:31 +08:00
parent 29bb92f841
commit a6f6dc271c
44 changed files with 185 additions and 66 deletions

View File

@ -72,10 +72,10 @@ end
group :test, :development do group :test, :development do
#gem 'pry' gem 'pry'
#gem 'pry-remote' gem 'pry-remote'
#gem 'pry-stack_explorer' gem 'pry-stack_explorer'
#gem 'pry-debugger' gem 'pry-debugger'
gem 'faker' gem 'faker'
gem "sunspot-rails-tester" gem "sunspot-rails-tester"

View File

@ -42,6 +42,10 @@ $("#tag_list select").live('change', function() {
$.getScript($(this).attr('rel') + '/' + $(this).val() + '/reload_r_tag_options'); $.getScript($(this).attr('rel') + '/' + $(this).val() + '/reload_r_tag_options');
}); });
$("select.widget_field_select").live('change', function() {
$.getScript(get_object_path() + '/reload_after_widget_field_changed?widget_field_value='+ $(this).val()+'&dom_id=' + $(this).attr("id") + '&field_seri=' +$(this).attr('field_seri'));
});
$('.part_kind').live('click', function() { $('.part_kind').live('click', function() {
$('.part_kind_partial').hide(); $('.part_kind_partial').hide();
$('#part_' + $(this).attr('value')).show(); $('#part_' + $(this).attr('value')).show();

View File

@ -55,9 +55,10 @@ class Admin::PagePartsController < ApplicationController
def update def update
@part = PagePart.find(params[:id]) @part = PagePart.find(params[:id])
params[:page_part][:widget_field] = params[:page_part][:widget_field].zip( params[:page_part][:widget_field_type],params[:page_part][:widget_field_is_link] )
params[:page_part][:widget_field] = params[:page_part][:widget_field].zip( params[:page_part][:widget_field_type] ) if params[:page_part][:widget_field]
params[:page_part][:widget_field_type] = nil params[:page_part][:widget_field_type] = nil
params[:page_part][:widget_field_is_link] = nil
if params[:page_part][:module_app].blank? if params[:page_part][:module_app].blank?
params[:page_part][:module_app] = nil params[:page_part][:module_app] = nil
@ -90,6 +91,13 @@ class Admin::PagePartsController < ApplicationController
redirect_to admin_items_url( :parent_id => @item.parent_id ) redirect_to admin_items_url( :parent_id => @item.parent_id )
end end
def reload_widget_field
@index = params[:field_seri].to_i
@part = PagePart.find params[:id]
@choosen_field = params[:widget_field_value]
@module_app = @part.module_app
end
def reload_widgets def reload_widgets
@part = PagePart.find params[:id] @part = PagePart.find params[:id]
@module_app = ModuleApp.find(params[:module_app_id]) rescue nil @module_app = ModuleApp.find(params[:module_app_id]) rescue nil

View File

@ -24,7 +24,6 @@ class DefaultWidgetController< OrbitWidgetController
@page_part.widget_data_count.is_a?(Fixnum) ? @page_part.widget_data_count : (@page_part.widget_data_count.to_i rescue 3) @page_part.widget_data_count.is_a?(Fixnum) ? @page_part.widget_data_count : (@page_part.widget_data_count.to_i rescue 3)
end end
@data = eval(@default_widget["query"]).limit(data_limit).includes(@widget_image_field) @data = eval(@default_widget["query"]).limit(data_limit).includes(@widget_image_field)
case params[:type] case params[:type]
when "typeA" when "typeA"
@tag_class = 'default_widget_typeA' @tag_class = 'default_widget_typeA'

View File

@ -9,6 +9,42 @@ module Admin::PagePartsHelper
end end
end end
def get_widget_field_rel(local_item=nil)
local_item = @part if local_item.nil? && @part
local_item = @page if local_item.nil? && @page
case local_item
when Page
admin_pages_path
when PagePart
admin_page_parts_path
end
end
def field_link_switch(i,object_name,field_name,local_item=nil,prefill_value=nil)
local_item = @part if local_item.nil? && @part
local_item = @page if local_item.nil? && @page
res = ''
choosen_value = prefill_value || local_item[:widget_field][i][0]
choosen_field_is_link = (@module_app.widget_fields.select{|t| t[0].to_s==choosen_value}.first)[2]==:link
if choosen_field_is_link
value = case local_item
when Page
local_item[:frontend_field][i][2]
when PagePart
local_item[:widget_field][i][2]
end
res = label_tag '' do
check_box_tag("#{object_name}[#{field_name}_is_link][]", value = "true", value) + I18n.t("default_widget.field_is_link")
end
else # choosen_field_not_link
res = hidden_field_tag "#{object_name}[#{field_name}_is_link][]", 'false'
end # of if choosen_field_is_link
end
def widget_field_options(i,local_item=nil) def widget_field_options(i,local_item=nil)
local_item = @part if local_item.nil? && @part local_item = @part if local_item.nil? && @part
local_item = @page if local_item.nil? && @page local_item = @page if local_item.nil? && @page

View File

@ -1,6 +1,6 @@
module DefaultWidgetHelper module DefaultWidgetHelper
def get_field_header(field) def get_field_header(field)
I18n.t(@page_part.module_app.widget_fields.select{|t|t[0]==field}[0][1]) I18n.t("#{@page_part.module_app.key}.default_widget.#{field}")
end end
def link_to_field(row_data,field) def link_to_field(row_data,field)

View File

@ -6,7 +6,7 @@ class ModuleApp
field :key field :key
field :title field :title
field :sidebar_order#,type: Integer field :sidebar_order,type: Integer,default: 0
def refetch_setting!(reg) def refetch_setting!(reg)
# %w{module_label category base_url version organization author intro update_info create_date}.each do |field| # %w{module_label category base_url version organization author intro update_info create_date}.each do |field|
@ -30,7 +30,7 @@ class ModuleApp
end end
def get_default_widget def get_default_widget
raise 'Need to link with OrbitApp [type: Array]' get_registration.get_default_widget
end end

View File

@ -31,12 +31,14 @@
<div class="rows clear"> <div class="rows clear">
<span class="span4"> <span class="span4">
<%= i+1 %> <%= i+1 %>
<%= select_tag "#{object_name}[#{field_name}][]", widget_field_options(i), :include_blank => true %> <%= select_tag "#{object_name}[#{field_name}][]", widget_field_options(i), :include_blank => true ,:class=>'widget_field_select',:field_seri => i ,:id=>"#{object_name}_#{field_name}_#{i}"%>
</span> </span>
<span class="span3"> <span class="span3">
<%= select_tag "#{object_name}[#{field_name}_type][]", widget_fiield_type_options(i), :include_blank => true %> <br /> <%= select_tag "#{object_name}[#{field_name}_type][]", widget_fiield_type_options(i), :include_blank => true %> <br />
</span> </span>
<span class="span5"></span> <span class="span5 link_switch_holder">
<%= field_link_switch(i,object_name,field_name) %>
</span>
</div><br/> </div><br/>
<% end %> <% end %>
<br/> <br/>

View File

@ -26,7 +26,7 @@
<%= t "default_widget.select_widget_path" %> <%= t "default_widget.select_widget_path" %>
</label> </label>
<div class="controls"> <div class="controls">
<%= f.select :widget_path, @module_app ? @module_app.widgets.collect{|k,v| [I18n.t(v["i18n"]),k]} : [], {}, { :selected => @part.widget_path, :rel => admin_page_parts_path } %> <%= f.select :widget_path, @module_app ? @module_app.widgets.collect{|k,v| [I18n.t(v["i18n"]),k]} : [], {}, { :selected => @part.widget_path, :rel => get_widget_field_rel } %>
</div> </div>
</div> </div>

View File

@ -0,0 +1 @@
$("#<%= params[:dom_id] %>").parents(".rows").find(".link_switch_holder").html("<%= j field_link_switch(@index,'page_part','widget_field',nil,@choosen_field) %>");

View File

@ -120,6 +120,7 @@ zh_tw:
name: 預設樣式 name: 預設樣式
no_support_setting: 沒有可以使用的設定 no_support_setting: 沒有可以使用的設定
no_value: 不設定(全部) no_value: 不設定(全部)
field_is_link: 連結
fields_: 前台輸出欄位 fields_: 前台輸出欄位
fields_order: 輸出欄位順序 fields_order: 輸出欄位順序
fields_style: 輸出欄位樣式 fields_style: 輸出欄位樣式

View File

@ -114,6 +114,7 @@ Orbit::Application.routes.draw do
resources :page_parts do resources :page_parts do
member do member do
get 'reload_after_widget_field_changed',:action=>'reload_widget_field'
get 'reload_after_module_changed',:action=>'reload_widgets' get 'reload_after_module_changed',:action=>'reload_widgets'
get 'reload_after_list_changed',:action=> 'reload_widget_styles' get 'reload_after_list_changed',:action=> 'reload_widget_styles'
get 'reload_r_tag_options' get 'reload_r_tag_options'

View File

@ -66,7 +66,7 @@ module OrbitApp
end end
def get_sidebar_order! def get_sidebar_order!
@sidebar_order = get_module_app.sidebar_order @sidebar_order = (get_module_app.sidebar_order rescue 0)
end end
def get_module_app def get_module_app

View File

@ -98,11 +98,11 @@ module OrbitApp
def self.get_interface_args def self.get_interface_args
#will need to work with design #will need to work with design
{:name=>"default_widget",:field=>nil,:label=>'label',:style=>STYLE,:i18n=>'default_widget.default_widget'} {:name=>"default_widget",:field=>@fields,:style=>STYLE,:i18n=>'default_widget.default_widget'}
end end
def to_module_app_format def to_module_app_format
{:query=>@query,:image=>@image} rescue nil {"query"=>@query,"image"=>@image} rescue nil
end end
def link_field(field_name,setting) def link_field(field_name,setting)
@ -161,7 +161,7 @@ module OrbitApp
def to_hash def to_hash
{:name => @name,:fields=>@fields,:label=>@label,:style=>@style,:i18n=>@widget_i18n} {:name => @name,:fields=>@fields,:style=>@style,:i18n=>@widget_i18n}
end end
protected protected

View File

@ -439,5 +439,56 @@ namespace :migrate do
ma.save ma.save
end end
end end
task :cleanup_page_part_without_page => :environment do
pps = PagePart.all.select{|t| t.page.nil? }
pps.each{|t| t.destroy}
end
task :backup_module_app_info => :environment do
PagePart.all.each do |pp|
pp[:backup_module_app_key] = (pp.module_app ? pp.module_app.key : nil)
pp.save
puts pp.inspect
end
Page.all.each do |page|
page[:backup_module_app_key] = (page.module_app ? page.module_app.key : nil)
page.save
puts page.inspect
end
end
task :rebind_module_app => :environment do
Page.all.each do |page|
if page[:backup_module_app_key].nil?
page.module_app = nil
else
page.module_app = ModuleApp.where(:key=> page[:backup_module_app_key]).first
end
page.save
end
PagePart.all.each do |pp|
if pp[:backup_module_app_key].nil?
pp.module_app = nil
else
pp.module_app = ModuleApp.where(:key=> pp[:backup_module_app_key]).first
end
pp.save
end
end
task :clean_up_module_app_info => :environment do
Page.all.each do |page|
page.unset(:backup_module_app_key)
page.save
end
PagePart.all.each do |pp|
pp.unset(:backup_module_app_key)
pp.save
end
end
end end

View File

@ -1,4 +1,3 @@
zh_tw: zh_tw:
module_name:
ad_banner:
ad_banner: 廣告輪播 ad_banner: 廣告輪播

View File

@ -1,6 +1,6 @@
module AdBanner module AdBanner
OrbitApp.registration "AdBanner",:type=> 'ModuleApp' do OrbitApp.registration "AdBanner",:type=> 'ModuleApp' do
module_label 'miss_module_i18n.ad_banner' module_label 'module_name.ad_banner'
base_url File.expand_path File.dirname(__FILE__) base_url File.expand_path File.dirname(__FILE__)
# personal_plugin :enable => true,:path=>"panel/ad_banner/plugin/profile",:i18n=>'admin.ad_banner' # personal_plugin :enable => true,:path=>"panel/ad_banner/plugin/profile",:i18n=>'admin.ad_banner'

View File

@ -11,8 +11,8 @@ zh_tw:
editing_announcement_category: 編輯公告類別 editing_announcement_category: 編輯公告類別
error: error:
no_avilb_cate_for_posting: 公告必需有一個類別才能發送,請與管理員聯絡 no_avilb_cate_for_posting: 公告必需有一個類別才能發送,請與管理員聯絡
front_end: frontend:
bulletins: 請LIN給名字前台頁 bulletins: 公告前台
new_bulletin_category: 新增公告類別 new_bulletin_category: 新增公告類別
search: 搜尋公告 search: 搜尋公告
update_bulletin_success: 公告已成功更新 update_bulletin_success: 公告已成功更新

View File

@ -13,7 +13,7 @@ module Announcement
front_end do front_end do
app_page 'bulletins' do app_page 'bulletins' do
frontend_i18n "announcement.front_end.bulletins" frontend_i18n "announcement.frontend.bulletins"
end end
end end

View File

@ -6,6 +6,8 @@ zh_tw:
all: 全部檔案 all: 全部檔案
widget: widget:
archive_files: 檔案室Wiget archive_files: 檔案室Wiget
frontend:
archive: 檔案室前台
add: 新增 add: 新增
back: 回去 back: 回去
create: 創造 create: 創造

View File

@ -15,7 +15,9 @@ module Archive
update_info 'some update_info' update_info 'some update_info'
front_end do front_end do
app_page 'archive_files' app_page 'archive_files' do
frontend_i18n "archive.frontend.archive"
end
end end
widgets do widgets do

View File

@ -2,15 +2,13 @@ zh_tw:
miss_module_i18n: miss_module_i18n:
miss_plugin_i18n: # miss_plugin_i18n:
personal_book: Personal Book
personal_diploma: Personal Diploma # personal_experience: 經歷
personal_experience: Personal Experience # personal_honor: 榮譽
personal_honor: Personal Honor
personal_journal: Personal Journal
personal_lab: Personal Lab # personal_project: 研究計畫
personal_patent: Personal Patent # personal_research: 研究
personal_project: Personal Project # personal_conference: 研討會論文
personal_research: Personal Research
personal_conference: Personal Conference

View File

@ -5,3 +5,5 @@ zh_tw:
create_page_content_success: 頁面內容已成功建立 create_page_content_success: 頁面內容已成功建立
editing_page_content: 編輯頁面內容 editing_page_content: 編輯頁面內容
update_page_content_success: 頁面內容已成功更新 update_page_content_success: 頁面內容已成功更新
frontend:
page: 頁面前台

View File

@ -12,7 +12,9 @@ module PageContent
update_info 'some update_info' update_info 'some update_info'
front_end do front_end do
app_page 'page_contexts' app_page 'page_contexts' do
frontend_i18n "page_content.frontend.page"
end
end end
side_bar do side_bar do

View File

@ -1,7 +1,8 @@
zh_tw: zh_tw:
_locale: 中文 _locale: 中文
module_name:
personal_book: 專書
add: 新增 add: 新增
back: 回去 back: 回去
create: 創造 create: 創造

View File

@ -1,8 +1,8 @@
module PersonalBook module PersonalBook
OrbitApp.registration "Book",:type=> 'ModuleApp' do OrbitApp.registration "Book",:type=> 'ModuleApp' do
module_label 'miss_plugin_i18n.personal_book' module_label 'module_name.personal_book'
base_url File.expand_path File.dirname(__FILE__) base_url File.expand_path File.dirname(__FILE__)
personal_plugin :enable => true,:path=>"panel/personal_book/plugin/profile",:i18n=>'miss_module_i18n.personal_book' personal_plugin :enable => true,:path=>"panel/personal_book/plugin/profile",:i18n=>'module_name.personal_book'
end end

View File

@ -1,7 +1,8 @@
zh_tw: zh_tw:
_locale: 中文 _locale: 中文
module_name:
personal_conference: 研討會論文
add: 新增 add: 新增
back: 回去 back: 回去
create: 創造 create: 創造

View File

@ -1,8 +1,8 @@
module PersonalConference module PersonalConference
OrbitApp.registration "Conference",:type=> 'ModuleApp' do OrbitApp.registration "Conference",:type=> 'ModuleApp' do
module_label 'admin.personal_conference' module_label 'module_name.personal_conference'
base_url File.expand_path File.dirname(__FILE__) base_url File.expand_path File.dirname(__FILE__)
personal_plugin :enable => true,:path=>"panel/personal_conference/plugin/profile",:i18n=>'admin.personal_conference' personal_plugin :enable => true,:path=>"panel/personal_conference/plugin/profile",:i18n=>'module_name.personal_conference'
end end

View File

@ -1,7 +1,8 @@
zh_tw: zh_tw:
_locale: 中文 _locale: 中文
module_name:
personal_diploma: 學歷
add: 新增 add: 新增
back: 回去 back: 回去
create: 創造 create: 創造

View File

@ -1,8 +1,8 @@
module PersonalDiploma module PersonalDiploma
OrbitApp.registration "Diploma",:type=> 'ModuleApp' do OrbitApp.registration "Diploma",:type=> 'ModuleApp' do
module_label 'miss_plugin_i18n.personal_diploma' module_label 'module_name.personal_diploma'
base_url File.expand_path File.dirname(__FILE__) base_url File.expand_path File.dirname(__FILE__)
personal_plugin :enable => true,:path=>"panel/personal_diploma/plugin/profile",:i18n=>'miss_plugin_i18n.personal_diploma' personal_plugin :enable => true,:path=>"panel/personal_diploma/plugin/profile",:i18n=>'module_name.personal_diploma'
end end

View File

@ -1,7 +1,8 @@
zh_tw: zh_tw:
_locale: 中文 _locale: 中文
module_name:
personal_experience: 經歷
add: 新增 add: 新增
back: 回去 back: 回去
create: 創造 create: 創造

View File

@ -1,9 +1,9 @@
module PersonalExperience module PersonalExperience
OrbitApp.registration "Experience",:type=> 'ModuleApp' do OrbitApp.registration "Experience",:type=> 'ModuleApp' do
module_label 'miss_plugin_i18n.personal_experience' module_label 'module_name.personal_experience'
base_url File.expand_path File.dirname(__FILE__) base_url File.expand_path File.dirname(__FILE__)
personal_plugin :enable => true,:path=>"panel/personal_experience/plugin/profile",:i18n=>'miss_plugin_i18n.personal_experience' personal_plugin :enable => true,:path=>"panel/personal_experience/plugin/profile",:i18n=>'module_name.personal_experience'
end end

View File

@ -1,7 +1,8 @@
zh_tw: zh_tw:
_locale: 中文 _locale: 中文
module_name:
personal_honor: 榮譽
add: 新增 add: 新增
back: 回去 back: 回去
create: 創造 create: 創造

View File

@ -1,8 +1,8 @@
module PersonalHonor module PersonalHonor
OrbitApp.registration "Honor",:type=> 'ModuleApp' do OrbitApp.registration "Honor",:type=> 'ModuleApp' do
module_label 'miss_plugin_i18n.personal_honor' module_label 'module_name.personal_honor'
base_url File.expand_path File.dirname(__FILE__) base_url File.expand_path File.dirname(__FILE__)
personal_plugin :enable => true,:path=>"panel/personal_honor/plugin/profile",:i18n=>'miss_plugin_i18n.personal_honor' personal_plugin :enable => true,:path=>"panel/personal_honor/plugin/profile",:i18n=>'module_name.personal_honor'
end end

View File

@ -1,4 +1,6 @@
zh_tw: zh_tw:
module_name:
personal_journal: 期刊著作
personal_journal: personal_journal:
paper_title : "論文名稱" paper_title : "論文名稱"
journal_title : "期刊名稱" journal_title : "期刊名稱"

View File

@ -1,8 +1,8 @@
module PersonalJournal module PersonalJournal
OrbitApp.registration "Journal",:type=> 'ModuleApp' do OrbitApp.registration "Journal",:type=> 'ModuleApp' do
module_label 'miss_plugin_i18n.personal_journal' module_label 'module_name.personal_journal'
base_url File.expand_path File.dirname(__FILE__) base_url File.expand_path File.dirname(__FILE__)
personal_plugin :enable => true,:path=>"panel/personal_journal/plugin/profile",:i18n=>'miss_plugin_i18n.personal_journal' personal_plugin :enable => true,:path=>"panel/personal_journal/plugin/profile",:i18n=>'module_name.personal_journal'
end end

View File

@ -1,7 +1,8 @@
zh_tw: zh_tw:
_locale: 中文 _locale: 中文
module_name:
personal_lab: 實驗室
add: 新增 add: 新增
back: 回去 back: 回去
create: 創造 create: 創造

View File

@ -1,8 +1,8 @@
module PersonalLab module PersonalLab
OrbitApp.registration "Lab",:type=> 'ModuleApp' do OrbitApp.registration "Lab",:type=> 'ModuleApp' do
module_label 'miss_plugin_i18n.personal_lab' module_label 'module_name.personal_lab'
base_url File.expand_path File.dirname(__FILE__) base_url File.expand_path File.dirname(__FILE__)
personal_plugin :enable => true,:path=>"panel/personal_lab/plugin/profile",:i18n=>'miss_plugin_i18n.personal_lab' personal_plugin :enable => true,:path=>"panel/personal_lab/plugin/profile",:i18n=>'module_name.personal_lab'
end end

View File

@ -1,7 +1,8 @@
zh_tw: zh_tw:
_locale: 中文 _locale: 中文
module_name:
personal_patent: 專利
add: 新增 add: 新增
back: 回去 back: 回去
create: 創造 create: 創造

View File

@ -1,8 +1,8 @@
module PersonalPatent module PersonalPatent
OrbitApp.registration "Patent",:type=> 'ModuleApp' do OrbitApp.registration "Patent",:type=> 'ModuleApp' do
module_label 'miss_plugin_i18n.personal_patent' module_label 'module_name.personal_patent'
base_url File.expand_path File.dirname(__FILE__) base_url File.expand_path File.dirname(__FILE__)
personal_plugin :enable => true,:path=>"panel/personal_patent/plugin/profile",:i18n=>'miss_plugin_i18n.personal_patent' personal_plugin :enable => true,:path=>"panel/personal_patent/plugin/profile",:i18n=>'module_name.personal_patent'
end end

View File

@ -1,7 +1,8 @@
zh_tw: zh_tw:
_locale: 中文 _locale: 中文
module_name:
personal_project: 研究計畫
add: 新增 add: 新增
back: 回去 back: 回去
create: 創造 create: 創造

View File

@ -1,8 +1,8 @@
module PersonalProject module PersonalProject
OrbitApp.registration "Research Project",:type=> 'ModuleApp' do OrbitApp.registration "Research Project",:type=> 'ModuleApp' do
module_label 'miss_plugin_i18n.personal_project' module_label 'module_name.personal_project'
base_url File.expand_path File.dirname(__FILE__) base_url File.expand_path File.dirname(__FILE__)
personal_plugin :enable => true,:path=>"panel/personal_project/plugin/profile",:i18n=>'miss_plugin_i18n.personal_project' personal_plugin :enable => true,:path=>"panel/personal_project/plugin/profile",:i18n=>'module_name.personal_project'
end end

View File

@ -1,7 +1,8 @@
zh_tw: zh_tw:
_locale: 中文 _locale: 中文
module_name:
personal_research: 研究
add: 新增 add: 新增
back: 回去 back: 回去
create: 創造 create: 創造

View File

@ -1,8 +1,8 @@
module PersonalResearch module PersonalResearch
OrbitApp.registration "Research",:type=> 'ModuleApp' do OrbitApp.registration "Research",:type=> 'ModuleApp' do
module_label 'miss_plugin_i18n.personal_research' module_label 'module_name.personal_research'
base_url File.expand_path File.dirname(__FILE__) base_url File.expand_path File.dirname(__FILE__)
personal_plugin :enable => true,:path=>"panel/personal_research/plugin/profile",:i18n=>'miss_plugin_i18n.personal_research' personal_plugin :enable => true,:path=>"panel/personal_research/plugin/profile",:i18n=>'module_name.personal_research'
end end