Merge branch 'master' into 'master'

Fix bug.

See merge request spen/seminar!49
This commit is contained in:
chiu 2022-08-20 06:17:49 +00:00
commit 75ed82e94d
3 changed files with 49 additions and 61 deletions

View File

@ -47,6 +47,9 @@ class Admin::SeminarsController < OrbitAdminController
@seminar_template_setting = SeminarTemplateSetting.create(:seminar_main=>@seminar) @seminar_template_setting = SeminarTemplateSetting.create(:seminar_main=>@seminar)
end end
@seminar_page_root = Page.where(:parent_page_id=>params[:id]).first @seminar_page_root = Page.where(:parent_page_id=>params[:id]).first
if @seminar_page_root.nil?
@seminar_page_root = @seminar_template_setting.create_seminar_pages
end
display_menu = [] display_menu = []
if @seminar_page_root if @seminar_page_root
default_display_menu = SeminarTemplateSetting::DefaultMenu default_display_menu = SeminarTemplateSetting::DefaultMenu
@ -77,29 +80,7 @@ class Admin::SeminarsController < OrbitAdminController
available_locales = Site.first.in_use_locales rescue I18n.available_locales available_locales = Site.first.in_use_locales rescue I18n.available_locales
available_locales = available_locales.map{|l| l.to_s} available_locales = available_locales.map{|l| l.to_s}
if @seminar_page_root.nil? if @seminar_page_root.nil?
@seminar_page_root = Page.create(:parent_page_id=>params[:id],:module=>"seminars_home",:name_translations=>@seminar.title_translations,:url=>"/home",:page_id=>"home",:enabled_for=>available_locales,:bind_uid=>@seminar.uid,:bind_module_app=>"seminar",:bind_model=>"SeminarMain",:menu_enabled_for=>available_locales) @seminar_page_root = @seminar_template_setting.create_seminar_pages
else
@seminar_page_root.update(:name_translations=>@seminar.title_translations,:module=>"seminars_home",:url=>"/home",:page_id=>"home",:enabled_for=>available_locales,:bind_uid=>@seminar.uid,:bind_module_app=>"seminar",:bind_model=>"SeminarMain",:menu_enabled_for=>available_locales)
end
pages_info = SeminarTemplateSetting::PagesInfo
relation_model = {"news" => "CustomBulletin","album"=>"CustomAlbum"}
pages_info.each do |page_id , page_module|
seminar_page = @seminar_page_root.child_page.where(:page_id=>page_id).first
page_trans = available_locales.map{|l| [l,I18n.with_locale(l){I18n.t("seminar.menu.#{page_id}")}]}.to_h
available_locales_tmp = available_locales.clone
if relation_model[page_id]
relation = relation_model[page_id].constantize rescue nil
if relation
if relation.where(:bind_uid=>@seminar.uid).count == 0
available_locales_tmp = []
end
end
end
if seminar_page.nil?
seminar_page = @seminar_page_root.child_page.create(:name_translations=>page_trans,:page_id=>page_id,:url=>"/home/#{page_id}",:enabled_for=>available_locales_tmp,:module=>page_module,:menu_enabled_for=>available_locales_tmp)
else
seminar_page.update(:name_translations=>page_trans,:page_id=>page_id,:url=>"/home/#{page_id}",:module=>page_module)
end
end end
@items = @seminar_page_root.child_page @items = @seminar_page_root.child_page
@parent_pages = [] @parent_pages = []

View File

@ -10,7 +10,7 @@ class SeminarSignup
field :status field :status
field :name # become Last Name for TICC field :name # become Last Name for TICC
field :tel, type: String # become First Name for TICC field :tel, type: String # become First Name for TICC
field :unit, localize: true field :unit, localize: true #Only localize for preserving old record
field :phone, type: String field :phone, type: String
field :fax, type: String field :fax, type: String
field :email, type: String field :email, type: String
@ -33,7 +33,12 @@ class SeminarSignup
before_create do before_create do
unit = self.unit_translations.values.select{|v| v.present?}.first unit = self.unit_translations.values.select{|v| v.present?}.first
self.unit_translations = I18n.available_locales.map{|l| [l.to_s,unit]}.to_h tmp_unit_translations = self.unit_translations
self.unit_translations = I18n.available_locales.map do |l|
l = l.to_s
tmp = tmp_unit_translations[l]
[l, (tmp ? tmp : unit)]
end.to_h
if self.serial_number.nil? if self.serial_number.nil?
s = SeminarMain.find(self.seminar_main) s = SeminarMain.find(self.seminar_main)
s.last_serial_number += 1 s.last_serial_number += 1
@ -87,10 +92,11 @@ class SeminarSignup
field_name = set.field_name field_name = set.field_name
next if set.disabled || except_fields.include?(field_name) next if set.disabled || except_fields.include?(field_name)
value = self.send(field_name) rescue nil value = self.send(field_name) rescue nil
next if value.nil? localize = self.fields[field_name].options[:localize]
next if value.nil? && !localize
if field_name == "status" if field_name == "status"
value = I18n.t("seminar.registration_status_#{value}") value = I18n.t("seminar.registration_status_#{value}")
elsif self.fields[field_name].options[:localize] elsif localize && field_name != "unit"
values = self.send("#{field_name}_translations").select{|k,v| v.present?} values = self.send("#{field_name}_translations").select{|k,v| v.present?}
value = "" value = ""
if values.count == 0 if values.count == 0

