finish admin pages except student

This commit is contained in:
BOHUNG 2020-01-31 18:52:53 +08:00
parent 994c117220
commit e4139e72ad
22 changed files with 673 additions and 25 deletions

BIN
app/assets/images/ok.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 576 B

View File

@ -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('<div id="SchoolName-E" class="errMsg"> '+((I18n.locale == "en") ? 'Required field': '必填欄位')+'</div>');
}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();
});

View File

@ -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;
}

View File

@ -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;

View File

@ -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

View File

@ -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 = '<div class="PageDetails">'+((I18n.locale.to_s == 'zh_tw') ? "#{page}" : "page #{page}") +'/'+ ((I18n.locale.to_s == 'zh_tw') ? "#{all_page_num}" : "Total #{all_page_num} page(s)")+'<ol class="PageList">'+
((page == 1) ? '<li>['+t('olympiamanagement.prev_page')+']</li>' : '<li><a href="?page='+(page-1).to_s+'"> ['+t('olympiamanagement.prev_page')+'] </a></li>')
(1..all_page_num).to_a.each{|page_num| pagination += ((page_num == page) ? '<li>'+page_num.to_s+'</li>' : '<li><a href="?page='+page_num.to_s+'"> '+page_num.to_s+' </a></li>')}
pagination += (((page==all_page_num) ? '<li>['+t('olympiamanagement.next_page')+']</li>' : '<li><a href="?page='+(page+1).to_s+'"> ['+t('olympiamanagement.next_page')+'] </a></li>')+'</ol></div>')
((page == 1) ? '<li>['+t('olympiamanagement.prev_page')+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+(page-1).to_s+'"> ['+t('olympiamanagement.prev_page')+'] </a></li>')
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) ? '<li>['+page_num.to_s+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+page_num.to_s+'"> '+page_num.to_s+' </a></li>')}
else
(1..3).to_a.each{|page_num| pagination += ((page_num == page) ? '<li>['+page_num.to_s+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+page_num.to_s+'"> '+page_num.to_s+' </a></li>')}
pagination +='<li>...</li>'
(page-3..page).to_a.each{|page_num| pagination += ((page_num == page) ? '<li>['+page_num.to_s+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+page_num.to_s+'"> '+page_num.to_s+' </a></li>')}
end
(page+1..page+3).to_a.each{|page_num| pagination += ((page_num == page) ? '<li>['+page_num.to_s+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+page_num.to_s+'"> '+page_num.to_s+' </a></li>')}
pagination +='<li>...</li>'
(all_page_num-2..all_page_num).to_a.each{|page_num| pagination += ((page_num == page) ? '<li>['+page_num.to_s+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+page_num.to_s+'"> '+page_num.to_s+' </a></li>')}
else
(1..3).to_a.each{|page_num| pagination += ((page_num == page) ? '<li>['+page_num.to_s+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+page_num.to_s+'"> '+page_num.to_s+' </a></li>')}
pagination +='<li>...</li>'
(page-3..page).to_a.each{|page_num| pagination += ((page_num == page) ? '<li>['+page_num.to_s+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+page_num.to_s+'"> '+page_num.to_s+' </a></li>')}
if all_page_num - page <= 7
(page+1..all_page_num).to_a.each{|page_num| pagination += ((page_num == page) ? '<li>['+page_num.to_s+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+page_num.to_s+'"> '+page_num.to_s+' </a></li>')}
else
(page+1..page+3).to_a.each{|page_num| pagination += ((page_num == page) ? '<li>['+page_num.to_s+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+page_num.to_s+'"> '+page_num.to_s+' </a></li>')}
pagination +='<li>...</li>'
(all_page_num-2..all_page_num).to_a.each{|page_num| pagination += ((page_num == page) ? '<li>['+page_num.to_s+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+page_num.to_s+'"> '+page_num.to_s+' </a></li>')}
end
end
else
(1..all_page_num).to_a.each{|page_num| pagination += ((page_num == page) ? '<li>['+page_num.to_s+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+page_num.to_s+'"> '+page_num.to_s+' </a></li>')}
end
pagination += (((page==all_page_num) ? '<li>['+t('olympiamanagement.next_page')+']</li>' : '<li><a href="'+(extra_params.blank? ? '?' : "?#{extra_params}&")+'page='+(page+1).to_s+'"> ['+t('olympiamanagement.next_page')+'] </a></li>')+'</ol></div>')
end
end

