diff --git a/app/controllers/admin/olympiamanagements_controller.rb b/app/controllers/admin/olympiamanagements_controller.rb index c3cea92..05914d7 100644 --- a/app/controllers/admin/olympiamanagements_controller.rb +++ b/app/controllers/admin/olympiamanagements_controller.rb @@ -161,19 +161,26 @@ 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 + # SchoolDataFields.destroy_all + # SchoolDataFields.create if params[:new_sign_up] == "true" #render :html => @sign_up_params and return - SignUpSetting.create(@sign_up_params) + sign_up_setting = SignUpSetting.create(@sign_up_params) + student_data_field = StudentDataField.create(:sign_up_setting_id=>sign_up_setting.id.to_s) + index = student_data_field.student_data_fields.map{|h| h.keys.first}.index('StudentArea') + student_data_field.student_data_fields[index]['StudentArea']['values'] = params[:StudentArea] + student_data_field.save redirect_to :back else @sign_up_setting = SignUpSetting.find(params[:id]) rescue SignUpSetting.where(:active=>true).last if @sign_up_setting.nil? render_404_html else + student_data_field = StudentDataField.where(:sign_up_setting_id=>@sign_up_setting.id.to_s).first + student_data_field = StudentDataField.create(:sign_up_setting_id=>@sign_up_setting.id.to_s) if student_data_field.nil? + index = student_data_field.student_data_fields.map{|h| h.keys.first}.index('StudentArea') + student_data_field.student_data_fields[index]['StudentArea']['values'] = params[:StudentArea] + student_data_field.save @sign_up_setting.update_attributes(@sign_up_params) redirect_to :back end @@ -303,6 +310,8 @@ class Admin::OlympiamanagementsController < OrbitAdminController @site_locales = Site.first.in_use_locales @site_locales.delete(I18n.locale) @site_locales.insert(0,I18n.locale) + @student_data_field = StudentDataField.where(:sign_up_setting_id=>@sign_up_setting.id).first + @student_data_field = StudentDataField.create(:sign_up_setting_id=>@sign_up_setting.id) if @student_data_field.nil? end def export_school_connection_data @OlympiaSchoolDataFields = OlympiaSchoolDataFields.where(:sign_up_setting_id=>@sign_up_setting.id).asc(:id) @@ -320,7 +329,9 @@ class Admin::OlympiamanagementsController < OrbitAdminController end def sign_up_student_data_list page_num = params[:page] || 1 - @field_infos = StudentDataField.first.student_data_fields + @student_data_field = StudentDataField.where(:sign_up_setting_id=>@sign_up_setting.id).first + @student_data_field = StudentDataField.create(:sign_up_setting_id=>@sign_up_setting.id) if @student_data_field.nil? + @field_infos = @student_data_field.student_data_fields @sign_up_setting_id = @sign_up_setting.id @student_fields = OlympiaStudentDataField.where(:olympia_school_data_fields_id=>params[:olympia_school_id],:sign_up_setting_id=>@sign_up_setting_id).asc(:id).page(page_num).per(10) end @@ -329,7 +340,9 @@ class Admin::OlympiamanagementsController < OrbitAdminController 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 - @field_infos = (StudentDataField.first || StudentDataField.new).student_data_fields + @student_data_field = StudentDataField.where(:sign_up_setting_id=>@sign_up_setting.id).first + @student_data_field = StudentDataField.create(:sign_up_setting_id=>@sign_up_setting.id) if @student_data_field.nil? + @field_infos = @student_data_field.student_data_fields @student_data_list = [] @fields = [ "school_code", "school_name" , "StudentName" ,"StudentSex","StudentIDNO","birth_date","StudentClass","StudentPhone","StudentCode","StudentAddress","StudentArea","StudentIdentity"] @student_data_fields.each do |field| @@ -426,27 +439,17 @@ class Admin::OlympiamanagementsController < OrbitAdminController 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? - @flag = false - break - end - end - if !@flag - I18n.t('olympiamanagement.please_set_school_connect_data') - @error_msg << "

