fix bugs in version 1

This commit is contained in:
BOHUNG 2020-02-17 16:09:48 +08:00
parent 27397156d2
commit 660716e8c7
3 changed files with 32 additions and 12 deletions

View File

@ -18,6 +18,25 @@ $(document).ready(function(){
window.location.search="";
});
});
$('.class_setting_block input').keypress(function(event){
var keycode = event['keyCode'] || event['which'];
if(Number(keycode) == 13){
var class_number_range = [];
class_number_range.push(Number($('.class_setting_block .col_input[name="MinClass"]').val()));
class_number_range.push(Number($('.class_setting_block .col_input[name="MaxClass"]').val()));
var enrollment_available = $('.class_setting_block .col_input#Person').val();
class_number_range.sort();
var params_array = (window.location.search.substring(1)=="") ? [] : window.location.search.substring(1).split('&').map(function(el){return el.split('=')});
var params = {};
params_array.forEach(function(el){params[el[0]] = el[1]});
var params_to_send = {'type':'class_setting','class_number_range':class_number_range,'enrollment_available':enrollment_available};
params_to_send = Object.assign(params,params_to_send);
var post_data = $.post('/admin/olympiamanagements/update_school_data',params_to_send);
post_data.done(function(){
window.location.search="";
});
};
});
$('.fieldset_block input[type="submit"]').click(function(){
$el = $('.fieldset_block li.required');
for(var i = 0; i< $el.length ; i++){

View File

@ -390,6 +390,7 @@ class Admin::OlympiamanagementsController < OrbitAdminController
@olympia_school_data_field = OlympiaSchoolDataFields.find(params[:school_id]) rescue nil
redirect_to :back if @olympia_school_data_field.nil?
@required_fields = [:school_contact_person_name,:department_job_title,:office_tel_number,:fax,:mobile_number,:email]
@error_msg = []
@flag = true
@required_fields.each do |field|
if @olympia_school_data_field[field].to_s.blank?
@ -399,7 +400,7 @@ class Admin::OlympiamanagementsController < OrbitAdminController
end
if !@flag
I18n.t('olympiamanagement.please_set_school_connect_data')
@error_msg << "<p><a href=#{school_connection_data_olympiamanagements_path}>#{I18n.t('olympiamanagement.please_set_school_connect_data')}</a></p>"
@error_msg << "<p><a href=#{school_connection_data_olympiamanagements_path}>#{I18n.t('olympiamanagement.please_set_school_connect_data')}</a></p>".html_safe
render 'error_message'
else
@student_data_field = StudentDataField.first

View File

@ -133,7 +133,7 @@ class OlympiamanagementsController < ApplicationController
elsif @instructions_pages.length != 1
@instructions_pages.slice(1,@instructions_pages.length).each{|page| page.destroy}
end
@school = OlympiaSchoolDataFields.where(:account_number=>@@session[:olympia_login_id],:approved=>true).first rescue nil
@school = OlympiaSchoolDataFields.where(:account_number=>@@session[:olympia_login_id],:approved=>true,:sign_up_setting_id=>@sign_up_setting.id).first rescue nil
if @school.nil?
@page_content = render_to_string(:formats=> [:html] ,:partial=>'login',:locals=>{:@error=>@error})
else
@ -150,7 +150,7 @@ class OlympiamanagementsController < ApplicationController
{'fax'=>{'type'=>'String','size'=>'20','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true"}},
{'mobile_number'=>{'type'=>'String','size'=>'20','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true"}},
{'email'=>{'type'=>'String','size'=>'40','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true"}}]
@olympia_school_data_field = OlympiaSchoolDataFields.where(:account_number=>@@session[:olympia_login_id]).first
@olympia_school_data_field = OlympiaSchoolDataFields.where(:account_number=>@@session[:olympia_login_id],:approved=>true,:sign_up_setting_id=>@sign_up_setting.id).first
@page_content = @breadcumb
@page_content += render_to_string(:formats=> [:html] ,:partial=>'edit_school_data_for_index.html',:locals=>{:@school_data_fields=>@school_data_fields,:@olympia_school_data_field=>@olympia_school_data_field,:@@session=>@@session}) #form_for not work for rendering in Pagescontroller => edit to form
end
@ -186,7 +186,7 @@ class OlympiamanagementsController < ApplicationController
{'fax'=>{'type'=>'String','size'=>'20','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true"}},
{'mobile_number'=>{'type'=>'String','size'=>'20','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true"}},
{'email'=>{'type'=>'String','size'=>'40','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true"}}]
@olympia_school_data_field = OlympiaSchoolDataFields.where(:account_number=>session[:olympia_login_id]).first
@olympia_school_data_field = OlympiaSchoolDataFields.where(:account_number=>session[:olympia_login_id],:sign_up_setting_id=>@sign_up_setting.id,:approved=>true).first
@page_content = render_to_string(:formats=> [:html] ,:partial=>'edit_school_data.html',:locals=>{:@school_data_fields=>@school_data_fields,:@olympia_school_data_field=>@olympia_school_data_field})
render_contents_in_index_page(@breadcumb+@page_content)#redirect_to :back
else
@ -206,7 +206,7 @@ class OlympiamanagementsController < ApplicationController
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
@olympia_school_data_field = OlympiaSchoolDataFields.where(:account_number=>session[:olympia_login_id],:sign_up_setting_id=>@sign_up_setting.id,:approved=>true).first
redirect_to :back if @olympia_school_data_field.nil?
@required_fields = [:school_contact_person_name,:department_job_title,:office_tel_number,:fax,:mobile_number,:email]
@flag = true
@ -230,7 +230,7 @@ class OlympiamanagementsController < ApplicationController
def sign_up_student_data_list
page_num = params[:page] || 1
@field_infos = StudentDataField.first.student_data_fields
@olympia_school_data_fields_id = OlympiaSchoolDataFields.where(:account_number=>session[:olympia_login_id],:sign_up_setting_id=>@sign_up_setting.id).first.id
@olympia_school_data_fields_id = OlympiaSchoolDataFields.where(:account_number=>session[:olympia_login_id],:sign_up_setting_id=>@sign_up_setting.id,:approved=>true).first.id
@sign_up_setting_id = @sign_up_setting.id
@student_fields = OlympiaStudentDataField.where(:olympia_school_data_fields_id=>@olympia_school_data_fields_id,:sign_up_setting_id=>@sign_up_setting_id).asc(:id).page(page_num).per(10)
@page_content = render_to_string(:formats=> [:html] ,:partial=>'student_data_list.html',:locals=>{:@student_fields=>(@student_fields rescue [])}).html_safe
@ -252,7 +252,7 @@ class OlympiamanagementsController < ApplicationController
elsif params[:new_password].to_s.blank?
@@error = "new_password_empty"
else
@olympia_school_data_field = OlympiaSchoolDataFields.where(:account_number=>session[:olympia_login_id]).first
@olympia_school_data_field = OlympiaSchoolDataFields.where(:account_number=>session[:olympia_login_id],:sign_up_setting_id=>@sign_up_setting.id,:approved=>true).first
@olympia_school_data_field.password = params[:new_password]
@olympia_school_data_field.save
end
@ -273,12 +273,12 @@ class OlympiamanagementsController < ApplicationController
end
@remark_texts = @remark_texts.html_safe
@record_form_title = ((I18n.locale.to_s == "zh_tw") ? "#{@sign_up_setting.end_year}年國中科學奧林匹亞競賽國家代表隊選拔初選報名表" : "#{Time.now.year} Year International Junior Science Olympiad National Team Selection First Stage Sign up Form")
@school_data = OlympiaSchoolDataFields.where(:account_number=>session[:olympia_login_id]).first
@school_data = OlympiaSchoolDataFields.where(:account_number=>session[:olympia_login_id],:sign_up_setting_id=>@sign_up_setting.id,:approved=>true).first
@record_fields = [['school_name','school_code'],['school_address'],['class_number','enrollment_limited'],
['office_tel_number','fax'],['mobile_number','email'],['principal_signature','dean_signature']]
@student_fields = ['serial_number','StudentName','StudentSex','StudentClass','StudentIDNO','birth_date','StudentArea','StudentIdentity']
@field_infos = StudentDataField.first.student_data_fields
@olympia_school_data_fields_id = OlympiaSchoolDataFields.where(:account_number=>session[:olympia_login_id],:sign_up_setting_id=>@sign_up_setting.id).first.id
@olympia_school_data_fields_id = OlympiaSchoolDataFields.where(:account_number=>session[:olympia_login_id],:sign_up_setting_id=>@sign_up_setting.id,:approved=>true).first.id
@sign_up_setting_id = @sign_up_setting.id
@student_data_list = OlympiaStudentDataField.where(:olympia_school_data_fields_id=>@olympia_school_data_fields_id,:sign_up_setting_id=>@sign_up_setting_id)
@head = render_to_string(:formats=>[:html],:file=>"#{Rails.root}/app/templates/#{@key}/partial/_head.html")
@ -302,7 +302,7 @@ class OlympiamanagementsController < ApplicationController
}
end
def download_school_code
@OlympiaSchoolDataFields = OlympiaSchoolDataFields.all.asc(:id)
@OlympiaSchoolDataFields = OlympiaSchoolDataFields.where(:sign_up_setting_id=>@sign_up_setting.id).asc(:id)
dir_path = 'tmp/olympiamanagement/'
#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
@ -644,7 +644,7 @@ class OlympiamanagementsController < ApplicationController
end
def update_school_data
@readonly_fields = ['account_number','password','school_name','school_code','school_address','class_number','enrollment_limited']
@olympia_school_data_field = OlympiaSchoolDataFields.where(:account_number=>params[:olympia_user_name]).first
@olympia_school_data_field = OlympiaSchoolDataFields.where(:account_number=>params[:olympia_user_name],:sign_up_setting_id=>@sign_up_setting.id,:approved=>true).first
redirect_to :back if @olympia_school_data_field.nil?
params['add_school_data'].keys.each do |field|
if !@readonly_fields.include?(field)
@ -680,7 +680,7 @@ class OlympiamanagementsController < ApplicationController
if @student_params['StudentIdentity'] == '1' && (@student_params['olympia_student_images']['0']['StudentFile'].nil? rescue true)
@error_msg << I18n.t('olympiamanagement.StudentFile')
end
@olympia_school_data_field = OlympiaSchoolDataFields.where(:account_number=>session[:olympia_login_id],:sign_up_setting_id=>@sign_up_setting.id).first
@olympia_school_data_field = OlympiaSchoolDataFields.where(:account_number=>session[:olympia_login_id],:sign_up_setting_id=>@sign_up_setting.id,:approved=>true).first
@enrollment_limited = ((@olympia_school_data_field.enrollment_limited.nil? || @olympia_school_data_field.enrollment_limited == 0) ? ClassSettingFields.all.select{|class_setting_field| class_setting_field.class_number_range[0] <= @olympia_school_data_field.class_number.to_i && class_setting_field.class_number_range[1] >= @olympia_school_data_field.class_number.to_i}.first.enrollment_available.to_i : @olympia_school_data_field.enrollment_limited.to_i)
@student_fields = OlympiaStudentDataField.where(:olympia_school_data_fields_id=>@olympia_school_data_field.id,:sign_up_setting_id=>@sign_up_setting.id)
if @student_fields.length > @enrollment_limited