diff --git a/app/assets/javascripts/olympiamanagement.js b/app/assets/javascripts/olympiamanagement.js index b59d1f2..4c727d9 100644 --- a/app/assets/javascripts/olympiamanagement.js +++ b/app/assets/javascripts/olympiamanagement.js @@ -114,6 +114,10 @@ $(document).ready(function(){ $('.fieldset_block input[type="submit"]').click(function(){ $el = $('.fieldset_block li.required'); for(var i = 0; i< $el.length ; i++){ + if($el.eq(i).attr('for') == "StudentFile"){ + if($el.eq(i).siblings('.col_r').find('img').length != 0){ + continue; + }}; 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) diff --git a/app/controllers/admin/olympiamanagements_controller.rb b/app/controllers/admin/olympiamanagements_controller.rb index 596a02a..a0b4880 100644 --- a/app/controllers/admin/olympiamanagements_controller.rb +++ b/app/controllers/admin/olympiamanagements_controller.rb @@ -206,6 +206,11 @@ class Admin::OlympiamanagementsController < OrbitAdminController @olympia_school_data_field = OlympiaSchoolDataFields.where(:school_code=> row[@row_index_hash["school_code"]],:sign_up_setting_id=>@sign_up_setting.id).first @olympia_school_data_field = OlympiaSchoolDataFields.new() if @olympia_school_data_field.nil? @update_attributes = @row_index_hash.map{|key,index| [key,row[index]]}.to_h + if !@update_attributes["class_number"].nil? + class_number = @update_attributes["class_number"].to_i + enrollment_limited = (ClassSettingFields.all.select{|class_setting_field| class_setting_field.class_number_range[0] <= class_number && class_setting_field.class_number_range[1] >= class_number}.first.enrollment_available.to_s rescue ClassSettingFields.all.desc(:enrollment_available).first.enrollment_available.to_s) + @update_attributes.merge!({:enrollment_limited=>enrollment_limited}) + end @olympia_school_data_field.update_attributes(@update_attributes) end end @@ -426,13 +431,15 @@ class Admin::OlympiamanagementsController < OrbitAdminController if @id_error_msg.length != 0 @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) - @error_msg << I18n.t('olympiamanagement.StudentFile') + if @olympia_student_data.olympia_student_images.empty? || !@olympia_student_data.olympia_student_images.first.student_file.file.present? + @error_msg << I18n.t('olympiamanagement.StudentFile') + end end @olympia_school_data_field = OlympiaSchoolDataFields.find(params[:school_id]) rescue nil - @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) + @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) - @olympia_student_data = OlympiaStudentDataField.find(params[:id]) rescue nil extra_num = 0 extra_num = 1 if(@olympia_student_data.nil? && @student_params['StudentIdentity'] != '1') if (@student_fields.length + extra_num) > @enrollment_limited diff --git a/app/controllers/olympiamanagements_controller.rb b/app/controllers/olympiamanagements_controller.rb index f35a83b..e75ed70 100644 --- a/app/controllers/olympiamanagements_controller.rb +++ b/app/controllers/olympiamanagements_controller.rb @@ -678,10 +678,12 @@ class OlympiamanagementsController < ApplicationController @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) - @error_msg << I18n.t('olympiamanagement.StudentFile') + if @olympia_student_data.olympia_student_images.empty? || !@olympia_student_data.olympia_student_images.first.student_file.file.present? + @error_msg << I18n.t('olympiamanagement.StudentFile') + end end @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) + @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=>@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 diff --git a/app/models/olympia_school_data_fields.rb b/app/models/olympia_school_data_fields.rb index 005f7a0..c7cca64 100644 --- a/app/models/olympia_school_data_fields.rb +++ b/app/models/olympia_school_data_fields.rb @@ -23,10 +23,9 @@ class OlympiaSchoolDataFields after_destroy do |record| OlympiaStudentDataField.where(:olympia_school_data_fields_id => record.id).destroy_all end - after_save do |record| + before_save do |record| if record.account_number.blank? && !record.school_code.blank? record.account_number = record.school_code - record.save end end after_initialize do diff --git a/app/models/student_data_field.rb b/app/models/student_data_field.rb index 0b635ad..c7aaee2 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']},'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 889b670..70fe4d3 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 @@ -63,6 +63,10 @@ <% end %>
- + <% if @olympia_student_data.new_record? %> + + <% else %> + + <% end %> <% end %> \ No newline at end of file diff --git a/app/views/admin/olympiamanagements/add_student_data.html.erb b/app/views/admin/olympiamanagements/add_student_data.html.erb index 5175af8..54f2d00 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." %> @@ -63,6 +63,10 @@ <% end %> - + <% if @olympia_student_data.new_record? %> + + <% else %> + + <% end %> <% end %> \ No newline at end of file diff --git a/app/views/olympiamanagements/_add_student_data.html.erb b/app/views/olympiamanagements/_add_student_data.html.erb index b5818a4..79c56e3 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." %> @@ -66,6 +66,10 @@ <% end %> - + <% if @olympia_student_data.new_record? %> + + <% else %> + + <% end %> <% end %> \ No newline at end of file diff --git a/app/views/olympiamanagements/_edit_school_data.html.erb b/app/views/olympiamanagements/_edit_school_data.html.erb index 7a478ce..42187f0 100644 --- a/app/views/olympiamanagements/_edit_school_data.html.erb +++ b/app/views/olympiamanagements/_edit_school_data.html.erb @@ -11,7 +11,7 @@ <% @extra_text = ((field.values[0]["required"] == "true")? "*" : "")%>