#{I18n.t('olympiamanagement.please_set_school_connect_data')}

".html_safe - render 'error_message' - else - @student_data_field = StudentDataField.first - @olympia_student_data = (OlympiaStudentDataField.find(params[:id]) rescue OlympiaStudentDataField.new) - end + @student_data_field = StudentDataField.where(:sign_up_setting_id=>@sign_up_setting.id).first + @student_data_field = StudentDataField.create(:sign_up_setting_id=>@sign_up_setting.id) if @student_data_field.nil? + @olympia_student_data = (OlympiaStudentDataField.find(params[:id]) rescue OlympiaStudentDataField.new) end def update_student_data if params[:type] == 'add_student_data' @error_msg = [] @student_params = params.require(:add_student_data).permit! - @all_fields_name = (StudentDataField.first || StudentDataField.new).student_data_fields.map{|hash| hash.keys[0]} + @student_data_field = StudentDataField.where(:sign_up_setting_id=>@sign_up_setting.id).first + @student_data_field = StudentDataField.create(:sign_up_setting_id=>@sign_up_setting.id) if @student_data_field.nil? + @all_fields_name = @student_data_field.student_data_fields.map{|hash| hash.keys[0]} if @student_params.select{|key,value| !value.to_s.blank?}.count < @all_fields_name.slice(0,@all_fields_name.count-1).count @error_msg << "缺少#{@all_fields_name.slice(0,@all_fields_name.count-1).count-@student_params.select{|key,value| !value.to_s.blank?}.count}個欄位值" end diff --git a/app/controllers/olympiamanagements_controller.rb b/app/controllers/olympiamanagements_controller.rb index 6b28e45..bd99584 100644 --- a/app/controllers/olympiamanagements_controller.rb +++ b/app/controllers/olympiamanagements_controller.rb @@ -227,7 +227,8 @@ class OlympiamanagementsController < ApplicationController I18n.t('olympiamanagement.please_set_school_connect_data') render_contents_in_index_page(@breadcumb+"

#{I18n.t('olympiamanagement.please_set_school_connect_data')}