View File

@ -21,40 +21,7 @@ class SeminarTemplateSetting
has_many :seminar_banner_images, :autosave => true, :dependent => :destroy has_many :seminar_banner_images, :autosave => true, :dependent => :destroy
accepts_nested_attributes_for :seminar_banner_images, :allow_destroy => true accepts_nested_attributes_for :seminar_banner_images, :allow_destroy => true
after_create do after_create do
if self.seminar_main self.create_seminar_pages
@seminar_page_root = Page.where(:parent_page_id=>self.seminar_main_id).first
available_locales = Site.first.in_use_locales rescue I18n.available_locales
available_locales = available_locales.map{|l| l.to_s}
if @seminar_page_root.nil?
@seminar_page_root = Page.create(:parent_page_id=>self.seminar_main_id,:module=>"seminars_home",:name_translations=>@seminar.title_translations,:url=>"/home",:page_id=>"home",:enabled_for=>available_locales,:bind_uid=>@seminar.uid,:bind_module_app=>"seminar",:bind_model=>"SeminarMain",:menu_enabled_for=>available_locales)
else
@seminar_page_root.update(:name_translations=>@seminar.title_translations,:module=>"seminars_home",:url=>"/home",:page_id=>"home",:enabled_for=>available_locales,:bind_uid=>@seminar.uid,:bind_module_app=>"seminar",:bind_model=>"SeminarMain",:menu_enabled_for=>available_locales)
end
pages_info = {"introduction" => "seminars_page",
"news" => "custom_announcement",
"registration" => "seminar_registration",
"submission" => "seminar_submission",
"album" => "custom_gallery"}
relation_model = {"news" => "CustomBulletin","album"=>"CustomAlbum"}
pages_info.each do |page_id , page_module|
seminar_page = @seminar_page_root.child_page.where(:page_id=>page_id).first
page_trans = available_locales.map{|l| [l,I18n.with_locale(l){I18n.t("seminar.menu.#{page_id}")}]}.to_h
available_locales_tmp = available_locales.clone
if relation_model[page_id]
relation = relation_model[page_id].constantize rescue nil
if relation
if relation.where(:bind_uid=>@seminar.uid).count == 0
available_locales_tmp = []
end
end
end
if seminar_page.nil?
seminar_page = @seminar_page_root.child_page.create(:name_translations=>page_trans,:page_id=>page_id,:url=>"/home/#{page_id}",:enabled_for=>available_locales_tmp,:module=>page_module,:menu_enabled_for=>available_locales_tmp)
else
seminar_page.update(:name_translations=>page_trans,:page_id=>page_id,:url=>"/home/#{page_id}",:module=>page_module)
end
end
end
end end
after_save do after_save do
if self.display_menu_changed? if self.display_menu_changed?
@ -84,6 +51,40 @@ class SeminarTemplateSetting
end end
end end
end end
def create_seminar_pages
if self.seminar_main
@seminar = self.seminar_main
@seminar_page_root = Page.where(:parent_page_id=>self.seminar_main_id).first
available_locales = Site.first.in_use_locales rescue I18n.available_locales
available_locales = available_locales.map{|l| l.to_s}
if @seminar_page_root.nil?
@seminar_page_root = Page.create(:parent_page_id=>self.seminar_main_id,:module=>"seminars_home",:name_translations=>@seminar.title_translations,:url=>"/home",:page_id=>"home",:enabled_for=>available_locales,:bind_uid=>@seminar.uid,:bind_module_app=>"seminar",:bind_model=>"SeminarMain",:menu_enabled_for=>available_locales)
else
@seminar_page_root.update(:name_translations=>@seminar.title_translations,:module=>"seminars_home",:url=>"/home",:page_id=>"home",:enabled_for=>available_locales,:bind_uid=>@seminar.uid,:bind_module_app=>"seminar",:bind_model=>"SeminarMain",:menu_enabled_for=>available_locales)
end
pages_info = PagesInfo
relation_model = {"news" => "CustomBulletin","album"=>"CustomAlbum"}
pages_info.each do |page_id , page_module|
seminar_page = @seminar_page_root.child_page.where(:page_id=>page_id).first
page_trans = available_locales.map{|l| [l,I18n.with_locale(l){I18n.t("seminar.menu.#{page_id}")}]}.to_h
available_locales_tmp = available_locales.clone
if relation_model[page_id]
relation = relation_model[page_id].constantize rescue nil
if relation
if relation.where(:bind_uid=>@seminar.uid).count == 0
available_locales_tmp = []
end
end
end
if seminar_page.nil?
seminar_page = @seminar_page_root.child_page.create(:name_translations=>page_trans,:page_id=>page_id,:url=>"/home/#{page_id}",:enabled_for=>available_locales_tmp,:module=>page_module,:menu_enabled_for=>available_locales_tmp)
else
seminar_page.update(:name_translations=>page_trans,:page_id=>page_id,:url=>"/home/#{page_id}",:module=>page_module)
end
end
return @seminar_page_root
end
end
def self.initialize_variables def self.initialize_variables
app_path = Pathname.new(__FILE__).dirname.dirname app_path = Pathname.new(__FILE__).dirname.dirname
@@background_style_infos = {} @@background_style_infos = {}