fix bugs in version 1

This commit is contained in:
BOHUNG 2020-02-20 17:49:29 +08:00
parent d242ef087e
commit 91c018dabf
12 changed files with 77 additions and 18 deletions

View File

@ -139,10 +139,10 @@ $(document).ready(function(){
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');
try{CKEDITOR.replaceAll()}catch(e){console.log(e)};
if($('#StudentIdentity').val() != '1')
if($('#StudentIdentity').val() != '1' && $('#StudentIdentity').val() != '2')
$('#StudentFile').removeClass('required');
$('#StudentIdentity').click(function(){
if(this.value != '1'){
if(this.value != '1' && this.value != '2'){
$('#StudentFile').removeClass('required');
}else{
$('#StudentFile').addClass('required');
@ -157,6 +157,18 @@ $(document).ready(function(){
$el.siblings('.col_r').find('.errMsg').remove();
};
});
$('.fieldset_block input').on('input',function(){
if($(this).val() != ''){
$(this).parent().siblings('.col').removeClass('errFld');
$(this).siblings('.errMsg').remove();
};
});
$('.fieldset_block select').on('input',function(){
if($(this).val() != ''){
$(this).parent().siblings('.col').removeClass('errFld');
$(this).siblings('.errMsg').remove();
};
});
$('#StudentFile').on('input',function(){
if($(this).val() != ''){
$('[for="StudentFile"]').removeClass('errFld');

View File

@ -27,6 +27,7 @@ class Admin::OlympiamanagementsController < OrbitAdminController
else
@error_msg << ((I18n.locale.to_s == "zh_tw") ? "尚無學生資料" : "There is no student data yet.")
end
@msg_title = ((I18n.locale.to_s == "zh_tw") ? "提示訊息" : "Message")
render 'error_message'
elsif params[:type] == "active"
@sign_up_setting = SignUpSetting.find(params[:id]) rescue nil
@ -55,6 +56,26 @@ class Admin::OlympiamanagementsController < OrbitAdminController
@error_msg << ((I18n.locale.to_s == "zh_tw") ? "查無資料" : "Not found.")
render 'error_message'
end
elsif params[:type] == "active_all_school"
@sign_up_setting = SignUpSetting.find(params[:id]) rescue nil
if !@sign_up_setting.nil?
OlympiaSchoolDataFields.where(:sign_up_setting_id=>@sign_up_setting.id.to_s).each{|school| school.update(:approved=>true) }
redirect_to :back
else
@error_msg = []
@error_msg << ((I18n.locale.to_s == "zh_tw") ? "查無資料" : "Not found.")
render 'error_message'
end
elsif params[:type] == "disable_all_school"
@sign_up_setting = SignUpSetting.find(params[:id]) rescue nil
if !@sign_up_setting.nil?
OlympiaSchoolDataFields.where(:sign_up_setting_id=>@sign_up_setting.id.to_s).each{|school| school.update(:approved=>false) }
redirect_to :back
else
@error_msg = []
@error_msg << ((I18n.locale.to_s == "zh_tw") ? "查無資料" : "Not found.")
render 'error_message'
end
else
render :html => '404' and return
end
@ -140,6 +161,10 @@ class Admin::OlympiamanagementsController < OrbitAdminController
end
elsif params[:type] == 'sign_up_setting'
@sign_up_params = params.require(:sign_up_setting).permit!
StudentDataField.destroy_all
SchoolDataFields.destroy_all
StudentDataField.create
SchoolDataFields.create
if params[:new_sign_up] == "true"
#render :html => @sign_up_params and return
SignUpSetting.create(@sign_up_params)
@ -432,8 +457,8 @@ class Admin::OlympiamanagementsController < OrbitAdminController
@error_msg << @id_error_msg
end
@olympia_student_data = OlympiaStudentDataField.find(params[:id]) rescue nil
if @student_params['StudentIdentity'] == '1' && (@student_params['olympia_student_images']['0']['StudentFile'].nil? rescue true)
if @olympia_student_data.olympia_student_images.empty? || !@olympia_student_data.olympia_student_images.first.student_file.file.present?
if (@student_params['StudentIdentity'] == '1' || @student_params['StudentIdentity'] == '2') && (@student_params['olympia_student_images']['0']['StudentFile'].nil? rescue true)
if(@olympia_student_data.olympia_student_images.empty? || !@olympia_student_data.olympia_student_images.first.student_file.file.present? rescue true)
@error_msg << I18n.t('olympiamanagement.StudentFile')
end
end
@ -441,7 +466,7 @@ class Admin::OlympiamanagementsController < OrbitAdminController
@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 rescue ClassSettingFields.all.desc(:enrollment_available).first.enrollment_available.to_i) : @olympia_school_data_field.enrollment_limited.to_i)
@student_fields = OlympiaStudentDataField.where(:olympia_school_data_fields_id=>params[:school_id],:sign_up_setting_id=>@sign_up_setting_id)
extra_num = 0
extra_num = 1 if(@olympia_student_data.nil? && @student_params['StudentIdentity'] != '1')
extra_num = 1 if(@olympia_student_data.nil? && @student_params['StudentIdentity'] == '0')
if (@student_fields.length + extra_num) > @enrollment_limited
@error_msg << ((I18n.locale.to_s == "zh_tw") ? ("一般身分報名人數上限為 #{@enrollment_limited} 人。") : ("Enrollment limited of General identity is #{@enrollment_limited} people."))
@error_msg << I18n.t('olympiamanagement.already_exceed_enrollment_limited')

View File

@ -677,8 +677,8 @@ class OlympiamanagementsController < ApplicationController
if @id_error_msg.length != 0
@error_msg << I18n.t('olympiamanagement.id_number_error')
end
if @student_params['StudentIdentity'] == '1' && (@student_params['olympia_student_images']['0']['student_file'].nil? rescue true)
if @olympia_student_data.olympia_student_images.empty? || !@olympia_student_data.olympia_student_images.first.student_file.file.present?
if (@student_params['StudentIdentity'] == '1' || @student_params['StudentIdentity'] == '2') && (@student_params['olympia_student_images']['0']['student_file'].nil? rescue true)
if (@olympia_student_data.olympia_student_images.empty? || !@olympia_student_data.olympia_student_images.first.student_file.file.present? rescue true)
@error_msg << I18n.t('olympiamanagement.StudentFile')
end
end
@ -687,7 +687,7 @@ class OlympiamanagementsController < ApplicationController
@student_fields = OlympiaStudentDataField.where(:olympia_school_data_fields_id=>@olympia_school_data_field.id,:sign_up_setting_id=>@sign_up_setting.id,:StudentIdentity=>'0')
@olympia_student_data = OlympiaStudentDataField.find(params[:id]) rescue nil
extra_num = 0
extra_num = 1 if(@olympia_student_data.nil? && @student_params['StudentIdentity'] != '1')
extra_num = 1 if(@olympia_student_data.nil? && @student_params['StudentIdentity'] == '0')
if (@student_fields.length + extra_num) > @enrollment_limited
@error_msg << ((I18n.locale.to_s == "zh_tw") ? ("一般身分報名人數上限為 #{@enrollment_limited} 人。") : ("Enrollment limited of General identity is #{@enrollment_limited} people."))
@error_msg << I18n.t('olympiamanagement.already_exceed_enrollment_limited')

View File

@ -6,7 +6,7 @@ class StudentDataField
# encoding: utf-8
include OrbitTag::Taggable
include OrbitCategory::Categorizable
field :student_data_fields , type: Array , default: [{'StudentIdentity'=>{'type'=>'select_string','hint'=>{'zh_tw'=>'','en'=>''},'values'=>{'zh_tw'=>['一般身分','科展得獎科學班'],'en'=>['General identity','Science Fair Winner']},'required'=>"true"}},
field :student_data_fields , type: Array , default: [{'StudentIdentity'=>{'type'=>'select_string','hint'=>{'zh_tw'=>'','en'=>''},'values'=>{'zh_tw'=>['一般身分','科展得獎者','科學班'],'en'=>['General identity','Science Fair Winner','Science Class']},'required'=>"true"}},
{'StudentName'=>{'type'=>'String','size'=>'20','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true"}},
{'StudentSex'=>{'type'=>'radio','size'=>'20','choices'=>['M','F'],'values'=>{'zh_tw'=>['男','女'],'en'=>['Male','Female']},'hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true"}},
{'StudentIDNO'=>{'type'=>'String','size'=>'20','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true"}},

View File

@ -33,7 +33,7 @@
<%=t('olympiamanagement.a_d_')%>
<% @please_choice = (I18n.locale.to_s == "zh_tw") ? "請選擇" : "Please select." %>
<select name="<%="[add_student_data][#{field.keys[0]}]"%>" id="<%=field.keys[0]%>" class="required" value="<%= @olympia_student_data[field.keys[0]] %>" style="width: auto;"><option value=""><%=@please_choice%></option>
<% for @num in (Time.now.year.to_i-10) .. (Time.now.year.to_i+10) %>
<% for @num in (Time.now.year.to_i-15) .. (Time.now.year.to_i) %>
<%= ('<option value="' + @num.to_s + '">' + @num.to_s + (field.values[0][:unit][I18n.locale.to_s] rescue "") + '</option>').html_safe %>
<% end %>
</select>

View File

@ -33,7 +33,7 @@
<%=t('olympiamanagement.a_d_')%>
<% @please_choice = (I18n.locale.to_s == "zh_tw") ? "請選擇" : "Please select." %>
<select name="<%="[add_student_data][#{field.keys[0]}]"%>" id="<%=field.keys[0]%>" class="required" value="<%= @olympia_student_data[field.keys[0]] %>" style="width: auto;"><option value=""><%=@please_choice%></option>
<% for @num in (Time.now.year.to_i-15) .. (Time.now.year.to_i+10) %>
<% for @num in (Time.now.year.to_i-15) .. (Time.now.year.to_i) %>
<%= ('<option value="' + @num.to_s + '">' + @num.to_s + (field.values[0][:unit][I18n.locale.to_s] rescue "") + '</option>').html_safe %>
<% end %>
</select>

View File

@ -1,9 +1,15 @@
<h2><%= (I18n.locale.to_s == "zh_tw") ? '錯誤提示' : 'Error message' %></h2>
<h2>
<%if(@msg_title.nil? rescue true)%>
<%= (I18n.locale.to_s == "zh_tw") ? '錯誤提示' : 'Error message' %>
<% else %>
<%= @msg_title %>
<% end %>
</h2>
<ul>
<% @error_msg.each do |a| %>
<li><%= a %></li>
<li class="error_msg"><%= a %></li>
<% end %>
@ -11,3 +17,8 @@
<input name="goback" type="button" onclick="window.history.go(-1);" onkeypress="window.history.go(-1);" value="<%=t('back')%>">
<style type="text/css">
li.error_msg{
font-size: 1.5em;
}
</style>

View File

@ -31,6 +31,8 @@
<% end %>
</td>
<td>
<a class="btn" href='<%= admin_olympiamanagements_update_sign_up_data_path + "?type=active_all_school&id=#{sign_up_setting.id}"%>'><%=t('olympiamanagement.active_all_school')%></a>
<a class="btn" href='<%= admin_olympiamanagements_update_sign_up_data_path + "?type=disable_all_school&id=#{sign_up_setting.id}"%>'><%=t('olympiamanagement.disable_all_school')%></a>
<% if !sign_up_setting.active%>
<a class="btn" href='<%= admin_olympiamanagements_update_sign_up_data_path + "?type=active&id=#{sign_up_setting.id}"%>'><%=t('olympiamanagement.active')%></a>
<% end %>

View File

@ -32,7 +32,7 @@
<%=t('olympiamanagement.a_d_')%>
<% @please_choice = (I18n.locale.to_s == "zh_tw") ? "請選擇" : "Please select." %>
<select name="<%="[add_student_data][#{field.keys[0]}]"%>" id="<%=field.keys[0]%>" class="required" value="<%= @olympia_student_data[field.keys[0]] %>" style="width: auto;"><option value=""><%=@please_choice%></option>
<% for @num in (Time.now.year.to_i-15) .. (Time.now.year.to_i+10) %>
<% for @num in (Time.now.year.to_i-15) .. (Time.now.year.to_i) %>
<%= ('<option value="' + @num.to_s + '">' + @num.to_s + (field.values[0][:unit][I18n.locale.to_s] rescue "") + '</option>').html_safe %>
<% end %>
</select>

View File

@ -1,9 +1,14 @@
<h2 align="center"><img style="height: 1em;" alt="<%= t('olympiamanagement.error_msg')%>" src="/assets/warning.gif"><%= t('olympiamanagement.error_msg')%></h2>
<h2 align="center"><img style="height: 1em;" alt="<%= t('olympiamanagement.error_msg')%>" src="/assets/warning.gif"><%= ((@msg_title.nil? rescue true) ? t('olympiamanagement.error_msg') : @msg_title )%></h2>
<ul align="center">
<% @error_msg.each do |a| %>
<li style="width: fit-content;margin: auto;"><%= a %></li>
<li style="width: fit-content;margin: auto;" class="error_msg"><%= a %></li>
<% end %>
</ul>
<p align="center">
<input name="goback" type="button" onclick="window.history.go(-1);" onkeypress="window.history.go(-1);" value="<%=t('back')%>">
</p>
<style type="text/css">
li.error_msg{
font-size: 1.5em;
}
</style>

View File

@ -2,6 +2,8 @@ en:
module_name:
olympiamanagement: Olympia Competition Management
olympiamanagement:
active_all_school: Active all school
disable_all_school: Disable all school
school_number: School number
new_sign_up: Create new Sign up
view: View

View File

@ -2,6 +2,8 @@ zh_tw:
module_name:
olympiamanagement: 奧林匹亞競賽 Management
olympiamanagement:
active_all_school: 啟用全部學校
disable_all_school: 停用全部學校
school_number: 學校數量
new_sign_up: 建立新的報名
view: 查看