".html_safe) else - @student_data_field = StudentDataField.first + @student_data_field = StudentDataField.where(:sign_up_setting_id=>@sign_up_setting.id).first + @student_data_field = StudentDataField.create(:sign_up_setting_id=>@sign_up_setting.id) if @student_data_field.nil? @olympia_student_data = (OlympiaStudentDataField.find(params[:id]) rescue OlympiaStudentDataField.new) @page_content = render_to_string(:formats=> [:html] ,:partial=>'add_student_data.html',:locals=>{:@error=>(@@error rescue nil),:@student_data_field=>@student_data_field,:@olympia_student_data=>@olympia_student_data}) render_contents_in_index_page(@breadcumb+@page_content.html_safe) @@ -236,7 +237,9 @@ class OlympiamanagementsController < ApplicationController end def sign_up_student_data_list page_num = params[:page] || 1 - @field_infos = StudentDataField.first.student_data_fields + @student_data_field = StudentDataField.where(:sign_up_setting_id=>@sign_up_setting.id).first + @student_data_field = StudentDataField.create(:sign_up_setting_id=>@sign_up_setting.id) if @student_data_field.nil? + @field_infos = @student_data_field.student_data_fields @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) @@ -284,7 +287,9 @@ class OlympiamanagementsController < ApplicationController @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 + @student_data_field = StudentDataField.where(:sign_up_setting_id=>@sign_up_setting.id).first + @student_data_field = StudentDataField.create(:sign_up_setting_id=>@sign_up_setting.id) if @student_data_field.nil? + @field_infos = @student_data_field.student_data_fields @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) @@ -673,7 +678,9 @@ class OlympiamanagementsController < ApplicationController @student_params[key] = @olympia_student_data[key] end end - @all_fields_name = (StudentDataField.first || StudentDataField.new).student_data_fields.map{|hash| hash.keys[0]} + @student_data_field = StudentDataField.where(:sign_up_setting_id=>@sign_up_setting.id).first + @student_data_field = StudentDataField.create(:sign_up_setting_id=>@sign_up_setting.id) if @student_data_field.nil? + @all_fields_name = @student_data_field.student_data_fields.map{|hash| hash.keys[0]} if @student_params.select{|key,value| !value.to_s.blank?}.count < @all_fields_name.slice(0,@all_fields_name.count-1).count @error_msg << "缺少#{@all_fields_name.slice(0,@all_fields_name.count-1).count-@student_params.select{|key,value| !value.to_s.blank?}.count}個欄位值" end diff --git a/app/models/class_setting_fields.rb b/app/models/class_setting_fields.rb index 2dedee1..c48d77d 100644 --- a/app/models/class_setting_fields.rb +++ b/app/models/class_setting_fields.rb @@ -1,11 +1,9 @@ class ClassSettingFields include Mongoid::Document include Mongoid::Timestamps - include OrbitModel::Status - include OrbitModel::Impression # encoding: utf-8 include OrbitTag::Taggable - include OrbitCategory::Categorizable + include OrbitCategory::Categorizable field :class_number_range , type: Array , default: [] field :enrollment_available , type: Fixnum , default: 0 end \ No newline at end of file diff --git a/app/models/olympia_school_data_fields.rb b/app/models/olympia_school_data_fields.rb index ceadb21..100693d 100644 --- a/app/models/olympia_school_data_fields.rb +++ b/app/models/olympia_school_data_fields.rb @@ -1,8 +1,6 @@ class OlympiaSchoolDataFields include Mongoid::Document include Mongoid::Timestamps - include OrbitModel::Status - include OrbitModel::Impression # encoding: utf-8 field :account_number , type: String , default: '' field :password , type: String , default: '' @@ -34,7 +32,7 @@ class OlympiaSchoolDataFields self.approved = true self.save! end - if self.enrollment.nil? || self.enrollment.class != Fixnum + if self.enrollment.nil? || self.enrollment.class != Fixnum || self.enrollment < 0 self.enrollment = 0 self.save! end diff --git a/app/models/olympia_student_data_field.rb b/app/models/olympia_student_data_field.rb index f8e9830..e742967 100644 --- a/app/models/olympia_student_data_field.rb +++ b/app/models/olympia_student_data_field.rb @@ -1,19 +1,17 @@ class OlympiaStudentDataField include Mongoid::Document include Mongoid::Timestamps - include OrbitModel::Status - include OrbitModel::Impression # encoding: utf-8 include OrbitTag::Taggable - include OrbitCategory::Categorizable + include OrbitCategory::Categorizable field :StudentIdentity , type: String , default: '' - field :StudentName , type: String , default: '' + field :StudentName , type: String , default: '' field :StudentSex , type: String , default: '' - field :StudentIDNO , type: String , default: '' - field :StudentBirthYear , type: Fixnum , default: Time.now.year + field :StudentIDNO , type: String , default: '' + field :StudentBirthYear , type: Fixnum , default: Time.now.year field :StudentBirthMonth , type: Fixnum , default: Time.now.month field :StudentBirthDay , type: Fixnum , default: Time.now.day - field :StudentClass , type: String , default: '' + field :StudentClass , type: String , default: '' field :StudentPhone , type: String , default: '' field :StudentCode , type: String , default: '' field :StudentAddress , type: String , default: '' diff --git a/app/models/olympia_student_image.rb b/app/models/olympia_student_image.rb index e196e67..032a28c 100644 --- a/app/models/olympia_student_image.rb +++ b/app/models/olympia_student_image.rb @@ -1,8 +1,6 @@ class OlympiaStudentImage include Mongoid::Document include Mongoid::Timestamps - include OrbitModel::Status - include OrbitModel::Impression # encoding: utf-8 include OrbitTag::Taggable include OrbitCategory::Categorizable diff --git a/app/models/school_data_fields.rb b/app/models/school_data_fields.rb index 6aa7289..887f3a3 100644 --- a/app/models/school_data_fields.rb +++ b/app/models/school_data_fields.rb @@ -1,11 +1,9 @@ class SchoolDataFields include Mongoid::Document include Mongoid::Timestamps - include OrbitModel::Status - include OrbitModel::Impression # encoding: utf-8 include OrbitTag::Taggable - include OrbitCategory::Categorizable + include OrbitCategory::Categorizable field :school_data_fields , type: Array , default: [{'account_number'=>{'type'=>'String','size'=>'20','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true"}}, {'password'=>{'type'=>'String','size'=>'','hint'=>{'zh_tw'=>'未修改即依照預設密碼','en'=>'Use default password without modification'}}}, {'school_name'=>{'type'=>'String','size'=>'20','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true"}}, diff --git a/app/models/sign_up_setting.rb b/app/models/sign_up_setting.rb index 934c293..02fd9a9 100644 --- a/app/models/sign_up_setting.rb +++ b/app/models/sign_up_setting.rb @@ -1,11 +1,7 @@ class SignUpSetting include Mongoid::Document include Mongoid::Timestamps - include OrbitModel::Status - include OrbitModel::Impression # encoding: utf-8 - include OrbitTag::Taggable - include OrbitCategory::Categorizable field :start_year , type: String , default: Time.now.strftime("%Y") field :end_year , type: String , default: Time.now.strftime("%Y") field :start_month , type: String , default: Time.now.strftime("%m") @@ -40,7 +36,8 @@ class SignUpSetting field :active , type: Boolean , default: true after_save :change_all_password , :check_active after_destroy do |record| - OlympiaSchoolDataFields.where(:sign_up_setting_id => record.id).destroy_all + OlympiaSchoolDataFields.where(:sign_up_setting_id => record.id.to_s).destroy + StudentDataField.where(:sign_up_setting_id => record.id.to_s).destroy end after_create do |record| SignUpSetting.where(:id.ne=>record.id).each{|record| record.update(:active=>false)} diff --git a/app/models/student_data_field.rb b/app/models/student_data_field.rb index 1d8a4b2..356fc70 100644 --- a/app/models/student_data_field.rb +++ b/app/models/student_data_field.rb @@ -1,11 +1,10 @@ class StudentDataField include Mongoid::Document include Mongoid::Timestamps - include OrbitModel::Status - include OrbitModel::Impression # encoding: utf-8 include OrbitTag::Taggable - include OrbitCategory::Categorizable + include OrbitCategory::Categorizable + field :sign_up_setting_id , type: String , default: (SignUpSetting.where(:active=>true).last.id.to_s rescue "") 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"}}, diff --git a/app/views/admin/olympiamanagements/sign_up_setting.html.erb b/app/views/admin/olympiamanagements/sign_up_setting.html.erb index e1615a3..324c177 100644 --- a/app/views/admin/olympiamanagements/sign_up_setting.html.erb +++ b/app/views/admin/olympiamanagements/sign_up_setting.html.erb @@ -11,6 +11,32 @@ <%=render :partial=>'checkbox',:locals=>{:name=>t('olympiamanagement.new_sign_up'),:params_name=>'new_sign_up',:id=>'new_sign_up',:extra_class=>'lleft red_text',:is_checked=>nil}%>

+
+

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

+
+ <% index = @student_data_field.student_data_fields.map{|h| h.keys.first}.index('StudentArea') %> + <% for i in 0...(@student_data_field.student_data_fields[index]['StudentArea']['values'][@site_locales.first.to_s].count) %> +
+ +
+ <% @site_locales.each_with_index do |locale,locale_index|%> + > + <% end %> +
+
+ <% @site_locales.each_with_index do |locale,locale_index|%> + <%=t(locale)%> + <% end %> +
+
+ <% end %> +
+ <%=t(:add)%> +
+
+
+
+
  • <%= t('olympiamanagement.sign_up_start_time')%>
  • @@ -94,3 +120,47 @@ <% end %> + + \ No newline at end of file