View File

@ -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

View File

@ -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'=>''}}},

View File

@ -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

View File

@ -0,0 +1,5 @@
<div class="required <%=extra_class%>">
<input name="<%=params_name%>" type="hidden" value="0">
<input <%=is_checked ? "checked=checked" : "" %> class="checkbox" id="<%=id%>" name="<%=params_name%>" style="float:left;" type="checkbox" value="1">
<label class="checklabel" for="<%=name%>" style="float:right;"><%=name%></label>
</div>

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,7 @@
<% @please_choice = (I18n.locale.to_s == "zh_tw") ? "請選擇" : "Please select." %>
<select name="<%=name%>" id="<%=id%>" class="<%=extra_class%> required" value="<%= value %>" style="width: auto;"><option value=""><%=@please_choice%></option>
<% @max_length = range[1].to_s.length %>
<% for @num in range[0] .. range[1] %>
<%= ('<option value="' + ((is_add_zero rescue false) ? @num.to_s.insert(0,(1..(@max_length-@num.to_s.length)).collect{"0"}.join) : @num.to_s) + '">' + ((is_add_zero rescue false) ? @num.to_s.insert(0,(1..(@max_length-@num.to_s.length)).collect{"0"}.join) : @num.to_s) + unit + '</option>').html_safe %>
<% end %>
</select>

View File

