fix bugs in version 1

This commit is contained in:
BOHUNG 2020-02-17 21:52:00 +08:00
parent 660716e8c7
commit 9ec22c3487
6 changed files with 60 additions and 62 deletions

View File

@ -1,13 +1,14 @@
PATH
remote: .
specs:
cancerpredict (0.0.1)
olympiamanagement (0.0.1)
mongoid (= 4.0.0.beta1)
rails (~> 4.1.0.rc2)
GEM
remote: https://rubygems.org/
specs:
rubyXL (~> 3.4.6)
actionmailer (4.1.0.rc2)
actionpack (= 4.1.0.rc2)
actionview (= 4.1.0.rc2)

View File

@ -1,42 +1,4 @@
$(document).ready(function(){
$('.class_setting_block input[type="reset"]').off('click').on('click',function(){
$('.col_input').val('');
});
$('.class_setting_block input[type="submit"]').off('click').on('click',function(){
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="";
});
});
$('.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

@ -143,5 +143,28 @@ $(document).ready(function(){
}else{
$('#StudentFile').addClass('required');
};
$el = $('.fieldset_block li[for="StudentFile"]');
if($el.siblings('.col_r').find('.required').val() == ""){
$el.addClass('errFld');
if($el.siblings('.col_r').find('.errMsg').length == 0)
$el.siblings('.col_r').append('<div id="SchoolName-E" class="errMsg"> '+((I18n.locale == "en") ? 'Required field': '必填欄位')+'</div>');
}else{
$el.removeClass('errFld');
$el.siblings('.col_r').find('.errMsg').remove();
};
});
$('#StudentFile').on('input',function(){
if($(this).val() != ''){
$('[for="StudentFile"]').removeClass('errFld');
$('[for="StudentFile"]').siblings('.col_r').find('.errMsg').remove();
};
});
$('[data-dismiss="fileupload"]').click(function(){
if($('#StudentFile').hasClass('required')){
$el = $('.fieldset_block li[for="StudentFile"]');
$el.addClass('errFld');
if($el.siblings('.col_r').find('.errMsg').length == 0)
$el.siblings('.col_r').append('<div id="SchoolName-E" class="errMsg"> '+((I18n.locale == "en") ? 'Required field': '必填欄位')+'</div>');
};
});
});

View File

@ -66,6 +66,12 @@ class Admin::OlympiamanagementsController < OrbitAdminController
@ClassSettingField.enrollment_available = params[:enrollment_available].to_i
@ClassSettingField.save
render :json => {'success'=>true} and return
elsif params[:type] == 'class_setting_for_form'
@ClassSettingField = (params[:id].nil? ? ClassSettingFields.new : ((ClassSettingFields.find(params[:id]).nil? rescue true) ? ClassSettingFields.new : ClassSettingFields.find(params[:id])))
@ClassSettingField.class_number_range = [params[:MinClass],params[:MaxClass]].map{|str| str.to_i}.sort
@ClassSettingField.enrollment_available = params[:Person].to_i
@ClassSettingField.save
redirect_to admin_olympiamanagements_class_setting_path
elsif params[:type] == 'delete_class_setting'
if !params[:id].to_s.blank?
begin
@ -197,12 +203,10 @@ class Admin::OlympiamanagementsController < OrbitAdminController
flag = 0
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.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?
@row_index_hash.each do |key,index|
@olympia_school_data_field[key] = row[index]
end
@olympia_school_data_field.save
@update_attributes = @row_index_hash.map{|key,index| [key,row[index]]}.to_h
@olympia_school_data_field.update_attributes(@update_attributes)
end
end
return true
@ -428,7 +432,10 @@ class Admin::OlympiamanagementsController < OrbitAdminController
@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)
@student_fields = OlympiaStudentDataField.where(:olympia_school_data_fields_id=>params[:school_id],:sign_up_setting_id=>@sign_up_setting_id)
if @student_fields.length > @enrollment_limited
@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
@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')
end
@ -474,7 +481,7 @@ class Admin::OlympiamanagementsController < OrbitAdminController
end
end
def download_import_file
@OlympiaSchoolDataFields = OlympiaSchoolDataFields.all.asc(:id)
@OlympiaSchoolDataFields = OlympiaSchoolDataFields.where(:sign_up_setting_id=>@sign_up_setting.id).asc(:id)
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

View File

@ -677,13 +677,16 @@ 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']['StudentFile'].nil? rescue true)
if @student_params['StudentIdentity'] == '1' && (@student_params['olympia_student_images']['0']['student_file'].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,: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
@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')
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')
end

View File

@ -2,19 +2,21 @@
<link rel="stylesheet" media="print" type="text/css" href="/assets/admin/olympiamanagement.scss">
<script src="/assets/admin/olympiamanagement.js"></script>
<fieldset class="fieldset_block class_setting_block">
<legend class="fieldset_title"><%=t('olympiamanagement.class_setting')%></legend>
<div class="col_text">
<li class="col" for="MinClass"><%= t('olympiamanagement.class_number')+"(#{t('olympiamanagement.spacing')})"%></li>
<li class="col_r"><input name="MinClass" type="text" id="MinClass" size="5" class="col_input" <%= @ClassSettingField.nil? ? nil : "value=#{@ClassSettingField.class_number_range[0]}"%>></li>
<span style="float:left;">~</span>
<li class="col_r"><input name="MaxClass" type="text" id="MaxClass" size="5" class="col_input" <%= @ClassSettingField.nil? ? nil : "value=#{@ClassSettingField.class_number_range[1]}"%>></li>
</div>
<div class="col_text">
<li class="col" for="Person"><%= t('olympiamanagement.enrollment_available') %></li><li class="col_r"><input name="Person" type="text" id="Person" size="5" class="col_input" <%= @ClassSettingField.nil? ? nil : "value=#{@ClassSettingField.enrollment_available}"%>></li>
</div>
<div style="clear:both;"></div>
<input type="submit" name="Submit" value="<%=t('olympiamanagement.confirm')%>">
<input type="reset" name="Submit" value="<%=t('olympiamanagement.cancel')%>">
<%= form_tag admin_olympiamanagements_update_school_data_path(:type => "class_setting_for_form") do %>
<legend class="fieldset_title"><%=t('olympiamanagement.class_setting')%></legend>
<div class="col_text">
<li class="col" for="MinClass"><%= t('olympiamanagement.class_number')+"(#{t('olympiamanagement.spacing')})"%></li>
<li class="col_r"><input name="MinClass" type="text" id="MinClass" size="5" class="col_input" <%= @ClassSettingField.nil? ? nil : "value=#{@ClassSettingField.class_number_range[0]}"%>></li>
<span style="float:left;">~</span>
<li class="col_r"><input name="MaxClass" type="text" id="MaxClass" size="5" class="col_input" <%= @ClassSettingField.nil? ? nil : "value=#{@ClassSettingField.class_number_range[1]}"%>></li>
</div>
<div class="col_text">
<li class="col" for="Person"><%= t('olympiamanagement.enrollment_available') %></li><li class="col_r"><input name="Person" type="text" id="Person" size="5" class="col_input" <%= @ClassSettingField.nil? ? nil : "value=#{@ClassSettingField.enrollment_available}"%>></li>
</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>
<table cellspacing="0" class="ts_rowsonly" width="100%" id="RSS_Table_page_contest_admin_1">
<thead>