forked from spen/seminar
Fix bug.
This commit is contained in:
parent
b0e1d024e6
commit
297f764f96
|
@ -47,6 +47,9 @@ class Admin::SeminarsController < OrbitAdminController
|
|||
@seminar_template_setting = SeminarTemplateSetting.create(:seminar_main=>@seminar)
|
||||
end
|
||||
@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 = []
|
||||
if @seminar_page_root
|
||||
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 = available_locales.map{|l| l.to_s}
|
||||
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)
|
||||
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
|
||||
@seminar_page_root = @seminar_template_setting.create_seminar_pages
|
||||
end
|
||||
@items = @seminar_page_root.child_page
|
||||
@parent_pages = []
|
||||
|
|
|
@ -10,7 +10,7 @@ class SeminarSignup
|
|||
field :status
|
||||
field :name # become Last 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 :fax, type: String
|
||||
field :email, type: String
|
||||
|
@ -33,7 +33,12 @@ class SeminarSignup
|
|||
|
||||
before_create do
|
||||
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?
|
||||
s = SeminarMain.find(self.seminar_main)
|
||||
s.last_serial_number += 1
|
||||
|
@ -87,10 +92,11 @@ class SeminarSignup
|
|||
field_name = set.field_name
|
||||
next if set.disabled || except_fields.include?(field_name)
|
||||
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"
|
||||
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?}
|
||||
value = ""
|
||||
if values.count == 0
|
||||
|
|
|
@ -21,40 +21,7 @@ class SeminarTemplateSetting
|
|||
has_many :seminar_banner_images, :autosave => true, :dependent => :destroy
|
||||
accepts_nested_attributes_for :seminar_banner_images, :allow_destroy => true
|
||||
after_create do
|
||||
if 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 = {"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
|
||||
self.create_seminar_pages
|
||||
end
|
||||
after_save do
|
||||
if self.display_menu_changed?
|
||||
|
@ -84,6 +51,40 @@ class SeminarTemplateSetting
|
|||
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
|
||||
app_path = Pathname.new(__FILE__).dirname.dirname
|
||||
@@background_style_infos = {}
|
||||
|
|
Loading…
Reference in New Issue