From e4139e72adc297a5bed5ef879470d75e7d71e1df Mon Sep 17 00:00:00 2001 From: BOHUNG Date: Fri, 31 Jan 2020 18:52:53 +0800 Subject: [PATCH] finish admin pages except student --- app/assets/images/ok.gif | Bin 0 -> 2108 bytes app/assets/images/warning.gif | Bin 0 -> 576 bytes .../javascripts/admin/olympiamanagement.js | 21 +- app/assets/javascripts/checkid.js | 96 +++++++++ .../stylesheets/admin/olympiamanagement.scss | 13 +- .../admin/olympiamanagements_controller.rb | 194 ++++++++++++++++++ .../admin/olympiamanagements_helper.rb | 38 +++- app/models/olympia_school_data_fields.rb | 23 +++ app/models/school_data_fields.rb | 14 +- app/models/sign_up_setting.rb | 34 +++ .../olympiamanagements/_checkbox.html.erb | 5 + .../_import_schoo_class_setting.xlsx.axlsx | 27 +++ .../_school_export.xlsx.axlsx | 27 +++ .../admin/olympiamanagements/_select.html.erb | 7 + .../add_school_data.html.erb | 17 +- ...rt_editing_number_of_school_class.html.erb | 16 ++ .../import_error_msg.html.erb | 14 ++ .../school_data_list.html.erb | 9 +- .../sign_up_setting.html.erb | 92 +++++++++ config/locales/en.yml | 23 ++- config/locales/zh_tw.yml | 24 ++- config/routes.rb | 4 + 22 files changed, 673 insertions(+), 25 deletions(-) create mode 100644 app/assets/images/ok.gif create mode 100644 app/assets/images/warning.gif create mode 100644 app/assets/javascripts/checkid.js create mode 100644 app/models/sign_up_setting.rb create mode 100644 app/views/admin/olympiamanagements/_checkbox.html.erb create mode 100644 app/views/admin/olympiamanagements/_import_schoo_class_setting.xlsx.axlsx create mode 100644 app/views/admin/olympiamanagements/_school_export.xlsx.axlsx create mode 100644 app/views/admin/olympiamanagements/_select.html.erb create mode 100644 app/views/admin/olympiamanagements/import_error_msg.html.erb diff --git a/app/assets/images/ok.gif b/app/assets/images/ok.gif new file mode 100644 index 0000000000000000000000000000000000000000..4154ffb45b306c443c677ad8f143c154cbeef7b2 GIT binary patch literal 2108 zcmV-C2*dYBNk%w1VK4wN0Qdg@WwP!{P)YB zE0vX%ip6vok~9;6FPWRV{_CRY>FIc>gWB5K&d=WZ{rO&Bc%`Soc)?AB##^1ygrA?E zqtt~HZYbLB&StqaXlQ6@x;S*Fdgb%ozTv3x@$t)@Bdn~f;^OVn;??{6`{?QMZ@fZ? zvyx(BV)^;`K3PN)gD@R%EGBC;6M8KC{QUg=`t|korPhe|`}FPi>d@)I-S6CaiG2R( zlx(~`@b>X>zC@vWFNDRD|N7?t_}VlNuE&gl zj6!`+O?OsNYDZRJSSENcuD-E0Y(Xx4IHq$Go6mvo_3$KJFfyJrkIQNvlsluOy}!S| zZn}YCgh_Y5fj)FfIe$o7vQ|N+GeD*}M5sUL^x!pZCpv{eLxWOEjaS*mrc_pMtkj)| ziM67lqW}N@A^8LW00930EC2ui05AYB000R80RIUbNU)&5QdZy%SjZ6Giw{}67@SD4 z;=fZ?PAs&5CWR0oDbQG0XvW!wH5OA&45QIP838b3$}BT7!HW=MRI2P!VSoi4F;}p= zbH|-KU4mlj7-k%A{0(GwcE8hj0#6 zYS~7u09SzH9!VgpncP)Ejms*aXtu$mmgh6;va}5|K!^ZAdg}E+ouqhP2@U$N+8ya;iM#Q$V_3Qew6L=`(zIpEk&)6k^oM2?}7wzL_BqM8HU9A#}bN z08{~%NmA6%#&`pwCqX@Lu#y=qX7FG{1-mRj*Z|?IgOWw%oFIw-fk42>A9@6c+=vHG zQV0aC0Fem~8<-LR6aWA)m?)|Y5=ly>4Db>xDtO3BGS}oIO${~F0~R2RYyyKBVFchL z8@t3Pj{s#1(8~c5RkR;WK(w+61PYi@fg}T1@x~j4`~krxnDEerlK}uS#}qLV0Mh`u zFrZsS@K_*#A1Gu1MVlKq8N&elU;%*&P7osr9dH6tN0c!FK%FR~{BUDM16b7pIw(L> z0i;n&Zw;h(8T~appZ$Ea9(l4 zoU#HSp{dJn*a;Q`bWDGfMIi` z5?V*bAo*34#W8*c@rcar+HiD?kJJ}M2~_B5kr%@72ei<^LU47A66!Dj4IC7ZWku8^ z5Cu%KPz`4dX9FM$Oi`%+f`C6os5C}2y9N<+j99oRfz?;jhc6@?RH9u)&ZGIg_$EaH128kYb92P5pMSQ;8w^UeS{_!iS42GmkMbukH%!vN+W zAj1e6C{|Dw2gGrE4rl-+lTv7`Uji9a_`w0RC%=KL;S&s4M)EddffS^`0wY<-C?Fw* z3ozgl#Va5|xL1HJ#GxDQkVH=g;0t@ufDGO+fef}#fVF6_B3{tI5vJh?KIB0JJ79qw z#IV8<964{6Y@)i^z0ugqw13B0d1GvP13lPCeM08-4FGNBIJmHCcXoCVQNG1uE`G96N(*=!) zW+Q&7uNQJ*7`RY^5^UiDA9&N7S_r2r#yO6CXj7Y(Wa1c(zZh002831Kqd) literal 0 HcmV?d00001 diff --git a/app/assets/images/warning.gif b/app/assets/images/warning.gif new file mode 100644 index 0000000000000000000000000000000000000000..873bbb52cb9768103c27fbb9a9bac16ac615fce5 GIT binary patch literal 576 zcmZ?wbhEHbB!Sy%bj7w z8LP{2I!WYbmF&-Ixi?j6tD|K1XR2M#l>Aw*aXL%wXS3nYW}{zi=4WzsU5r%E6qx+# za{AThd85YVOsT`KDUrWsBtGknIa3>Sy(4;AS@f^Dxt>-=XPXm#FD(1Lr2hBv=9?3X zZS^!XrNw@)>eiN((2|w-y>{aB1+99DGMA?}+UTggT+(Z*rf8+5x~aWVOGcurtl;&U zIa)H3I&#vwvQjJBn`YHj9iKlB7`)(M#!e{yWMO1rC}Yq8NrU2qfqia6SyOXMYa1sM zM_a34eqyRfcQbQJY;^IYGTuzaxglKLqNQEA}OiQec+sQ#rUUjLqg_MpsPmY43 zsgmVV8EHK$eV-B~6*UcAW2+w%1e4o&9#aAczLGF}PmMg|6J0Ey4q A)Bpeg literal 0 HcmV?d00001 diff --git a/app/assets/javascripts/admin/olympiamanagement.js b/app/assets/javascripts/admin/olympiamanagement.js index 000f6ac..cf2cbbb 100644 --- a/app/assets/javascripts/admin/olympiamanagement.js +++ b/app/assets/javascripts/admin/olympiamanagement.js @@ -18,7 +18,26 @@ $(document).ready(function(){ window.location.search=""; }); }); + $('.fieldset_block input[type="submit"]').click(function(){ + $el = $('.fieldset_block li.required'); + for(var i = 0; i< $el.length ; i++){ + if($el.eq(i).siblings('.col_r').find('.required').val() == ""){ + $el.eq(i).addClass('errFld'); + if($el.eq(i).siblings('.col_r').find('.errMsg').length == 0) + $el.eq(i).siblings('.col_r').append('
'+((I18n.locale == "en") ? 'Required field': '必填欄位')+'
'); + }else{ + $el.eq(i).removeClass('errFld'); + $el.eq(i).siblings('.col_r').find('.errMsg').remove(); + }; + }; + if($('.fieldset_block .required.errFld').length != 0) + return false; + else + return true; + }) var $el = $('.fieldset_block select'); for(var i = 0 ; i < $el.length ; i++) - $el.eq(i).find('option[value='+$el.eq(i).attr('value')+']').attr('selected','selected'); + 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(); }); \ No newline at end of file diff --git a/app/assets/javascripts/checkid.js b/app/assets/javascripts/checkid.js new file mode 100644 index 0000000..251e034 --- /dev/null +++ b/app/assets/javascripts/checkid.js @@ -0,0 +1,96 @@ +var ALP_STR = "ABCDEFGHJKLMNPQRSTUVXYWZIO"; +var NUM_STR = "0123456789"; +function CheckPID(it) { + var sMsg = ""; + var sPID = it.value; + if (sPID == '') { + sMsg = "請輸入身分證字號"; + } else if (sPID.length != 10) { + sMsg = "身分證字號長度應為 10 !"; + } else { + sPID = trim(sPID.toUpperCase()); + if (!chkPID_CHAR(sPID)) return; + + var iChkNum = getPID_SUM(sPID); + + if (iChkNum % 10 != 0) { + var iLastNum = sPID.substr(9, 1) * 1; + for (i = 0; i < 10; i++) { + var xRightAlpNum = iChkNum - iLastNum + i; + if ((xRightAlpNum % 10) == 0) { + sMsg = "身分證字號最後一個數應為:" + i; + break; + } + } + } + } + if (sMsg.length != 0) { + alert(sMsg); + it.select(); + return false; + } +} +// 去字串前後空白 +function trim(str) { + while (str.indexOf("") == 0) { + str = str.substring(1, str.length); + } + while ((str.length > 0) && (str.indexOf("") == (str.length - 1))) { + str = str.substring(0, str.length - 1); + } + return str; +} +// 身分證字號檢查器 - 檢查合法字元 +function chkPID_CHAR(sPID) { + var sMsg = ""; + //sPID = trim(sPID.toUpperCase()); + var iPIDLen = String(sPID).length; + + var sChk = ALP_STR + NUM_STR; + for (i = 0; i < iPIDLen; i++) { + if (sChk.indexOf(sPID.substr(i, 1)) < 0) { + sMsg = "這個身分證字號含有不正確的字元!"; + break; + } + } + + if (sMsg.length == 0) { + if (ALP_STR.indexOf(sPID.substr(0, 1)) < 0) { + sMsg = "身分證字號第 1 碼應為英文字母(A~Z)。"; + } else if ((sPID.substr(1, 1) != "1") && (sPID.substr(1, 1) != "2")) { + sMsg = "身分證字號第 2 碼應為數字(1~2)。"; + } else { + for (var i = 2; i < iPIDLen; i++) { + if (NUM_STR.indexOf(sPID.substr(i, 1)) < 0) { + sMsg = "第 " + (i + 1) + " 碼應為數字(0~9)。"; + break; + } + } + } + } + + if (sMsg.length != 0) { + alert(sMsg); + return false; + } else { + return true; + } +} +//身份證字號檢查器 - 累加檢查碼 +function getPID_SUM(sPID) { + var iChkNum = 0; + + // 第 1 碼 + iChkNum = ALP_STR.indexOf(sPID.substr(0, 1)) + 10; + iChkNum = Math.floor(iChkNum / 10) + (iChkNum % 10 * 9); + + // 第 2 - 9 碼 + for (var i = 1; i < sPID.length - 1; i++) { + iChkNum += sPID.substr(i, 1) * (9 - i); + } + + // 第 10 碼 + iChkNum += sPID.substr(9, 1) * 1; + + return iChkNum; +} \ No newline at end of file diff --git a/app/assets/stylesheets/admin/olympiamanagement.scss b/app/assets/stylesheets/admin/olympiamanagement.scss index e8a7eab..8242242 100644 --- a/app/assets/stylesheets/admin/olympiamanagement.scss +++ b/app/assets/stylesheets/admin/olympiamanagement.scss @@ -6,6 +6,15 @@ border: 0em; width: auto; } +.errMsg { + color: #CC3333; + display: block; + margin: 10px; + padding-left: 20px; + background-image: url(/assets/warning.gif); + background-repeat: no-repeat; + background-position: left center; +} .fieldset_block{ padding: 1.25em 0.625em 1.25em 3%; border-width: 0.125em; @@ -110,7 +119,9 @@ ol { } .required { font-weight: bold; - width: auto; +} +.lleft{ + float: left; } li{ display: block; diff --git a/app/controllers/admin/olympiamanagements_controller.rb b/app/controllers/admin/olympiamanagements_controller.rb index 94c7667..08be929 100644 --- a/app/controllers/admin/olympiamanagements_controller.rb +++ b/app/controllers/admin/olympiamanagements_controller.rb @@ -1,4 +1,8 @@ class Admin::OlympiamanagementsController < OrbitAdminController + require 'spreadsheet' + require 'rubyXL' + require 'fileutils' + require "axlsx" helper Admin::OlympiamanagementsHelper def index end @@ -7,6 +11,13 @@ class Admin::OlympiamanagementsController < OrbitAdminController @SchoolDataField = SchoolDataFields.first @olympia_school_data_field = (params[:id].nil? ? OlympiaSchoolDataFields.new : ((OlympiaSchoolDataFields.find(params[:id]).nil? rescue true) ? OlympiaSchoolDataFields.new : OlympiaSchoolDataFields.find(params[:id]))) end + def update_sign_up_data + if params[:type] == "delete_old_data" + + else + render :html => params and return + end + end def update_school_data if params[:type] == 'class_setting' @ClassSettingField = (params[:id].nil? ? ClassSettingFields.new : ((ClassSettingFields.find(params[:id]).nil? rescue true) ? ClassSettingFields.new : ClassSettingFields.find(params[:id]))) @@ -35,12 +46,55 @@ 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 + elsif params[:type] == 'import_class_setting' + if params[:upload_file].nil? + redirect_to admin_olympiamanagements_import_editing_number_of_school_class_path+'?error=true' + else + import_class_setting + end + elsif params[:type] == 'approved' + @olympia_school_data_field = OlympiaSchoolDataFields.find(params[:id]) rescue nil + if @olympia_school_data_field.nil? + render_404_html + else + @olympia_school_data_field.approved = true + @olympia_school_data_field.save + redirect_to :back + end + elsif params[:type] == 'unapproved' + @olympia_school_data_field = OlympiaSchoolDataFields.find(params[:id]) rescue nil + if @olympia_school_data_field.nil? + render_404_html + else + @olympia_school_data_field.approved = false + @olympia_school_data_field.save + redirect_to :back + end + elsif params[:type] == 'sign_up_setting' + @sign_up_setting = SignUpSetting.find(params[:id]) rescue SignUpSetting.new + 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 + redirect_to :back + end + else + render :html => params and return end end + def render_404_html + render :html => File.read('app/views/errors/404.html').html_safe + end def school_data_list @SchoolDataField = SchoolDataFields.first @SchoolDataname = @SchoolDataField.school_data_fields.map{|field| field.keys[0]} @@ -55,14 +109,154 @@ class Admin::OlympiamanagementsController < OrbitAdminController @class_setting_list = ClassSettingFields.all.asc(:enrollment_available).page(page_num).per(10) @ClassSettingField = (params[:id].nil? ? nil : ((ClassSettingFields.find(params[:id]).nil? rescue true) ? nil : ClassSettingFields.find(params[:id]))) end + def import_class_setting + if !params[:upload_file].blank? + flag = read_xlsx_temp_file_and_import_class_setting(params[:upload_file].tempfile,params[:upload_file].original_filename) + if flag == true + redirect_to admin_olympiamanagements_school_data_list_path + else + render 'import_error_msg' + end + end + end + def read_xlsx_temp_file_and_import_class_setting(tempfile,filename) + import_class_setting_check(tempfile,filename) + if !@error_msg.empty? + return false + else + @error_msg = Array.new + @filename = filename.nil? ? tempfile.path : filename + workbook = RubyXL::Parser.parse(tempfile) + sheet = workbook[0].sheet_data.rows + first_index = 0 + 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? + next + end + if index == first_index || first_index != -1 + first_index = -1 + else + #@error_msg << @row_index_hash and return false + @olympia_school_data_field = OlympiaSchoolDataFields.where(:school_code=> row[@row_index_hash["school_code"]]).first + @olympia_school_data_field = OlympiaSchoolDataFields.new() if @olympia_school_data_field.nil? + @row_index_hash.each do |key,index| + @olympia_school_data_field[key] = row[index] + end + @olympia_school_data_field.save + end + end + return true + end + end + def import_class_setting_check(tempfile,filename) + @profile_data_row = [ "school_code", "school_name" , "school_address" ,"class_number","enrollment_limited","school_contact_person_name","department_job_title","office_tel_number","fax","mobile_number","email","enrollment"] + @error_msg = Array.new + @filename = filename.nil? ? tempfile.path : filename + @row_index_hash = {} + begin + workbook = RubyXL::Parser.parse(tempfile) + rescue + @error_msg << filename+'格式錯誤' + return @error_msg + end + sheet = workbook[0].sheet_data.rows + first_index = 0 + sheet.each_with_index do |raw_row,index| + begin + row = raw_row.cells.map{ |cell| cell.value rescue nil} + rescue + @error_msg << filename+'格式錯誤' + return @error_msg + end + if row.nil? && first_index != -1 + next + elsif row.nil? + next + end + if index == first_index || first_index != -1 + @field_data = row + delete_array = [] + @profile_data_row.each do |row_key| + if !@field_data.include?(t('olympiamanagement.'+row_key)) + delete_array << row_key + else + @row_index_hash[row_key] = @field_data.index(t('olympiamanagement.'+row_key)) + end + end + delete_array.each{|element| @profile_data_row.delete(element)} + first_index = -1 + 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}欄位學校代碼不符(該欄位值不可為空)。" + end + end + end + end + def make_alpha_from_numbers(number) + @numeric = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + if number < @numeric.size + @a = @numeric[number] + else + @dev_by = (number/@numeric.size).floor + @a = "#{make_alpha_from_numbers(@dev_by-1)}#{make_alpha_from_numbers(number-(@dev_by*@numeric.size))}"; + end + end def sign_up_setting + @sign_up_setting = (SignUpSetting.all.length == 0) ? (SignUpSetting.new) : (SignUpSetting.last) + @site_locales = Site.first.in_use_locales + @site_locales.delete(I18n.locale) + @site_locales.insert(0,I18n.locale) end def export_school_connection_data + @OlympiaSchoolDataFields = OlympiaSchoolDataFields.all + 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 + @filename = 'school_export.xlsx' + Dir.chdir(dir_path) do + File.open(@filename, 'w') do |f| + f.write render_to_string( :handlers=> [:axlsx], :formats=> [:xlsx] ,:partial=> 'school_export.xlsx',:locals=> {:@OlympiaSchoolDataFields=>@OlympiaSchoolDataFields} ) + end + end + tmp_filename_data = File.read(dir_path +@filename) + send_data(tmp_filename_data, type: 'application/xlsx', disposition: 'attachment', filename: @filename) end def export_sign_up_student_data + # @OlympiaSchoolDataFields = OlympiaSchoolDataFields.all + # 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 + # @filename = 'school_export.xlsx' + # Dir.chdir(dir_path) do + # File.open(@filename, 'w') do |f| + # f.write render_to_string( :handlers=> [:axlsx], :formats=> [:xlsx] ,:partial=> 'school_export.xlsx',:locals=> {:@OlympiaSchoolDataFields=>@OlympiaSchoolDataFields} ) + # end + # 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 end def import_editing_number_of_school_class + @olympia_school_data_field = OlympiaSchoolDataFields.new + end + def download_import_file + @OlympiaSchoolDataFields = OlympiaSchoolDataFields.all + 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 + @filename = 'import_schoo_class_setting.xlsx' + Dir.chdir(dir_path) do + File.open(@filename, 'w') do |f| + f.write render_to_string( :handlers=> [:axlsx], :formats=> [:xlsx] ,:partial=> 'import_schoo_class_setting.xlsx',:locals=> {:@OlympiaSchoolDataFields=>@OlympiaSchoolDataFields} ) + end + end + tmp_filename_data = File.read(dir_path +@filename) + send_data(tmp_filename_data, type: 'application/xlsx', disposition: 'attachment', filename: "#{Time.now.year}#{Time.now.month}#{Time.now.day}_import_schoo_class_setting.xlsx") end end \ No newline at end of file diff --git a/app/helpers/admin/olympiamanagements_helper.rb b/app/helpers/admin/olympiamanagements_helper.rb index ff41f0f..0a9a00d 100644 --- a/app/helpers/admin/olympiamanagements_helper.rb +++ b/app/helpers/admin/olympiamanagements_helper.rb @@ -1,11 +1,37 @@ module Admin::OlympiamanagementsHelper - def create_pagination(page=1,fields=ClassSettingFields) + def create_pagination(page=1,fields=ClassSettingFields.all,extra_params="") page = 1 if page == 0 - per_page_num = 10 - all_page_num = fields.all.count / per_page_num + 1 + per_page_num = 10.0 + all_page_num = (fields.count / per_page_num).ceil pagination = '
'+((I18n.locale.to_s == 'zh_tw') ? "第 #{page} 頁" : "page #{page}") +'/'+ ((I18n.locale.to_s == 'zh_tw') ? "共 #{all_page_num} 頁" : "Total #{all_page_num} page(s)")+'
    '+ - ((page == 1) ? '
  1. ['+t('olympiamanagement.prev_page')+']
  2. ' : '
  3. ['+t('olympiamanagement.prev_page')+']
  4. ') - (1..all_page_num).to_a.each{|page_num| pagination += ((page_num == page) ? '
  5. '+page_num.to_s+'
  6. ' : '
  7. '+page_num.to_s+'
  8. ')} - pagination += (((page==all_page_num) ? '
  9. ['+t('olympiamanagement.next_page')+']
  10. ' : '
  11. ['+t('olympiamanagement.next_page')+']
  12. ')+'
') + ((page == 1) ? '
  • ['+t('olympiamanagement.prev_page')+']
  • ' : '
  • ['+t('olympiamanagement.prev_page')+']
  • ') + if all_page_num > 7 + if page <= (all_page_num / 2) + if page <= 7 + (1..page).to_a.each{|page_num| pagination += ((page_num == page) ? '
  • ['+page_num.to_s+']
  • ' : '
  • '+page_num.to_s+'
  • ')} + else + (1..3).to_a.each{|page_num| pagination += ((page_num == page) ? '
  • ['+page_num.to_s+']
  • ' : '
  • '+page_num.to_s+'
  • ')} + pagination +='
  • ...
  • ' + (page-3..page).to_a.each{|page_num| pagination += ((page_num == page) ? '
  • ['+page_num.to_s+']
  • ' : '
  • '+page_num.to_s+'
  • ')} + end + (page+1..page+3).to_a.each{|page_num| pagination += ((page_num == page) ? '
  • ['+page_num.to_s+']
  • ' : '
  • '+page_num.to_s+'
  • ')} + pagination +='
  • ...
  • ' + (all_page_num-2..all_page_num).to_a.each{|page_num| pagination += ((page_num == page) ? '
  • ['+page_num.to_s+']
  • ' : '
  • '+page_num.to_s+'
  • ')} + else + (1..3).to_a.each{|page_num| pagination += ((page_num == page) ? '
  • ['+page_num.to_s+']
  • ' : '
  • '+page_num.to_s+'
  • ')} + pagination +='
  • ...
  • ' + (page-3..page).to_a.each{|page_num| pagination += ((page_num == page) ? '
  • ['+page_num.to_s+']
  • ' : '
  • '+page_num.to_s+'
  • ')} + if all_page_num - page <= 7 + (page+1..all_page_num).to_a.each{|page_num| pagination += ((page_num == page) ? '
  • ['+page_num.to_s+']
  • ' : '
  • '+page_num.to_s+'
  • ')} + else + (page+1..page+3).to_a.each{|page_num| pagination += ((page_num == page) ? '
  • ['+page_num.to_s+']
  • ' : '
  • '+page_num.to_s+'
  • ')} + pagination +='
  • ...
  • ' + (all_page_num-2..all_page_num).to_a.each{|page_num| pagination += ((page_num == page) ? '
  • ['+page_num.to_s+']
  • ' : '
  • '+page_num.to_s+'
  • ')} + end + end + else + (1..all_page_num).to_a.each{|page_num| pagination += ((page_num == page) ? '
  • ['+page_num.to_s+']
  • ' : '
  • '+page_num.to_s+'
  • ')} + end + pagination += (((page==all_page_num) ? '
  • ['+t('olympiamanagement.next_page')+']
  • ' : '
  • ['+t('olympiamanagement.next_page')+']
  • ')+'') end end \ No newline at end of file diff --git a/app/models/olympia_school_data_fields.rb b/app/models/olympia_school_data_fields.rb index 26be76e..c99d6ba 100644 --- a/app/models/olympia_school_data_fields.rb +++ b/app/models/olympia_school_data_fields.rb @@ -19,4 +19,27 @@ 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 :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 + end + if self.enrollment.nil? + self.enrollment = 0 + self.save + end + if self.sign_up_setting_id.nil? + self.sign_up_setting_id = SignUpSetting.last.id.to_s + self.save + end + sign_up_setting = SignUpSetting.find(self.sign_up_setting_id) rescue nil + if sign_up_setting.nil? + self.destroy + end + end + end end \ No newline at end of file diff --git a/app/models/school_data_fields.rb b/app/models/school_data_fields.rb index 2656ae7..6aa7289 100644 --- a/app/models/school_data_fields.rb +++ b/app/models/school_data_fields.rb @@ -6,13 +6,13 @@ class SchoolDataFields # encoding: utf-8 include OrbitTag::Taggable include OrbitCategory::Categorizable - field :school_data_fields , type: Array , default: [{'account_number'=>{'type'=>'String','size'=>'20','hint'=>{'zh_tw'=>'','en'=>''}}}, - {'password'=>{'type'=>'String','size'=>'','hint'=>{'zh_tw'=>'未修改即依照預設密碼','en'=>''}}}, - {'school_name'=>{'type'=>'String','size'=>'20','hint'=>{'zh_tw'=>'','en'=>''}}}, - {'school_code'=>{'type'=>'String','size'=>'20','hint'=>{'zh_tw'=>'','en'=>''}}}, - {'school_address'=>{'type'=>'String','size'=>'40','hint'=>{'zh_tw'=>'','en'=>''}}}, - {'class_number'=>{'type'=>'select','size'=>'','hint'=>{'zh_tw'=>'','en'=>''},'range'=>[1,200],'unit'=>{'zh_tw'=>'班','en'=>'class'}}}, - {'enrollment_limited'=>{'type'=>'Fixnum','size'=>'5','hint'=>{'zh_tw'=>'未修改即依照班級設定','en'=>''}}}, + field :school_data_fields , type: Array , default: [{'account_number'=>{'type'=>'String','size'=>'20','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true"}}, + {'password'=>{'type'=>'String','size'=>'','hint'=>{'zh_tw'=>'未修改即依照預設密碼','en'=>'Use default password without modification'}}}, + {'school_name'=>{'type'=>'String','size'=>'20','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true"}}, + {'school_code'=>{'type'=>'String','size'=>'20','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true"}}, + {'school_address'=>{'type'=>'String','size'=>'40','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true"}}, + {'class_number'=>{'type'=>'select','size'=>'','hint'=>{'zh_tw'=>'','en'=>''},'range'=>[1,200],'unit'=>{'zh_tw'=>'班','en'=>'class'},'required'=>"true"}}, + {'enrollment_limited'=>{'type'=>'Fixnum','size'=>'5','hint'=>{'zh_tw'=>'未修改即依照班級設定','en'=>'Use class settings without modification'}}}, {'school_contact_person_name'=>{'type'=>'String','size'=>'20','hint'=>{'zh_tw'=>'','en'=>''}}}, {'department_job_title'=>{'type'=>'String','size'=>'20','hint'=>{'zh_tw'=>'','en'=>''}}}, {'office_tel_number'=>{'type'=>'String','size'=>'20','hint'=>{'zh_tw'=>'','en'=>''}}}, diff --git a/app/models/sign_up_setting.rb b/app/models/sign_up_setting.rb new file mode 100644 index 0000000..ae04947 --- /dev/null +++ b/app/models/sign_up_setting.rb @@ -0,0 +1,34 @@ +class SignUpSetting + include Mongoid::Document + include Mongoid::Timestamps + include OrbitModel::Status + include OrbitModel::Impression + # encoding: utf-8 + include OrbitTag::Taggable + include OrbitCategory::Categorizable + field :start_year , type: String , default: Time.now.strftime("%Y") + field :end_year , type: String , default: Time.now.strftime("%Y") + field :start_month , type: String , default: Time.now.strftime("%m") + field :end_month , type: String , default: Time.now.strftime("%m") + field :start_day , type: String , default: Time.now.strftime("%d") + field :end_day , type: String , default: Time.now.strftime("%d") + field :start_o_clock , type: String , default: Time.now.strftime("%H") + field :end_o_clock , type: String , default: Time.now.strftime("%H") + field :start_minute , type: String , default: Time.now.strftime("%M") + 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=>"",:en=>""} + field :registration_instructions , type: Hash , default: {:zh_tw=>"",:en=>""} + after_save :change_all_password + def change_all_password + if self.set_default_password + OlympiaSchoolDataFields.all.each do |school_field| + school_field.password = self.default_password + school_field.save + end + self.set_default_password = false + self.save + end + end +end \ No newline at end of file diff --git a/app/views/admin/olympiamanagements/_checkbox.html.erb b/app/views/admin/olympiamanagements/_checkbox.html.erb new file mode 100644 index 0000000..1eb9600 --- /dev/null +++ b/app/views/admin/olympiamanagements/_checkbox.html.erb @@ -0,0 +1,5 @@ +
    + + class="checkbox" id="<%=id%>" name="<%=params_name%>" style="float:left;" type="checkbox" value="1"> + +
    \ No newline at end of file diff --git a/app/views/admin/olympiamanagements/_import_schoo_class_setting.xlsx.axlsx b/app/views/admin/olympiamanagements/_import_schoo_class_setting.xlsx.axlsx new file mode 100644 index 0000000..7e3da27 --- /dev/null +++ b/app/views/admin/olympiamanagements/_import_schoo_class_setting.xlsx.axlsx @@ -0,0 +1,27 @@ +# encoding: utf-8 + +wb = xlsx_package.workbook +wb.add_worksheet(name: "school_class") do |sheet| + row = [] + title = sheet.styles.add_style(:bg_color => "FFFF00",:border=>{ :style => :thin, :color => "666666" },:alignment=>{ :horizontal => :center,:vertical => :center ,:wrap_text => true}) + column = sheet.styles.add_style(:alignment=>{ :horizontal => :center,:vertical => :center ,:wrap_text => true},:border=>{ :style => :thin, :color => "666666" }) + @fields = [ "school_code", "school_name" ,"class_number" ] + @fields.each do |field| + row << t('olympiamanagement.'+field) + end + #export data start + export_data_rows = [] + @OlympiaSchoolDataFields.each do |school_data_field| + temp_row = [] + @fields.each do |field_key| + temp_row << (school_data_field[field_key] rescue '') + end + export_data_rows << temp_row + end + + #export data end + sheet.add_row row , :style=> title,:widths => row.map{|cell| (cell.length* 11/ 2).round} + export_data_rows.each do |infos_row| + sheet.add_row infos_row , :style=> column + end +end \ No newline at end of file diff --git a/app/views/admin/olympiamanagements/_school_export.xlsx.axlsx b/app/views/admin/olympiamanagements/_school_export.xlsx.axlsx new file mode 100644 index 0000000..2292765 --- /dev/null +++ b/app/views/admin/olympiamanagements/_school_export.xlsx.axlsx @@ -0,0 +1,27 @@ +# encoding: utf-8 + +wb = xlsx_package.workbook +wb.add_worksheet(name: "school_class") do |sheet| + row = [] + title = sheet.styles.add_style(:bg_color => "FFFF00",:border=>{ :style => :thin, :color => "666666" },:alignment=>{ :horizontal => :center,:vertical => :center ,:wrap_text => true}) + column = sheet.styles.add_style(:alignment=>{ :horizontal => :center,:vertical => :center ,:wrap_text => true},:border=>{ :style => :thin, :color => "666666" }) + @fields = [ "school_code", "school_name" , "school_address" ,"class_number","enrollment_limited","school_contact_person_name","department_job_title","office_tel_number","fax","mobile_number","email","enrollment"] + @fields.each do |field| + row << t('olympiamanagement.'+field) + end + #export data start + export_data_rows = [] + @OlympiaSchoolDataFields.each do |school_data_field| + temp_row = [] + @fields.each do |field_key| + temp_row << (school_data_field[field_key] rescue '') + end + export_data_rows << temp_row + end + + #export data end + sheet.add_row row , :style=> title,:widths => row.map{|cell| (cell.length* 11/ 2).round} + export_data_rows.each do |infos_row| + sheet.add_row infos_row , :style=> column + end +end \ No newline at end of file diff --git a/app/views/admin/olympiamanagements/_select.html.erb b/app/views/admin/olympiamanagements/_select.html.erb new file mode 100644 index 0000000..b3b51d7 --- /dev/null +++ b/app/views/admin/olympiamanagements/_select.html.erb @@ -0,0 +1,7 @@ +<% @please_choice = (I18n.locale.to_s == "zh_tw") ? "請選擇" : "Please select." %> + \ No newline at end of file diff --git a/app/views/admin/olympiamanagements/add_school_data.html.erb b/app/views/admin/olympiamanagements/add_school_data.html.erb index 830efdb..8c9ff98 100644 --- a/app/views/admin/olympiamanagements/add_school_data.html.erb +++ b/app/views/admin/olympiamanagements/add_school_data.html.erb @@ -6,17 +6,20 @@ <%=form_for @olympia_school_data_field ,:url=>{:controller=>"olympiamanagements" ,:action=>"update_school_data",:type=>"add_school_data",:id=>params[:id]} do |form|%> <% @SchoolDataField.school_data_fields.each do |field| %>
    + <% @extra_class = ((field.values[0]["required"] == "true")? " required" : "")%> + <% @extra_text = ((field.values[0]["required"] == "true")? "*" : "")%> +
  • <%= @extra_text+t('olympiamanagement.'+field.keys[0]) %>
  • <% if field.values[0][:type] != 'select' %> -
  • <%= t('olympiamanagement.'+field.keys[0]) %>
  • " value="<%= @olympia_school_data_field[field.keys[0]] %>" size="<%=field.values[0][:size]%>" type="text" id="<%= field.keys[0] %>" class="col_input"/>
  • + " 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%>"/> <% else%> <% @please_choice = (I18n.locale.to_s == "zh_tw") ? "請選擇" : "Please select." %> -
  • <%= t('olympiamanagement.'+field.keys[0]) %>
  • - + <% end %> +
  • <% if !field.values[0][:hint][I18n.locale.to_s].blank? %> <%=field.values[0][:hint][I18n.locale.to_s]%> <% end %> diff --git a/app/views/admin/olympiamanagements/import_editing_number_of_school_class.html.erb b/app/views/admin/olympiamanagements/import_editing_number_of_school_class.html.erb index e69de29..d54d701 100644 --- a/app/views/admin/olympiamanagements/import_editing_number_of_school_class.html.erb +++ b/app/views/admin/olympiamanagements/import_editing_number_of_school_class.html.erb @@ -0,0 +1,16 @@ + +
    ※<%=t('olympiamanagement.import_hint_first')%>
    +
    ※<%=t('olympiamanagement.import_hint_second')%>
    +<%= form_tag admin_olympiamanagements_update_school_data_path(:type => "import_class_setting"), :multipart => true , :class=>"form-horizontal main-forms", :id=>"import_class_setting" do %> + <%=t('olympiamanagement.upload_file')%> + <%= file_field_tag :upload_file %> + <%= submit_tag t('olympiamanagement.submit') , :class=>"btn btn-default" %> +<% end %> +<% if params['error'] == "true" %> + +<% end %> \ No newline at end of file diff --git a/app/views/admin/olympiamanagements/import_error_msg.html.erb b/app/views/admin/olympiamanagements/import_error_msg.html.erb new file mode 100644 index 0000000..3837e03 --- /dev/null +++ b/app/views/admin/olympiamanagements/import_error_msg.html.erb @@ -0,0 +1,14 @@ + +

    <%= t('site.import_member_data.import_error')%>

    + +
      +<% @error_msg.each do |a| %> + +
    • <%= a %>
    • + +<% end %> + +
    + + +<%= link_to t('back'), :back, :class => 'btn' %> \ 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 c11aa83..3ce8df2 100644 --- a/app/views/admin/olympiamanagements/school_data_list.html.erb +++ b/app/views/admin/olympiamanagements/school_data_list.html.erb @@ -33,7 +33,13 @@ <% 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') %> + <%if field.approved%> + "><%= t('olympiamanagement.unapproved') %><%= t('olympiamanagement.unapproved') %> + <% else %> + "><%= t('olympiamanagement.approved') %><%= t('olympiamanagement.approved') %> + <% end %> <% end %> <% end %> @@ -41,4 +47,5 @@ <%end%> -<%=create_pagination(params[:page].to_i,OlympiaSchoolDataFields).html_safe%> \ No newline at end of file +<% @extra_params = request.query_parameters.map{|key,value| key+'='+value}.join('&') %> +<%=create_pagination(params[:page].to_i,@OlympiaSchoolDataFields,@extra_params).html_safe%> \ No newline at end of file diff --git a/app/views/admin/olympiamanagements/sign_up_setting.html.erb b/app/views/admin/olympiamanagements/sign_up_setting.html.erb index e69de29..2db38bc 100644 --- a/app/views/admin/olympiamanagements/sign_up_setting.html.erb +++ b/app/views/admin/olympiamanagements/sign_up_setting.html.erb @@ -0,0 +1,92 @@ + + + + diff --git a/config/locales/en.yml b/config/locales/en.yml index 4494854..dd76b6e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -18,7 +18,10 @@ en: cancel: Cancel action: Action edit: Edit + sign_up_student_data: Sign up student data delete: Delete + approved: Recover + unapproved: Suspended search: Search school_name: School name school_code: School code @@ -35,4 +38,22 @@ en: school_contact_person_name: School contact person's name prev_page: Previous page next_page: Next page - \ No newline at end of file + download_import_file: Download import file + upload_file: Upload file + import_hint_first: Please download import file first,and import after editing number of school class. + import_hint_second: Please don't change school code in the import Excel file , or it will cause the error when import data. + delete_all_sign_up_data: Delete all sign up data + sign_up_start_time: Start time of sign up + sign_up_end_time: End time of sign up + default_password: Default password + sign_up_setting_hint: Update all accounts to default password. + last_edit_time: Last edit time + a_d_: A.D. + year: Year + month: Month + day: Day + o_clock: o'clock + minute: Min. + remark: Remarks + registration_instructions: Online registration instructions + print_registration_form: Print registration form \ No newline at end of file diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 3d9e94c..086dd8a 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -18,7 +18,10 @@ zh_tw: cancel: 取消 action: 動作 edit: 編輯 + sign_up_student_data: 學生報名資料 delete: 刪除 + approved: 恢復 + unapproved: 停用 search: 搜尋 school_name: 學校名稱 school_code: 學校代碼 @@ -34,4 +37,23 @@ zh_tw: department_job_title: 單位職稱 school_contact_person_name: 學校聯絡人姓名 prev_page: 上一頁 - next_page: 下一頁 \ No newline at end of file + next_page: 下一頁 + download_import_file: 下載匯入檔案 + upload_file: 上傳檔案 + import_hint_first: 請先下載匯入檔案,修改班級數之後再匯入。 + import_hint_second: 請勿變更Excel檔案中的學校代碼,這會造成資料匯入異常。 + delete_all_sign_up_data: 刪除所有報名者的資料 + sign_up_start_time: 報名開始時間 + sign_up_end_time: 報名結束時間 + default_password: 預設密碼 + sign_up_setting_hint: 更新全部帳號為預設密碼。 + last_edit_time: 上次修改時間 + a_d_: 西元 + year: 年 + month: 月 + day: 日 + o_clock: 時 + minute: 分 + remark: 注意事項 + registration_instructions: 線上報名說明 + print_registration_form: 列印報名表 \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 1b0fd2a..0f28d04 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -16,6 +16,10 @@ Rails.application.routes.draw do post 'olympiamanagements/update_school_data' , to: 'olympiamanagements#update_school_data' patch 'olympiamanagements/update_school_data' , to: 'olympiamanagements#update_school_data' get 'olympiamanagements/update_school_data' , to: 'olympiamanagements#update_school_data' + post 'olympiamanagements/update_sign_up_data' , to: 'olympiamanagements#update_sign_up_data' + patch 'olympiamanagements/update_sign_up_data' , to: 'olympiamanagements#update_sign_up_data' + get 'olympiamanagements/update_sign_up_data' , to: 'olympiamanagements#update_sign_up_data' + get 'olympiamanagements/download_import_file' , to: 'olympiamanagements#download_import_file' resources :olympiamanagements end end