From ca31360f6513b226dfd21189c37aa69677512874 Mon Sep 17 00:00:00 2001 From: BOHUNG Date: Wed, 5 Feb 2020 21:44:49 +0800 Subject: [PATCH] fix --- .../stylesheets/admin/olympiamanagement.scss | 3 + .../admin/olympiamanagements_controller.rb | 145 ++++++++++++------ .../olympiamanagements_controller.rb | 27 ++-- app/models/olympia_school_data_fields.rb | 14 +- app/models/olympia_student_data_field.rb | 6 +- app/models/sign_up_setting.rb | 43 ++++-- .../olympiamanagements/_checkbox.html.erb | 6 +- .../olympiamanagements/error_message.html.erb | 13 ++ .../admin/olympiamanagements/index.html.erb | 42 +++++ .../school_data_list.html.erb | 4 +- .../sign_up_setting.html.erb | 6 +- config/locales/en.yml | 7 + config/locales/zh_tw.yml | 8 + lib/olympiamanagement/engine.rb | 6 +- 14 files changed, 239 insertions(+), 91 deletions(-) create mode 100644 app/views/admin/olympiamanagements/error_message.html.erb diff --git a/app/assets/stylesheets/admin/olympiamanagement.scss b/app/assets/stylesheets/admin/olympiamanagement.scss index 8242242..79cdc7d 100644 --- a/app/assets/stylesheets/admin/olympiamanagement.scss +++ b/app/assets/stylesheets/admin/olympiamanagement.scss @@ -123,6 +123,9 @@ ol { .lleft{ float: left; } +.red_text{ + color: red; +} li{ display: block; } \ No newline at end of file diff --git a/app/controllers/admin/olympiamanagements_controller.rb b/app/controllers/admin/olympiamanagements_controller.rb index 13ca7ba..6784ad5 100644 --- a/app/controllers/admin/olympiamanagements_controller.rb +++ b/app/controllers/admin/olympiamanagements_controller.rb @@ -7,6 +7,9 @@ class Admin::OlympiamanagementsController < OrbitAdminController helper Admin::OlympiamanagementsHelper load File.expand_path(__dir__)+'/zipgenerator.rb' def index + page_num = params[:page] || 1 + @sign_up_settings = SignUpSetting.all.desc(:id) + @sign_up_settings = @sign_up_settings.page(page_num).per(10) end def add_school_data SchoolDataFields.create if SchoolDataFields.all.count == 0 @@ -15,9 +18,34 @@ class Admin::OlympiamanagementsController < OrbitAdminController end def update_sign_up_data if params[:type] == "delete_old_data" - + @students = OlympiaStudentDataField.where(:sign_up_setting_id=>@sign_up_setting.id) + @error_msg = [] + if @students.length !=0 + @students.destroy_all + @error_msg << ((I18n.locale.to_s == "zh_tw") ? "已刪除#{@students.length}筆學生資料" : "Already delete #{@students.length} student data.") + else + @error_msg << ((I18n.locale.to_s == "zh_tw") ? "尚無學生資料" : "There is no student data yet.") + end + render 'error_message' + elsif params[:type] == "active" + @sign_up_setting = SignUpSetting.find(params[:id]) rescue nil + if !@sign_up_setting.nil? + @sign_up_setting.active = true + @sign_up_setting.save + end + redirect_to :back + elsif params[:type] == "view" + @sign_up_setting = SignUpSetting.find(params[:id]) rescue nil + if !@sign_up_setting.nil? + session[:sign_up_setting_id] = params[:id] + redirect_to admin_olympiamanagements_school_data_list_path + else + @error_msg = [] + @error_msg << ((I18n.locale.to_s == "zh_tw") ? "查無資料" : "Not found.") + render 'error_message' + end else - render :html => params and return + render :html => '404' and return end end def update_school_data @@ -77,15 +105,19 @@ class Admin::OlympiamanagementsController < OrbitAdminController redirect_to :back end elsif params[:type] == 'sign_up_setting' - @sign_up_setting = SignUpSetting.find(params[:id]) rescue SignUpSetting.where(:active=>true).last - if @sign_up_setting.nil? - render_404_html - else - params["sign_up_setting"].each do |key,value| - @sign_up_setting[key] = value - end - @sign_up_setting.save + @sign_up_params = params.require(:sign_up_setting).permit! + if params[:new_sign_up] == "true" + #render :html => @sign_up_params and return + SignUpSetting.create(@sign_up_params) redirect_to :back + else + @sign_up_setting = SignUpSetting.find(params[:id]) rescue SignUpSetting.where(:active=>true).last + if @sign_up_setting.nil? + render_404_html + else + @sign_up_setting.update_attributes(@sign_up_params) + redirect_to :back + end end else render :html => params and return @@ -98,7 +130,7 @@ class Admin::OlympiamanagementsController < OrbitAdminController @SchoolDataField = SchoolDataFields.first @SchoolDataname = @SchoolDataField.school_data_fields.map{|field| field.keys[0]} page_num = params[:page] || 1 - @OlympiaSchoolDataFields = OlympiaSchoolDataFields.all.asc(:id) + @OlympiaSchoolDataFields = OlympiaSchoolDataFields.where(:sign_up_setting_id=>@sign_up_setting.id).asc(:id) @OlympiaSchoolDataFields = @OlympiaSchoolDataFields.where("school_name" => /#{params[:school_name]}/) if !params[:school_name].to_s.blank? @OlympiaSchoolDataFields = @OlympiaSchoolDataFields.where("school_code" => /#{params[:school_code]}/) if !params[:school_code].to_s.blank? @OlympiaSchoolDataFields = @OlympiaSchoolDataFields.page(page_num).per(10) @@ -127,17 +159,14 @@ class Admin::OlympiamanagementsController < OrbitAdminController @filename = filename.nil? ? tempfile.path : filename workbook = RubyXL::Parser.parse(tempfile) sheet = workbook[0].sheet_data.rows - first_index = 0 + flag = 1 sheet.each_with_index do |raw_row,index| - row = raw_row.cells.map{ |cell| cell.value rescue nil} - if row.nil? && first_index != -1 - first_index += 1 - next - elsif row.nil? + row = raw_row.cells.map{ |cell| (cell.nil?) ? '' : cell.value } rescue nil + if row.nil? next end - if index == first_index || first_index != -1 - first_index = -1 + if flag == 1 + flag = 0 else #@error_msg << @row_index_hash and return false @olympia_school_data_field = OlympiaSchoolDataFields.where(:school_code=> row[@row_index_hash["school_code"]]).first @@ -163,20 +192,18 @@ class Admin::OlympiamanagementsController < OrbitAdminController return @error_msg end sheet = workbook[0].sheet_data.rows - first_index = 0 + flag = 1 sheet.each_with_index do |raw_row,index| begin - row = raw_row.cells.map{ |cell| cell.value rescue nil} + row = raw_row.cells.map{ |cell| (cell.nil?) ? '' : cell.value } rescue nil rescue @error_msg << filename+'格式錯誤' return @error_msg end - if row.nil? && first_index != -1 - next - elsif row.nil? + if row.nil? next end - if index == first_index || first_index != -1 + if flag == 1 @field_data = row delete_array = [] @profile_data_row.each do |row_key| @@ -187,11 +214,16 @@ class Admin::OlympiamanagementsController < OrbitAdminController end end delete_array.each{|element| @profile_data_row.delete(element)} - first_index = -1 + flag = 0 else #@error_msg << @row_index_hash and return - if row[@row_index_hash["school_code"]] == "" - @error_msg << @filename+"中#{make_alpha_from_numbers(@row_index_hash['school_code'])}#{index+1}欄位學校代碼不符(該欄位值不可為空)。" + if(row[@row_index_hash["school_code"]] == "" rescue true) + begin + @error_msg << @filename+"中#{make_alpha_from_numbers(@row_index_hash['school_code'])}#{index+1}欄位學校代碼不符(該欄位值不可為空)。" + rescue + @error_msg << "#{@filename}檔案格式錯誤" + return + end end end end @@ -227,7 +259,7 @@ class Admin::OlympiamanagementsController < OrbitAdminController def sign_up_student_data_list page_num = params[:page] || 1 @field_infos = StudentDataField.first.student_data_fields - @sign_up_setting_id = SignUpSetting.id + @sign_up_setting_id = @sign_up_setting.id @student_fields = OlympiaStudentDataField.where(:olympia_school_data_fields_id=>params[:olympia_school_id],:sign_up_setting_id=>@sign_up_setting_id).asc(:id).page(page_num).per(10) end def export_sign_up_student_data @@ -262,14 +294,20 @@ class Admin::OlympiamanagementsController < OrbitAdminController @student_data_list << @tmp_student_data end #render :html => @student_data_list and return - @filename = 'student_export.xlsx' - Dir.chdir(dir_path) do - File.open(@filename, 'w') do |f| - f.write render_to_string( :handlers=> [:axlsx], :formats=> [:xlsx] ,:partial=> 'student_export.xlsx',:locals=> {:@student_data_list=>@student_data_list,:@fields=>@fields} ) + if @student_data_list.empty? + @error_msg = [] + @error_msg << ((I18n.locale.to_s == "zh_tw") ? "尚無學生資料" : "There is no student data yet.") + render 'error_message' + else + @filename = 'student_export.xlsx' + Dir.chdir(dir_path) do + File.open(@filename, 'w') do |f| + f.write render_to_string( :handlers=> [:axlsx], :formats=> [:xlsx] ,:partial=> 'student_export.xlsx',:locals=> {:@student_data_list=>@student_data_list,:@fields=>@fields} ) + end end + tmp_filename_data = File.read(dir_path +@filename) + send_data(tmp_filename_data, type: 'application/xlsx', disposition: 'attachment', filename: @filename) end - tmp_filename_data = File.read(dir_path +@filename) - send_data(tmp_filename_data, type: 'application/xlsx', disposition: 'attachment', filename: @filename) end def download_scan_file_of_certificate @sign_up_setting_id = @sign_up_setting.id @@ -299,20 +337,25 @@ class Admin::OlympiamanagementsController < OrbitAdminController @new_pathname = Pathname.new(@new_pathname.to_s.insert(@new_pathname.to_s.rindex('.'),"-#{@index}")) @index += 1 end - #a[0...b].concat('-1').concat(a[b..-1]) FileUtils.cp(@original_filename,@new_pathname) end end - @filename = Pathname.new(zip_path).parent.to_s+"/#{Time.now.strftime('%Y_%m_%d')}_student_images.zip" - zip_file= ZipFileGenerator.new(zip_path,@filename) - begin - zip_file.write - rescue - File.delete(@filename) - zip_file.write + if !@student_data_image_path_arr.empty? + @filename = Pathname.new(zip_path).parent.to_s+"/#{Time.now.strftime('%Y_%m_%d')}_student_images.zip" + zip_file= ZipFileGenerator.new(zip_path,@filename) + begin + zip_file.write + rescue + File.delete(@filename) + zip_file.write + end + tmp_filename_data = File.read(@filename) + send_data(tmp_filename_data, type: 'application/zip', disposition: 'attachment', filename: Pathname.new(@filename).basename.to_s) + else + @error_msg = [] + @error_msg << ((I18n.locale.to_s == "zh_tw") ? "尚無學生獎狀掃描檔案。" : 'There is no scan file of certificate yet.' ) + render 'error_message' end - tmp_filename_data = File.read(@filename) - send_data(tmp_filename_data, type: 'application/zip', disposition: 'attachment', filename: Pathname.new(@filename).basename.to_s) end end def add_sign_up_student_data @@ -329,7 +372,7 @@ class Admin::OlympiamanagementsController < OrbitAdminController if !@flag I18n.t('olympiamanagement.please_set_school_connect_data') @error_msg << "

#{I18n.t('olympiamanagement.please_set_school_connect_data')}

" - render 'import_error_msg' + render 'error_message' else @student_data_field = StudentDataField.first @olympia_student_data = (OlympiaStudentDataField.find(params[:id]) rescue OlympiaStudentDataField.new) @@ -372,7 +415,7 @@ class Admin::OlympiamanagementsController < OrbitAdminController end redirect_to admin_olympiamanagements_sign_up_student_data_list_path+"?olympia_school_id=#{params[:school_id]}" else - render 'import_error_msg' + render 'error_message' end elsif params[:type] == 'delete_student_data' @olympia_student_data = OlympiaStudentDataField.find(params[:id]) rescue nil @@ -389,7 +432,13 @@ class Admin::OlympiamanagementsController < OrbitAdminController StudentDataField.create if StudentDataField.all.length == 0 SchoolDataFields.create if SchoolDataFields.all.length == 0 SignUpSetting.create if SignUpSetting.all.length == 0 - @sign_up_setting = SignUpSetting.where(:active=>true).last + @sign_up_setting + if session[:sign_up_setting_id].blank? + @sign_up_setting = SignUpSetting.where(:active=>true).last + else + @sign_up_setting = SignUpSetting.find(session[:sign_up_setting_id]) rescue nil + @sign_up_setting = SignUpSetting.where(:active=>true).last if @sign_up_setting.nil? + end end def download_import_file @OlympiaSchoolDataFields = OlympiaSchoolDataFields.all.asc(:id) diff --git a/app/controllers/olympiamanagements_controller.rb b/app/controllers/olympiamanagements_controller.rb index 871856c..db83f44 100644 --- a/app/controllers/olympiamanagements_controller.rb +++ b/app/controllers/olympiamanagements_controller.rb @@ -11,6 +11,9 @@ class OlympiamanagementsController < ApplicationController end def create_first_fields StudentDataField.create if StudentDataField.all.length == 0 + SchoolDataFields.create if SchoolDataFields.all.length == 0 + SignUpSetting.create if SignUpSetting.all.length == 0 + @sign_up_setting = SignUpSetting.where(:active=>true).last end def check_login begin @@ -72,7 +75,7 @@ class OlympiamanagementsController < ApplicationController @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" - if !(time_now_str <= end_time_str && time_now_str >= start_time_str) + 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) @@ -110,7 +113,7 @@ class OlympiamanagementsController < ApplicationController end @error = @@error rescue nil @page_content - if !(time_now_str <= end_time_str && time_now_str >= start_time_str) + 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') @@ -119,18 +122,8 @@ class OlympiamanagementsController < ApplicationController elsif @instructions_pages.length != 1 @instructions_pages.slice(1,@instructions_pages.length).each{|page| page.destroy} end - if !(OrbitHelper.params || params)[:login_id].to_s.blank? && @@session[:olympia_login_id].to_s.blank? - if OlympiaSchoolDataFields.where(:account_number=>(OrbitHelper.params || params)[:login_id]).length == 0 - @error = "no_account" - else - if OlympiaSchoolDataFields.where(:account_number=>(OrbitHelper.params || params)[:login_id]).first.password != (OrbitHelper.params || params)[:login_pw] - @error = "password_error" - else - @@session[:olympia_login_id] = (OrbitHelper.params || params)[:login_id] - end - end - end - if @@session[:olympia_login_id].to_s.blank? + @school = OlympiaSchoolDataFields.where(:account_number=>@@session[:olympia_login_id],:approved=>true).first rescue nil + if @school.nil? @page_content = render_to_string(:formats=> [:html] ,:partial=>'login',:locals=>{:@error=>@error}) else @@error = nil @@ -156,7 +149,7 @@ class OlympiamanagementsController < ApplicationController 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,:@title=>I18n.t('olympiamanagement.sign_up_title')}) - @page_content = @breadcumb+'

'+t('olympiamanagement.sign_up_hint')+'

' + @page_content = '

'+t('olympiamanagement.sign_up_hint')+'

' end { "olympiamanagement" => [], @@ -169,7 +162,7 @@ class OlympiamanagementsController < ApplicationController 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) @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"}}, @@ -194,7 +187,7 @@ class OlympiamanagementsController < ApplicationController 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) redirect_to :back else @olympia_school_data_field = OlympiaSchoolDataFields.where(:account_number=>session[:olympia_login_id]).first diff --git a/app/models/olympia_school_data_fields.rb b/app/models/olympia_school_data_fields.rb index 7933924..5939696 100644 --- a/app/models/olympia_school_data_fields.rb +++ b/app/models/olympia_school_data_fields.rb @@ -19,11 +19,17 @@ class OlympiaSchoolDataFields field :fax , type: String , default: '' field :mobile_number , type: String , default: '' field :email , type: String , default: '' - field :enrollment , type: Fixnum , default: 0 + field :enrollment , type: Hash , default: 0 field :approved , type: Boolean , default: true field :sign_up_setting_id , type: String , default: SignUpSetting.where(:active=>true).last.id.to_s after_destroy do |record| - OlympiaStudentDataField.where(:olympia_school_data_fields_id => record.id,:sign_up_setting_id=>SignUpSetting.where(:active=>true).last.id).destroy_all + OlympiaStudentDataField.where(:olympia_school_data_fields_id => record.id).destroy_all + end + after_save do |record| + if record.account_number.blank? && !record.school_code.blank? + record.account_number = record.school_code + record.save + end end after_initialize do if !self.new_record? @@ -35,10 +41,6 @@ class OlympiaSchoolDataFields self.enrollment = 0 self.save! end - if self.enrollment == 0 #check enrollment student number - self.enrollment = OlympiaStudentDataField.where(:olympia_school_data_fields_id=>self.id,:sign_up_setting_id=>SignUpSetting.where(:active=>true).last.id).length - self.save! - end if self.enrollment_limited.nil? self.enrollment_limited = 0 self.save! diff --git a/app/models/olympia_student_data_field.rb b/app/models/olympia_student_data_field.rb index d11ce38..f8e9830 100644 --- a/app/models/olympia_student_data_field.rb +++ b/app/models/olympia_student_data_field.rb @@ -21,14 +21,14 @@ class OlympiaStudentDataField field :remove_image , type: Boolean , default: false field :approved , type: Boolean , default: true field :olympia_school_data_fields_id , type: String , default: '' - field :sign_up_setting_id , type: String , default: '' + field :sign_up_setting_id , type: String , default: SignUpSetting.where(:active=>true).last.id.to_s has_many :olympia_student_images , :dependent => :destroy , autosave: true after_save :check_file after_create do |record| if !record.olympia_school_data_fields_id.blank? @school = OlympiaSchoolDataFields.find(record.olympia_school_data_fields_id) rescue nil if !@school.nil? - @school.enrollment = @school.enrollment + 1 + @school.enrollment += 1 @school.save end end @@ -37,7 +37,7 @@ class OlympiaStudentDataField if !record.olympia_school_data_fields_id.blank? @school = OlympiaSchoolDataFields.find(record.olympia_school_data_fields_id) rescue nil if !@school.nil? - @school.enrollment = @school.enrollment - 1 + @school.enrollment -= 1 @school.save end end diff --git a/app/models/sign_up_setting.rb b/app/models/sign_up_setting.rb index 1f39744..2dc6c90 100644 --- a/app/models/sign_up_setting.rb +++ b/app/models/sign_up_setting.rb @@ -18,16 +18,31 @@ class SignUpSetting field :end_minute , type: String , default: Time.now.strftime("%M") field :default_password , type: String , default: "" field :set_default_password , type: Boolean , default: false - field :remark_field , type: Hash , default: {:zh_tw=>"注意事項:
-請於2019年5月3日前(以郵戳為憑),將本報名表正本(需核章)以掛號方式郵寄至【11677台北市文山區汀州路4段88號科教中心,收件人: IJSO選訓委員會】,逾期概不受理報名。
-
-

",:en=>""} - field :registration_instructions , type: Hash , default: {:zh_tw=>"",:en=>""} + field :remark_field , type: Hash , default: {:zh_tw=>'注意事項:
+ 請於{{end_year}}年{{end_month}}月{{end_day}}日前(以郵戳為憑),將本報名表正本(需核章)以掛號方式郵寄至【11677台北市文山區汀州路4段88號科教中心,收件人: IJSO選訓委員會】,逾期概不受理報名。
+

',:en=>""} + field :registration_instructions , type: Hash , default: {:zh_tw=>'

報名日期:{{start_year}}/{{start_month}}/{{start_day}}~{{end_year}}/{{end_month}}/{{end_day}}
+
1. 線上報名系統之各校登入帳號為學校代碼,密碼隨公文發至各校。(學校代碼查詢)
+
2. 登入系統後,請先填學校聯絡資料
+
3. 新增報名學生資料:
+ (1)學生姓名
+ (2)性別
+ (3) 身份證字號
+ (4) 出生年月日
+ (5) 班級
+ (6) 聯絡電話
+ (7) 郵遞區號
+ (8) 地址
+ (9) 身份(一般身份、科展得獎者) : 科展得獎者需要上傳獎狀掃描檔
+ (10) 考區
+
4. 列印報名表,由校長及教務主任核章後,以掛號郵寄至【11677台北市文山區汀州路488號科教中心,收件人:IJSO選訓委員會】。

', + :en=>""} field :active , type: Boolean , default: true after_save :change_all_password , :check_active + after_create :auto_create_schools def change_all_password - if self.set_default_password - OlympiaSchoolDataFields.all.each do |school_field| + if self.set_default_password && !self.default_password.blank? + OlympiaSchoolDataFields.where(:sign_up_setting_id=>self.id).each do |school_field| school_field.password = self.default_password school_field.save end @@ -35,11 +50,19 @@ class SignUpSetting self.save end end + def auto_create_schools + @sign_up_setting = SignUpSetting.where(:id.ne=>self.id).last + @schools = OlympiaSchoolDataFields.where(:sign_up_setting_id=>@sign_up_setting.id) + @schools.each do |school| + OlympiaSchoolDataFields.create(school.attributes.except(*['_id','enrollment'])) + end + end def check_active if self.active - SignUpSetting.where.not(:id=>self.id).each do |setting| - setting.active = false - setting.save! + SignUpSetting.where(:id.ne=>self.id).each do |setting| + setting_copy = setting + setting_copy.active = false + setting_copy.save! end end end diff --git a/app/views/admin/olympiamanagements/_checkbox.html.erb b/app/views/admin/olympiamanagements/_checkbox.html.erb index 1eb9600..28ead8f 100644 --- a/app/views/admin/olympiamanagements/_checkbox.html.erb +++ b/app/views/admin/olympiamanagements/_checkbox.html.erb @@ -1,5 +1,5 @@
- - class="checkbox" id="<%=id%>" name="<%=params_name%>" style="float:left;" type="checkbox" value="1"> - + + class="checkbox" id="<%=id%>" name="<%=params_name%>" style="float:left;" type="checkbox" value="true"> +
\ No newline at end of file diff --git a/app/views/admin/olympiamanagements/error_message.html.erb b/app/views/admin/olympiamanagements/error_message.html.erb new file mode 100644 index 0000000..78ee3e3 --- /dev/null +++ b/app/views/admin/olympiamanagements/error_message.html.erb @@ -0,0 +1,13 @@ +

<%= (I18n.locale.to_s == "zh_tw") ? '錯誤提示' : 'Error message' %>

+ + + + + \ No newline at end of file diff --git a/app/views/admin/olympiamanagements/index.html.erb b/app/views/admin/olympiamanagements/index.html.erb index e69de29..d893fbb 100644 --- a/app/views/admin/olympiamanagements/index.html.erb +++ b/app/views/admin/olympiamanagements/index.html.erb @@ -0,0 +1,42 @@ + + + +<% th_name_list = ['sign_up_start_time','sign_up_end_time','enrollment','status','action']%> +<% time = ['year','month','day'] %> +

<%=t('olympiamanagement.history_contest')%>

+ + + <% th_name_list.each do |th_name| %> + + <% end %> + + +<% @sign_up_settings.each do |sign_up_setting| %> + + + + + + + +<% end %> + +
<%=t('olympiamanagement.'+th_name) %>
<%= time.map{|td| sign_up_setting["start_#{td}"]}.join('-') %><%= time.map{|td| sign_up_setting["end_#{td}"]}.join('-') %><%= @student_number = OlympiaStudentDataField.where(:sign_up_setting_id=>sign_up_setting.id).length %> + <% if sign_up_setting.active%> + + <%=t('olympiamanagement.active')%> + <%=t('olympiamanagement.active')%> + + <% else %> + + <%=t('olympiamanagement.inactive')%> + <%=t('olympiamanagement.inactive')%> + + <% end %> + + <% if !sign_up_setting.active%> + <%=t('olympiamanagement.active')%> + <% end %> + <%=t('olympiamanagement.view')%> +
+<%=create_pagination(params[:page].to_i,SignUpSetting.all).html_safe%> \ No newline at end of file diff --git a/app/views/admin/olympiamanagements/school_data_list.html.erb b/app/views/admin/olympiamanagements/school_data_list.html.erb index a5f8058..202c12b 100644 --- a/app/views/admin/olympiamanagements/school_data_list.html.erb +++ b/app/views/admin/olympiamanagements/school_data_list.html.erb @@ -28,13 +28,13 @@ <% @OlympiaSchoolDataFields.each do |field| %> <% th_name_list.each do |th_name|%> - <%if th_name != 'action'%> + <% if th_name != 'action'%> <%= field[th_name]%> <% else %> "><%= t('olympiamanagement.edit') %><%= t('olympiamanagement.edit') %> "><%= t('olympiamanagement.sign_up_student_data') %><%= t('olympiamanagement.sign_up_student_data') %> - "><%= t('olympiamanagement.delete') %><%= t('olympiamanagement.delete') %> + '; }" onkeypress="if( window.confirm('<%=t('olympiamanagement.please_confirm_delete')%>') ) { window.location='<%=admin_olympiamanagements_update_school_data_path+"?id=#{field.id}&type=delete_school_data"%>'; }"><%= t('olympiamanagement.delete') %><%= t('olympiamanagement.delete') %> <%if field.approved%> "><%= t('olympiamanagement.unapproved') %><%= t('olympiamanagement.unapproved') %> <% else %> diff --git a/app/views/admin/olympiamanagements/sign_up_setting.html.erb b/app/views/admin/olympiamanagements/sign_up_setting.html.erb index 6725ae8..e1615a3 100644 --- a/app/views/admin/olympiamanagements/sign_up_setting.html.erb +++ b/app/views/admin/olympiamanagements/sign_up_setting.html.erb @@ -4,9 +4,13 @@
<%=t('olympiamanagement.sign_up_setting')%> <%=form_for @sign_up_setting ,:url=>{:controller=>"olympiamanagements" ,:action=>"update_school_data",:type=>"sign_up_setting",:id=>@sign_up_setting.id} do |form|%> - + <%=t('olympiamanagement.delete_all_sign_up_data')%><%=t('olympiamanagement.delete_all_sign_up_data')%>
+
+ <%=render :partial=>'checkbox',:locals=>{:name=>t('olympiamanagement.new_sign_up'),:params_name=>'new_sign_up',:id=>'new_sign_up',:extra_class=>'lleft red_text',:is_checked=>nil}%> +
+
  • <%= t('olympiamanagement.sign_up_start_time')%>
  • diff --git a/config/locales/en.yml b/config/locales/en.yml index 36330cf..559fba9 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1,5 +1,12 @@ en: olympiamanagement: + new_sign_up: Create new Sign up + view: View + history_contest: History Contest + active: Active + inactive: Inactive + status: Status + please_confirm_delete: Please confirm deletion.? scan_file_of_certificate: Scan file of certificate sign_up_title: International Junior Science Olympiad First Stage Online Sign UP error_msg: Error message diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index a960538..cf15c70 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -1,5 +1,13 @@ zh_tw: olympiamanagement: + new_sign_up: 建立新的報名 + view: 查看 + add_sign_up_setting: 增加報名設定 + history_contest: 歷屆比賽 + active: 啟用 + inactive: 停用 + status: 狀態 + please_confirm_delete: 請確認是否刪除? scan_file_of_certificate: 獎狀掃描 sign_up_title: 國中科學奧林匹亞競賽初選線上報名 error_msg: 錯誤訊息 diff --git a/lib/olympiamanagement/engine.rb b/lib/olympiamanagement/engine.rb index f371b60..e690c04 100644 --- a/lib/olympiamanagement/engine.rb +++ b/lib/olympiamanagement/engine.rb @@ -15,7 +15,11 @@ module Olympiamanagement available_for "users" active_for_controllers (['admin/olympiamanagement']) head_link_path "admin_olympiamanagements_school_data_list_path" - + context_link 'olympiamanagement.history_contest', + :link_path=>"admin_olympiamanagements_path" , + :priority=>1, + :active_for_action=>{'admin/olympiamanagements'=>'index'}, + :available_for => 'users' context_link 'olympiamanagement.add_school_data', :link_path=>"admin_olympiamanagements_add_school_data_path" , :priority=>1,