From 91c018dabf1e8652f01f89863795f8e5b955adb8 Mon Sep 17 00:00:00 2001 From: BOHUNG Date: Thu, 20 Feb 2020 17:49:29 +0800 Subject: [PATCH] fix bugs in version 1 --- app/assets/javascripts/olympiamanagement.js | 16 ++++++++-- .../admin/olympiamanagements_controller.rb | 31 +++++++++++++++++-- .../olympiamanagements_controller.rb | 6 ++-- app/models/student_data_field.rb | 2 +- .../add_sign_up_student_data.html.erb | 2 +- .../add_student_data.html.erb | 2 +- .../olympiamanagements/error_message.html.erb | 17 ++++++++-- .../admin/olympiamanagements/index.html.erb | 2 ++ .../_add_student_data.html.erb | 2 +- .../_import_error_msg.html.erb | 11 +++++-- config/locales/en.yml | 2 ++ config/locales/zh_tw.yml | 2 ++ 12 files changed, 77 insertions(+), 18 deletions(-) diff --git a/app/assets/javascripts/olympiamanagement.js b/app/assets/javascripts/olympiamanagement.js index 4c727d9..d9b007f 100644 --- a/app/assets/javascripts/olympiamanagement.js +++ b/app/assets/javascripts/olympiamanagement.js @@ -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'); diff --git a/app/controllers/admin/olympiamanagements_controller.rb b/app/controllers/admin/olympiamanagements_controller.rb index a0b4880..2669edf 100644 --- a/app/controllers/admin/olympiamanagements_controller.rb +++ b/app/controllers/admin/olympiamanagements_controller.rb @@ -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') diff --git a/app/controllers/olympiamanagements_controller.rb b/app/controllers/olympiamanagements_controller.rb index e75ed70..fcbde15 100644 --- a/app/controllers/olympiamanagements_controller.rb +++ b/app/controllers/olympiamanagements_controller.rb @@ -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') diff --git a/app/models/student_data_field.rb b/app/models/student_data_field.rb index c7aaee2..1d8a4b2 100644 --- a/app/models/student_data_field.rb +++ b/app/models/student_data_field.rb @@ -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"}}, diff --git a/app/views/admin/olympiamanagements/add_sign_up_student_data.html.erb b/app/views/admin/olympiamanagements/add_sign_up_student_data.html.erb index 70fe4d3..8dc1919 100644 --- a/app/views/admin/olympiamanagements/add_sign_up_student_data.html.erb +++ b/app/views/admin/olympiamanagements/add_sign_up_student_data.html.erb @@ -33,7 +33,7 @@ <%=t('olympiamanagement.a_d_')%> <% @please_choice = (I18n.locale.to_s == "zh_tw") ? "請選擇" : "Please select." %> diff --git a/app/views/admin/olympiamanagements/add_student_data.html.erb b/app/views/admin/olympiamanagements/add_student_data.html.erb index 54f2d00..d0525f3 100644 --- a/app/views/admin/olympiamanagements/add_student_data.html.erb +++ b/app/views/admin/olympiamanagements/add_student_data.html.erb @@ -33,7 +33,7 @@ <%=t('olympiamanagement.a_d_')%> <% @please_choice = (I18n.locale.to_s == "zh_tw") ? "請選擇" : "Please select." %> diff --git a/app/views/admin/olympiamanagements/error_message.html.erb b/app/views/admin/olympiamanagements/error_message.html.erb index 78ee3e3..fc91c2c 100644 --- a/app/views/admin/olympiamanagements/error_message.html.erb +++ b/app/views/admin/olympiamanagements/error_message.html.erb @@ -1,13 +1,24 @@ -

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

+

+ <%if(@msg_title.nil? rescue true)%> + <%= (I18n.locale.to_s == "zh_tw") ? '錯誤提示' : 'Error message' %> + <% else %> + <%= @msg_title %> + <% end %> +

- \ No newline at end of file + + \ No newline at end of file diff --git a/app/views/admin/olympiamanagements/index.html.erb b/app/views/admin/olympiamanagements/index.html.erb index ab17ffa..3723b83 100644 --- a/app/views/admin/olympiamanagements/index.html.erb +++ b/app/views/admin/olympiamanagements/index.html.erb @@ -31,6 +31,8 @@ <% end %> + <%=t('olympiamanagement.active_all_school')%> + <%=t('olympiamanagement.disable_all_school')%> <% if !sign_up_setting.active%> <%=t('olympiamanagement.active')%> <% end %> diff --git a/app/views/olympiamanagements/_add_student_data.html.erb b/app/views/olympiamanagements/_add_student_data.html.erb index 79c56e3..421fb57 100644 --- a/app/views/olympiamanagements/_add_student_data.html.erb +++ b/app/views/olympiamanagements/_add_student_data.html.erb @@ -32,7 +32,7 @@ <%=t('olympiamanagement.a_d_')%> <% @please_choice = (I18n.locale.to_s == "zh_tw") ? "請選擇" : "Please select." %> diff --git a/app/views/olympiamanagements/_import_error_msg.html.erb b/app/views/olympiamanagements/_import_error_msg.html.erb index 4abddca..a44ae2f 100644 --- a/app/views/olympiamanagements/_import_error_msg.html.erb +++ b/app/views/olympiamanagements/_import_error_msg.html.erb @@ -1,9 +1,14 @@ -

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

+

<%= t('olympiamanagement.error_msg')%><%= ((@msg_title.nil? rescue true) ? t('olympiamanagement.error_msg') : @msg_title )%>

-

\ No newline at end of file +

+ \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index f1b9716..3f1637f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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 diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index ecb46cb..373b58e 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -2,6 +2,8 @@ zh_tw: module_name: olympiamanagement: 奧林匹亞競賽 Management olympiamanagement: + active_all_school: 啟用全部學校 + disable_all_school: 停用全部學校 school_number: 學校數量 new_sign_up: 建立新的報名 view: 查看