diff --git a/app/assets/javascripts/admin/olympiamanagement.js b/app/assets/javascripts/admin/olympiamanagement.js
index cf2cbbb..81b3f3a 100644
--- a/app/assets/javascripts/admin/olympiamanagement.js
+++ b/app/assets/javascripts/admin/olympiamanagement.js
@@ -39,5 +39,5 @@ $(document).ready(function(){
for(var i = 0 ; i < $el.length ; i++)
if($el.eq(i).attr('value') != "" && $el.eq(i).attr('value') != undefined)
$el.eq(i).find('option[value='+$el.eq(i).attr('value')+']').attr('selected','selected');
- CKEDITOR.replaceAll();
+ try{CKEDITOR.replaceAll()}catch(e){console.log(e)};
});
\ No newline at end of file
diff --git a/app/controllers/admin/olympiamanagements_controller.rb b/app/controllers/admin/olympiamanagements_controller.rb
index 08be929..7b327d7 100644
--- a/app/controllers/admin/olympiamanagements_controller.rb
+++ b/app/controllers/admin/olympiamanagements_controller.rb
@@ -46,10 +46,7 @@ class Admin::OlympiamanagementsController < OrbitAdminController
elsif params[:type] == 'add_school_data'
@olympia_school_data_field = (params[:id].nil? ? OlympiaSchoolDataFields.new : ((OlympiaSchoolDataFields.find(params[:id]).nil? rescue true) ? OlympiaSchoolDataFields.new : OlympiaSchoolDataFields.find(params[:id])))
params['add_school_data'].keys.each do |field|
- #if
@olympia_school_data_field[field] = params['add_school_data'][field]
- #elsif
- #ClassSettingFields.all.select{|field| field.class_number_range[0]<6 && field.class_number_range[1] > 6}
end
@olympia_school_data_field.save
redirect_to admin_olympiamanagements_school_data_list_path
@@ -213,7 +210,7 @@ class Admin::OlympiamanagementsController < OrbitAdminController
@site_locales.insert(0,I18n.locale)
end
def export_school_connection_data
- @OlympiaSchoolDataFields = OlympiaSchoolDataFields.all
+ @OlympiaSchoolDataFields = OlympiaSchoolDataFields.all.asc(:id)
dir_path = 'tmp/olypiamanagement/'
#FileUtils.rm_r(dir_path, :force => true) if Dir.exist?(dir_path)
FileUtils.mkdir dir_path if !Dir.exist?(dir_path) #create dir for storing tmp_file if dir doesn't exist
@@ -227,7 +224,7 @@ class Admin::OlympiamanagementsController < OrbitAdminController
send_data(tmp_filename_data, type: 'application/xlsx', disposition: 'attachment', filename: @filename)
end
def export_sign_up_student_data
- # @OlympiaSchoolDataFields = OlympiaSchoolDataFields.all
+ # @OlympiaSchoolDataFields = OlympiaSchoolDataFields.all.asc(:id)
# dir_path = 'tmp/olypiamanagement/'
# #FileUtils.rm_r(dir_path, :force => true) if Dir.exist?(dir_path)
# FileUtils.mkdir dir_path if !Dir.exist?(dir_path) #create dir for storing tmp_file if dir doesn't exist
@@ -246,7 +243,7 @@ class Admin::OlympiamanagementsController < OrbitAdminController
@olympia_school_data_field = OlympiaSchoolDataFields.new
end
def download_import_file
- @OlympiaSchoolDataFields = OlympiaSchoolDataFields.all
+ @OlympiaSchoolDataFields = OlympiaSchoolDataFields.all.asc(:id)
dir_path = 'tmp/olypiamanagement/'
#FileUtils.rm_r(dir_path, :force => true) if Dir.exist?(dir_path)
FileUtils.mkdir dir_path if !Dir.exist?(dir_path) #create dir for storing tmp_file if dir doesn't exist
diff --git a/app/controllers/olympiamanagements_controller.rb b/app/controllers/olympiamanagements_controller.rb
index c3067e8..d7f2438 100644
--- a/app/controllers/olympiamanagements_controller.rb
+++ b/app/controllers/olympiamanagements_controller.rb
@@ -21,78 +21,97 @@ class OlympiamanagementsController < PagesController
uid = OrbitHelper.params[:uid] rescue ""
tags = OrbitHelper.widget_tags
categories = OrbitHelper.widget_categories || []
- @sign_up_setting = SignUpSetting.last
+ set_sign_up_setting
+ @time_arr = ["year","month","day","o_clock","minute"]
+ start_time_str = @time_arr.map{|t| @sign_up_setting["start_"+t]}.join(' ')
+ end_time_str = @time_arr.map{|t| @sign_up_setting["end_"+t]}.join(' ')
+ time_now_str = Time.now.strftime("%Y %m %d %H %M")
+ @instructions_name = {}
+ Site.first.in_use_locales.each do |locale|
+ I18n.with_locale(locale) do
+ @instructions_name[locale.to_s] = I18n.t('olympiamanagement.registration_instructions')
+ end
+ end
+ @page = Page.where(:layout=>"olympia_managements_index",:parent_page_id=>(Page.where(:name=> ((I18n.locale.to_s == "en") ? "Home" : "首頁")).first.id)).first
+ @instructions_pages = Page.where(:parent_page_id=>@page.id).select{|page| page.name_translations==@instructions_name}
case OrbitHelper.params[:layout_type]
when "olympia_managements_instructions_index"
- @olympiamanagement_instruction = @sign_up_setting.registration_instructions[I18n.locale.to_s].to_s
- @sign_up_setting.attributes.to_h.each do |key,value|
- @olympiamanagement_instruction = @olympiamanagement_instruction.gsub("{{#{key}}}",value.to_s)
+ if !(time_now_str <= end_time_str && time_now_str >= start_time_str)
+ @olympiamanagement_instruction = @sign_up_setting.registration_instructions[I18n.locale.to_s].to_s
+ @sign_up_setting.attributes.to_h.each do |key,value|
+ @olympiamanagement_instruction = @olympiamanagement_instruction.gsub("{{#{key}}}",value.to_s)
+ end
+ if !OrbitHelper.current_user.nil?
+ @edit_link = '/admin/olympiamanagements/sign_up_setting#registration_instructions'
+ @edit_text = (I18n.locale.to_s == "zh_tw") ? "編輯" : "Edit"
+ if !OrbitHelper.current_user.nil?
+ @olympiamanagement_instruction += '
'+@edit_text+'
'
+ end
+ end
+ data_arr = @page.child_page.map{|page| {:url=>"/#{I18n.locale}#{page.url}",:name=>page.name}}
+ @breadcumb = render_to_string(:formats=> [:html] ,:partial=>'breadcumb',:locals=>{:data_arr=>data_arr})
+ @olympiamanagement_instruction = @breadcumb + @olympiamanagement_instruction.html_safe
+ else
+ if !@instructions_pages.empty?
+ @instructions_pages.each{|page| page.destroy}
+ end
+ @olympiamanagement_instruction = ''+t('olympiamanagement.sign_up_hint')+'
'
end
- @edit_link = '/admin/olympiamanagements/sign_up_setting#registration_instructions'
- @edit_text = (I18n.locale.to_s == "zh_tw") ? "編輯" : "Edit"
- if !OrbitHelper.current_user.nil?
- @olympiamanagement_instruction += ' '+@edit_text+'
'
- end
- #sign_up_hint
{
"olympiamanagement" => [],
"extras"=>{"instructions"=> @olympiamanagement_instruction}
}
when "olympia_managements_index"
- @time_arr = ["year","month","day","o_clock","minute"]
- start_time_str = @time_arr.map{|t| @sign_up_setting["start_"+t]}.join(' ')
- end_time_str = @time_arr.map{|t| @sign_up_setting["end_"+t]}.join(' ')
- time_now_str = Time.now.strftime("%Y %m %d %H %M")
- if time_now_str <= end_time_str && time_now_str >= start_time_str
- @error = nil
- @page_content
- if !OrbitHelper.params[:login_id].to_s.blank?
- if OlympiaSchoolDataFields.where(:account_number=>OrbitHelper.params[:login_id]).length == 0
- @error = "no_account"
- else
- if OlympiaSchoolDataFields.where(:account_number=>OrbitHelper.params[:login_id]).first.password != OrbitHelper.params[:login_pw]
- @error = "password_error"
- else
- @@session[:olympia_login_id] = OrbitHelper.params[:login_id]
- end
- end
- end
- if @@session[:olympia_login_id].to_s.blank?
- @page_content = render_to_string(:formats=> [:html] ,:partial=>'login')
- else
- @page_content = @breadcumb
-
- end
- {
- "olympiamanagement" => [],
- "extras"=>{"instructions"=> @page_content}
- }
- else
- #@page_content = ''+t('olympiamanagement.sign_up_hint')+'
'
- @error = nil
- @page_content
- if !OrbitHelper.params[:login_id].to_s.blank?
- if OlympiaSchoolDataFields.where(:account_number=>OrbitHelper.params[:login_id]).length == 0
- @error = "no_account"
- else
- if OlympiaSchoolDataFields.where(:account_number=>OrbitHelper.params[:login_id]).first.password != OrbitHelper.params[:login_pw]
- @error = "password_error"
- else
- @@session[:olympia_login_id] = OrbitHelper.params[:login_id]
- end
- end
- end
- if @@session[:olympia_login_id].to_s.blank?
- @page_content = render_to_string(:formats=> [:html] ,:partial=>'login')
- else
- @page_content = @breadcumb
-
- end
- {
- "olympiamanagement" => [],
- "extras"=>{"page_content"=> @page_content}
- }
+ if Page.where(:parent_page_id=>@page.id,:name=>@page.name).length == 0
+ @newpage = Page.create(:layout=> @page.layout,:data_count=>@page.data_count,:parent_page_id=>@page.id,:url=>@page.url,
+ :menu_enabled_for=>@page.menu_enabled_for,:enabled_for_sitemap=>@page.enabled_for_sitemap,:enabled_for=>@page.enabled_for,:module=>@page[:module],:page_id=>@page.page_id)
+ @newpage.name_translations = @page.name_translations
+ @newpage.save
+ @newpage = Page.create(:layout=> "olympia_managements_instructions_index",:data_count=>@page.data_count,:parent_page_id=>@page.id,:url=>"/olympia_instructions",
+ :menu_enabled_for=>@page.menu_enabled_for,:enabled_for_sitemap=>@page.enabled_for_sitemap,:enabled_for=>@page.enabled_for,:module=>@page[:module],:page_id=>'olympia_instructions')
+ @newpage.name_translations = @instructions_name
+ @newpage.save
end
+ @error = nil
+ @page_content
+ if !(time_now_str <= end_time_str && time_now_str >= start_time_str)
+ if @instructions_pages.empty?
+ @newpage = Page.create(:layout=> "olympia_managements_instructions_index",:data_count=>@page.data_count,:parent_page_id=>@page.id,:url=>"/olympia_instructions",
+ :menu_enabled_for=>@page.menu_enabled_for,:enabled_for_sitemap=>@page.enabled_for_sitemap,:enabled_for=>@page.enabled_for,:module=>@page[:module],:page_id=>'olympia_instructions')
+ @newpage.name_translations = @instructions_name
+ @newpage.save
+ elsif @instructions_pages.length != 1
+ @instructions_pages.slice(1,@instructions_pages.length).each{|page| page.destroy}
+ end
+ if !OrbitHelper.params[:login_id].to_s.blank?
+ if OlympiaSchoolDataFields.where(:account_number=>OrbitHelper.params[:login_id]).length == 0
+ @error = "no_account"
+ else
+ if OlympiaSchoolDataFields.where(:account_number=>OrbitHelper.params[:login_id]).first.password != OrbitHelper.params[:login_pw]
+ @error = "password_error"
+ else
+ @@session[:olympia_login_id] = OrbitHelper.params[:login_id]
+ end
+ end
+ end
+ if @@session[:olympia_login_id].to_s.blank?
+ @page_content = render_to_string(:formats=> [:html] ,:partial=>'login')
+ else
+ @page_content = @breadcumb
+
+ end
+ else
+ if !@instructions_pages.empty?
+ @instructions_pages.each{|page| page.destroy}
+ end
+ data_arr = @page.child_page.map{|page| {:url=>"/#{I18n.locale}#{page.url}",:name=>page.name}}
+ @breadcumb = render_to_string(:formats=> [:html] ,:partial=>'breadcumb',:locals=>{:data_arr=>data_arr})
+ @page_content = @breadcumb+''+t('olympiamanagement.sign_up_hint')+'
'
+ end
+ {
+ "olympiamanagement" => [],
+ "extras"=>{"page_content"=> @page_content}
+ }
end
end
def school_connection_data
@@ -101,11 +120,23 @@ class OlympiamanagementsController < PagesController
end_time_str = @time_arr.map{|t| @sign_up_setting["end_"+t]}.join(' ')
time_now_str = Time.now.strftime("%Y %m %d %H %M")
if !(time_now_str <= end_time_str && time_now_str >= start_time_str) || session[:olympia_login_id].to_s.blank?
- render_contents_in_index_page#redirect_to :back
+ @school_data_fields = [{'account_number'=>{'type'=>'String','size'=>'20','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true",'readonly'=>"readonly"}},
+ {'school_name'=>{'type'=>'String','size'=>'20','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true",'readonly'=>"readonly"}},
+ {'school_code'=>{'type'=>'String','size'=>'20','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true",'readonly'=>"readonly"}},
+ {'school_address'=>{'type'=>'String','size'=>'40','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true",'readonly'=>"readonly"}},
+ {'class_number'=>{'type'=>'String','size'=>'5','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true",'readonly'=>"readonly"}},
+ {'enrollment_limited'=>{'type'=>'Fixnum','size'=>'5','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true",'readonly'=>"readonly"}},
+ {'school_contact_person_name'=>{'type'=>'String','size'=>'20','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true"}},
+ {'department_job_title'=>{'type'=>'String','size'=>'20','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true"}},
+ {'office_tel_number'=>{'type'=>'String','size'=>'20','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true"}},
+ {'fax'=>{'type'=>'String','size'=>'20','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true"}},
+ {'mobile_number'=>{'type'=>'String','size'=>'20','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true"}},
+ {'email'=>{'type'=>'String','size'=>'40','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true"}}]
+ @olympia_school_data_field = OlympiaSchoolDataFields.where(:account_number=>session[:olympia_login_id]).first
+ @page_content = render_to_string(:formats=> [:html] ,:partial=>'edit_school_data.html',:locals=>{:@school_data_fields=>@school_data_fields,:@olympia_school_data_field=>@olympia_school_data_field})
+ render_contents_in_index_page(@breadcumb+@page_content)#redirect_to :back
else
- if params[:type].to_s == "update_school_data"
- redirect_to :back
- end
+ redirect_to :back
end
end
def add_sign_up_student_data
@@ -113,10 +144,10 @@ class OlympiamanagementsController < PagesController
start_time_str = @time_arr.map{|t| @sign_up_setting["start_"+t]}.join(' ')
end_time_str = @time_arr.map{|t| @sign_up_setting["end_"+t]}.join(' ')
time_now_str = Time.now.strftime("%Y %m %d %H %M")
- if !(time_now_str <= end_time_str && time_now_str >= start_time_str) || @@session[:olympia_login_id].to_s.blank?
+ if !(!(time_now_str <= end_time_str && time_now_str >= start_time_str) || session[:olympia_login_id].to_s.blank?)
redirect_to :back
else
- @olympia_school_data_field = OlympiaSchoolDataFields.where(:account_number=>@@session[:olympia_login_id]).first
+ @olympia_school_data_field = OlympiaSchoolDataFields.where(:account_number=>session[:olympia_login_id]).first
redirect_to :back if @olympia_school_data_field.nil?
@required_fields = [:school_contact_person_name,:department_job_title,:office_tel_number,:fax,:mobile_number,:email]
@flag = true
@@ -126,18 +157,50 @@ class OlympiamanagementsController < PagesController
break
end
end
+ if !@flag
+ I18n.t('olympiamanagement.please_set_school_connect_data')
+ render_contents_in_index_page(@breadcumb+"#{I18n.t('olympiamanagement.please_set_school_connect_data')}
".html_safe)
+ else
+ render_contents_in_index_page(@breadcumb)
+ end
#if @flag = false
end
end
def sign_up_student_data_list
end
def edit_password
+ if !session[:olympia_login_id].to_s.blank?
+ if params[:confirm_password].nil? && params[:new_password].nil?
+ @page_content = render_to_string(:formats=> [:html] ,:partial=>'edit_password.html',:locals=>{:@error=>(@@error rescue nil)})
+ render_contents_in_index_page(@breadcumb+@page_content)
+ else
+ @@error = nil
+ if params[:confirm_password].to_s != params[:new_password].to_s
+ @@error = "confirm_password_error"
+ elsif params[:confirm_password].to_s.blank? && params[:new_password].to_s.blank?
+ @@error = "password_all_empty"
+ elsif params[:confirm_password].to_s.blank?
+ @@error = "confirm_password_empty"
+ elsif params[:new_password].to_s.blank?
+ @@error = "new_password_empty"
+ else
+ @olympia_school_data_field = OlympiaSchoolDataFields.where(:account_number=>session[:olympia_login_id]).first
+ @olympia_school_data_field.password = params[:new_password]
+ @olympia_school_data_field.save
+ end
+ redirect_to edit_password_olympiamanagements_path
+ end
+ else
+ @page = Page.where(:layout=>"olympia_managements_index",:parent_page_id=>(Page.where(:name=> ((I18n.locale.to_s == "en") ? "Home" : "首頁")).first.id)).first
+ redirect_to "/#{I18n.locale}#{@page.url}"
+ end
end
def print_registration_form
end
def logout
session[:olympia_login_id] = ""
- redirect_to :back
+ @page = Page.where(:layout=>"olympia_managements_index",:parent_page_id=>(Page.where(:name=> ((I18n.locale.to_s == "en") ? "Home" : "首頁")).first.id)).first
+ redirect_to "/#{I18n.locale}#{@page.url}"#render :html => session.to_hash
end
def widget
uid = OrbitHelper.params[:uid] rescue ""
@@ -154,7 +217,7 @@ class OlympiamanagementsController < PagesController
}
end
def download_school_code
- @OlympiaSchoolDataFields = OlympiaSchoolDataFields.all.asc(:school_code)
+ @OlympiaSchoolDataFields = OlympiaSchoolDataFields.all.asc(:id)
dir_path = 'tmp/olypiamanagement/'
#FileUtils.rm_r(dir_path, :force => true) if Dir.exist?(dir_path)
FileUtils.mkdir dir_path if !Dir.exist?(dir_path) #create dir for storing tmp_file if dir doesn't exist
@@ -170,15 +233,21 @@ class OlympiamanagementsController < PagesController
def render_contents_in_index_page(contents=@breadcumb)
doc = Nokogiri::HTML(render_final_page("page",Page.where(:layout=>"olympia_managements_index").first,true), nil, "UTF-8")
viewarea = doc.css("*[data-content='true']")[0]
- viewarea.inner_html = @breadcumb
+ viewarea.inner_html = contents
render :html => doc.to_html.html_safe
end
def updata_school_data
- # doc = Nokogiri::HTML(render_final_page("page",Page.where(:layout=>"olympia_managements_index").first,true), nil, "UTF-8")
- # viewarea = doc.css("*[data-content='true']")[0]
- # viewarea.inner_html = "123"
- # render :html => doc.to_html.html_safe
- render_contents_in_index_page('123')
+ @readonly_fields = ['account_number','password','school_name','school_code','school_address','class_number','enrollment_limited']
+ @olympia_school_data_field = OlympiaSchoolDataFields.where(:account_number=>params[:olympia_user_name]).first
+ redirect_to :back if @olympia_school_data_field.nil?
+ params['add_school_data'].keys.each do |field|
+ if !@readonly_fields.include?(field)
+ @olympia_school_data_field[field] = params['add_school_data'][field]
+ end
+ end
+ @olympia_school_data_field.save
+ redirect_to add_sign_up_student_data_olympiamanagements_path
+ #render_contents_in_index_page(@olympia_school_data_field.attributes.to_s)
end
def updata_student_data
#render :html => '123'
diff --git a/app/models/olympia_school_data_fields.rb b/app/models/olympia_school_data_fields.rb
index c99d6ba..6a16fab 100644
--- a/app/models/olympia_school_data_fields.rb
+++ b/app/models/olympia_school_data_fields.rb
@@ -19,22 +19,26 @@ class OlympiaSchoolDataFields
field :fax , type: String , default: ''
field :mobile_number , type: String , default: ''
field :email , type: String , default: ''
- field :enrollment , type: String , default: 0
+ field :enrollment , type: Fixnum , default: 0
field :approved , type: Boolean , default: true
field :sign_up_setting_id , type: String , default: SignUpSetting.last.id.to_s
after_initialize do
if !self.new_record?
if self.approved.nil?
self.approved = true
- self.save
+ self.save!
end
- if self.enrollment.nil?
+ if self.enrollment.nil? || self.enrollment.class != Fixnum
self.enrollment = 0
- self.save
+ self.save!
+ end
+ if self.enrollment_limited.nil?
+ self.enrollment_limited = 0
+ self.save!
end
if self.sign_up_setting_id.nil?
self.sign_up_setting_id = SignUpSetting.last.id.to_s
- self.save
+ self.save!
end
sign_up_setting = SignUpSetting.find(self.sign_up_setting_id) rescue nil
if sign_up_setting.nil?
diff --git a/app/views/admin/olympiamanagements/add_school_data.html.erb b/app/views/admin/olympiamanagements/add_school_data.html.erb
index 8c9ff98..41168aa 100644
--- a/app/views/admin/olympiamanagements/add_school_data.html.erb
+++ b/app/views/admin/olympiamanagements/add_school_data.html.erb
@@ -10,7 +10,7 @@
<% @extra_text = ((field.values[0]["required"] == "true")? "*" : "")%>
<% if field.values[0][:type] != 'select' %>
- " value="<%= (field.keys[0]=="enrollment_limited"&&@olympia_school_data_field[field.keys[0]]== 0 ) ? "" : @olympia_school_data_field[field.keys[0]] %>" size="<%=field.values[0][:size]%>" type="text" id="<%= field.keys[0] %>" class="col_input<%= @extra_class%>"/>
+ " value="<%= (field.keys[0]=="enrollment_limited"&&(@olympia_school_data_field[field.keys[0]].nil? || @olympia_school_data_field[field.keys[0]] == 0) ) ? "" : @olympia_school_data_field[field.keys[0]] %>" size="<%=field.values[0][:size]%>" type="text" id="<%= field.keys[0] %>" class="col_input<%= @extra_class%>"/>
<% else%>
<% @please_choice = (I18n.locale.to_s == "zh_tw") ? "請選擇" : "Please select." %>