@ -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| %>
<div class="col_text">
<% @extra_class = ((field.values[0]["required"] == "true")? " required" : "")%>
<% @extra_text = ((field.values[0]["required"] == "true")? "*" : "")%>
<li class="col<%=@extra_class%>" for="<%=field.keys[0]%>"><%= @extra_text+t('olympiamanagement.'+field.keys[0]) %></li><li class="col_r">
<% if field.values[0][:type] != 'select' %>
<li class="col" for="<%=field.keys[0]%>"><%= t('olympiamanagement.'+field.keys[0]) %></li><li class="col_r"><input name="<%="[add_school_data][#{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"/></li>
<input name="<%="[add_school_data][#{field.keys[0]}]"%>" 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." %>
<li class="col" for="<%=field.keys[0]%>"><%= t('olympiamanagement.'+field.keys[0]) %></li><li class="col_r">
<select name="<%="[add_school_data][#{field.keys[0]}]"%>" id="<%=field.keys[0]%>" class="required" value="<%= @olympia_school_data_field[field.keys[0]] %>" ><option value=""><%=@please_choice%></option>
<% for @num in field.values[0]["range"][0] .. field.values[0]["range"][1] %>
<%= ('<option value="' + @num.to_s + '">' + @num.to_s + field.values[0][:unit][I18n.locale.to_s] + '</option>').html_safe %>
<% end %>
</select>
<select name="<%="[add_school_data][#{field.keys[0]}]"%>" id="<%=field.keys[0]%>" class="required" value="<%= @olympia_school_data_field[field.keys[0]] %>" style="width: auto;"><option value=""><%=@please_choice%></option>
<% for @num in field.values[0]["range"][0] .. field.values[0]["range"][1] %>
<%= ('<option value="' + @num.to_s + '">' + @num.to_s + field.values[0][:unit][I18n.locale.to_s] + '</option>').html_safe %>
<% end %>
</select>
<% end %>
</li>
<% if !field.values[0][:hint][I18n.locale.to_s].blank? %>
<span id="-H" class="field-hint-inactive"><%=field.values[0][:hint][I18n.locale.to_s]%></span>
<% end %>

View File

@ -0,0 +1,16 @@
<div><a href="<%= admin_olympiamanagements_download_import_file_path %>"><%=t('olympiamanagement.download_import_file')%></a></div>
<div>※<%=t('olympiamanagement.import_hint_first')%></div>
<div>※<%=t('olympiamanagement.import_hint_second')%></div>
<%= form_tag admin_olympiamanagements_update_school_data_path(:type => "import_class_setting"), :multipart => true , :class=>"form-horizontal main-forms", :id=>"import_class_setting" do %>
<span style="margin-right: 0.3em;"><%=t('olympiamanagement.upload_file')%></span>
<%= file_field_tag :upload_file %>
<%= submit_tag t('olympiamanagement.submit') , :class=>"btn btn-default" %>
<% end %>
<% if params['error'] == "true" %>
<script>
$(window).load(function(){
alert("<%=(I18n.locale.to_s == 'en') ? 'Please upload import file!' : '請上傳要匯入的檔案!'%>");
window.location.search='';
});
</script>
<% end %>

View File

@ -0,0 +1,14 @@
<h2><%= t('site.import_member_data.import_error')%></h2>
<ul>
<% @error_msg.each do |a| %>
<li><%= a %></li>
<% end %>
</ul>
<%= link_to t('back'), :back, :class => 'btn' %>

View File

@ -33,7 +33,13 @@
<% else %>
<td>
<a href="<%=admin_olympiamanagements_add_school_data_path+"?id=#{field.id}"%>"><img src="/assets/edit.gif" alt="<%= t('olympiamanagement.edit') %>" align="top" width="24"><%= t('olympiamanagement.edit') %></a>
<a href="<%=admin_olympiamanagements_add_school_data_path+"?id=#{field.id}"%>"><img src="/assets/view.gif" alt="<%= t('olympiamanagement.sign_up_student_data') %>" align="top" width="24"><%= t('olympiamanagement.sign_up_student_data') %></a>
<a href="<%=admin_olympiamanagements_update_school_data_path+"?id=#{field.id}&type=delete_school_data"%>"><img src="/assets/trash.gif" alt="<%= t('olympiamanagement.delete') %>" align="top" width="24"><%= t('olympiamanagement.delete') %></a>
<%if field.approved%>
<a href="<%=admin_olympiamanagements_update_school_data_path+"?id=#{field.id}&type=unapproved"%>"><img src="/assets/close.gif" alt="<%= t('olympiamanagement.unapproved') %>" align="top" width="24"><%= t('olympiamanagement.unapproved') %></a>
<% else %>
<a href="<%=admin_olympiamanagements_update_school_data_path+"?id=#{field.id}&type=approved"%>"><img src="/assets/ok.gif" alt="<%= t('olympiamanagement.approved') %>" align="top" width="24"><%= t('olympiamanagement.approved') %></a>
<% end %>
</td>
<% end %>
<% end %>
@ -41,4 +47,5 @@
<%end%>
</tbody>
</table>
<%=create_pagination(params[:page].to_i,OlympiaSchoolDataFields).html_safe%>
<% @extra_params = request.query_parameters.map{|key,value| key+'='+value}.join('&') %>
<%=create_pagination(params[:page].to_i,@OlympiaSchoolDataFields,@extra_params).html_safe%>

View File

@ -0,0 +1,92 @@
<link rel="stylesheet" media="screen" type="text/css" href="/assets/admin/olympiamanagement.scss">
<link rel="stylesheet" media="print" type="text/css" href="/assets/admin/olympiamanagement.scss">
<script src="/assets/admin/olympiamanagement.js"></script>
<fieldset class="fieldset_block sign_up_setting_block">
<legend class="fieldset_title"><%=t('olympiamanagement.sign_up_setting')%></legend>
<%=form_for @sign_up_setting ,:url=>{:controller=>"olympiamanagements" ,:action=>"update_school_data",:type=>"sign_up_setting",:id=>params[:id]} do |form|%>
<a href="#" onclick="if( window.confirm('Please confirm deletion.?') ) { window.location='<%=admin_olympiamanagements_update_sign_up_data_path + '?type=delete_old_data'%>'; }" onkeypress="if( window.confirm('Please confirm deletion.?') ) { window.location='<%=admin_olympiamanagements_update_sign_up_data_path + '?type=delete_old_data'%>'; }">
<img src="/assets/trash.gif" alt="<%=t('olympiamanagement.delete_all_sign_up_data')%>" align="top" width="24"><%=t('olympiamanagement.delete_all_sign_up_data')%></a>
<hr style="border-color: black;border-top: 0em;">
<div class="col_text">
<li class="col" for="start_time"><%= t('olympiamanagement.sign_up_start_time')%></li>
<li class="col_r" id="start_time">
<span style="float: left;padding: 0.3em;"><%= t('olympiamanagement.a_d_')%></span>
<%=render :partial=>'select',:locals=>{:name=>'[sign_up_setting][start_year]',:id=>'start_year',:value=> @sign_up_setting['start_year'],:unit=>'',:range=>[Time.now.year-10,Time.now.year+10],:extra_class=>'lleft',:is_add_zero=>false}%>
<span style="float: left;padding: 0.3em;"><%= t('olympiamanagement.year')%></span>
<%=render :partial=>'select',:locals=>{:name=>'[sign_up_setting][start_month]',:id=>'start_month',:value=>@sign_up_setting['start_month'],:unit=>'',:range=>[1,12],:extra_class=>'lleft',:is_add_zero=>true}%>
<span style="float: left;padding: 0.3em;"><%= t('olympiamanagement.month')%></span>
<%=render :partial=>'select',:locals=>{:name=>'[sign_up_setting][start_day]',:id=>'start_day',:value=>@sign_up_setting['start_day'],:unit=>'',:range=>[1,31],:extra_class=>'lleft',:is_add_zero=>true}%>
<span style="float: left;padding: 0.3em;"><%= t('olympiamanagement.day')%></span>
<%=render :partial=>'select',:locals=>{:name=>'[sign_up_setting][start_o_clock]',:id=>'start_o_clock',:value=>@sign_up_setting['start_o_clock'],:unit=>'',:range=>[0,23],:extra_class=>'lleft',:is_add_zero=>true}%>
<span style="float: left;padding: 0.3em;"><%= t('olympiamanagement.o_clock')%></span>
<%=render :partial=>'select',:locals=>{:name=>'[sign_up_setting][start_minute]',:id=>'start_minute',:value=>@sign_up_setting['start_minute'],:unit=>'',:range=>[0,59],:extra_class=>'lleft',:is_add_zero=>true}%>
<span style="float: left;padding: 0.3em;"><%= t('olympiamanagement.minute')%></span>
</li>
</div>
<div class="col_text">
<li class="col" for="end_time"><%= t('olympiamanagement.sign_up_end_time')%></li>
<li class="col_r" id="end_time">
<span style="float: left;padding: 0.3em;"><%= t('olympiamanagement.a_d_')%></span>
<%=render :partial=>'select',:locals=>{:name=>'[sign_up_setting][end_year]',:id=>'end_year',:value=>@sign_up_setting['end_year'],:unit=>'',:range=>[Time.now.year-10,Time.now.year+10],:extra_class=>'lleft',:is_add_zero=>false}%>
<span style="float: left;padding: 0.3em;"><%= t('olympiamanagement.year')%></span>
<%=render :partial=>'select',:locals=>{:name=>'[sign_up_setting][end_month]',:id=>'end_month',:value=>@sign_up_setting['end_month'],:unit=>'',:range=>[1,12],:extra_class=>'lleft',:is_add_zero=>true}%>
<span style="float: left;padding: 0.3em;"><%= t('olympiamanagement.month')%></span>
<%=render :partial=>'select',:locals=>{:name=>'[sign_up_setting][end_day]',:id=>'end_day',:value=>@sign_up_setting['end_day'],:unit=>'',:range=>[1,31],:extra_class=>'lleft',:is_add_zero=>true}%>
<span style="float: left;padding: 0.3em;"><%= t('olympiamanagement.day')%></span>
<%=render :partial=>'select',:locals=>{:name=>'[sign_up_setting][end_o_clock]',:id=>'end_o_clock',:value=>@sign_up_setting['end_o_clock'],:unit=>'',:range=>[0,23],:extra_class=>'lleft',:is_add_zero=>true}%>
<span style="float: left;padding: 0.3em;"><%= t('olympiamanagement.o_clock')%></span>
<%=render :partial=>'select',:locals=>{:name=>'[sign_up_setting][end_minute]',:id=>'end_minute',:value=>@sign_up_setting['end_minute'],:unit=>'',:range=>[0,59],:extra_class=>'lleft',:is_add_zero=>true}%>
<span style="float: left;padding: 0.3em;"><%= t('olympiamanagement.minute')%></span>
</li>
</div>
<div class="col_text">
<li class="col" for="default_password"><%= t('olympiamanagement.default_password') %></li>
<li class="col_r" style="margin-right: 0.5em;">
<input name="[sign_up_setting][default_password]" type="text" id="default_password" size="20" class="col_input" <%= @sign_up_setting.default_password.nil? ? nil : "value=#{@sign_up_setting.default_password}"%>>
</li>
<%=render :partial=>'checkbox',:locals=>{:name=>t('olympiamanagement.sign_up_setting_hint'),:params_name=>'[sign_up_setting][set_default_password]',:id=>'set_default_password',:extra_class=>'lleft',:is_checked=>nil}%>
</div>
<div style="clear:both;"></div>
<h4><%= t('olympiamanagement.remark')+"(#{t('olympiamanagement.print_registration_form')})" %></h4>
<ul class="nav nav-pills language-nav">
<% @site_locales.each_with_index do |locale,i|%>
<li <%= (i == 0) ? "class=active" : "" %>>
<a href=".<%=locale.to_s%>" data-toggle="tab"><%=t(locale.to_s)%></a>
</li>
<% end %>
</ul>
<div class="tab-content language-area">
<% @site_locales.each_with_index do |locale,i|%>
<div class="tab-pane fade <%=locale.to_s%> <%= (i == 0) ? "active in": "" %>">
<div class="control-group input-content">
<textarea id="remark_field_<%=locale.to_s%>" name="[sign_up_setting][remark_field][<%=locale.to_s%>]">
<%=@sign_up_setting.remark_field[locale] %>
</textarea>
</div>
</div>
<% end %>
</div>
<h4><%= t('olympiamanagement.registration_instructions') %></h4>
<ul class="nav nav-pills language-nav">
<% @site_locales.each_with_index do |locale,i|%>
<li <%= (i == 0) ? "class=active" : "" %>>
<a href=".<%=locale.to_s%>" data-toggle="tab"><%=t(locale.to_s)%></a>
</li>
<% end %>
</ul>
<div class="tab-content language-area">
<% @site_locales.each_with_index do |locale,i|%>
<div class="tab-pane fade <%=locale.to_s%> <%= (i == 0) ? "active in": "" %>">
<div class="control-group input-content">
<textarea id="registration_instructions_<%=locale.to_s%>" name="[sign_up_setting][registration_instructions][<%=locale.to_s%>]">
<%=@sign_up_setting.registration_instructions[locale] %>
</textarea>
</div>
</div>
<% end %>
</div>
<div style="clear:both;"></div>
<input type="submit" name="Submit" value="<%=t('olympiamanagement.confirm')%>">
<input type="reset" name="Submit" value="<%=t('olympiamanagement.cancel')%>">
<% end %>
</fieldset>

View File

@ -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
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

View File

@ -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: 下一頁
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: 列印報名表

View File

@ -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