diff --git a/app/controllers/olympiamanagements_controller.rb b/app/controllers/olympiamanagements_controller.rb index 52326ff..fc67b05 100644 --- a/app/controllers/olympiamanagements_controller.rb +++ b/app/controllers/olympiamanagements_controller.rb @@ -1,10 +1,16 @@ class OlympiamanagementsController < ApplicationController include ActionView::Context #vary important (only add this can access @@session from view) - before_action :set_sign_up_setting + before_action :set_sign_up_setting,:create_first_fields prepend_view_path "app/templates" #for_render_pages layout :get_layout #for_render_pages before_action :check_login, except: :login - #include "#{Rails.root}/app/helpers/application_helper.rb" + def initialize + super + @app_title = "olympiamanagement" + end + def create_first_fields + StudentDataField.create if StudentDataField.all.length == 0 + end def check_login begin @@error @@ -34,10 +40,6 @@ class OlympiamanagementsController < ApplicationController redirect_to params[:PreviousPage].to_s end end - def initialize - super - @app_title = "olympiamanagement" - end def set_sign_up_setting @key = Site.first.template rescue "" #for_render_pages @sign_up_setting = SignUpSetting.last @@ -176,9 +178,6 @@ class OlympiamanagementsController < ApplicationController start_time_str = @time_arr.map{|t| @sign_up_setting["start_"+t]}.join(' ') end_time_str = @time_arr.map{|t| @sign_up_setting["end_"+t]}.join(' ') time_now_str = Time.now.strftime("%Y %m %d %H %M") - #@request = Rack::Request.new((OrbitHelper.request.env rescue nil) || (request.env rescue env)) - #@session = @request.session - #render :html => session.to_hash and return if !(!(time_now_str <= end_time_str && time_now_str >= start_time_str) || session[:olympia_login_id].to_s.blank?) redirect_to :back else @@ -196,12 +195,17 @@ 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 - render_contents_in_index_page(@breadcumb) + @student_data_field = StudentDataField.first + @olympia_student_data = OlympiaStudentDataFields.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) end #if @flag = false end end def sign_up_student_data_list + @student_fields = OlympiaStudentDataFields.all + render_contents_in_index_page end def edit_password if !session[:olympia_login_id].to_s.blank? @@ -522,6 +526,13 @@ class OlympiamanagementsController < ApplicationController #render_contents_in_index_page(@olympia_school_data_field.attributes.to_s) end def updata_student_data + if params[:type] == 'add_student_data' + @olympia_student_data = OlympiaStudentDataFields.create(params.require(:add_student_data).permit(:StudentIdentity,:StudentName,:StudentSex,:StudentIDNO, + :StudentBirthMonth,:StudentBirthDay,:StudentClass,:StudentPhone,:StudentCode,:StudentAddress,:StudentArea,:StudentFile)) + redirect_to sign_up_student_data_list_olympiamanagements_path + else + render :html => '404' + end #render :html => '123' end end \ No newline at end of file diff --git a/app/models/olympia_images_uploader.rb b/app/models/olympia_images_uploader.rb new file mode 100644 index 0000000..d965035 --- /dev/null +++ b/app/models/olympia_images_uploader.rb @@ -0,0 +1,33 @@ +# encoding: utf-8 +require 'carrierwave/processing/mime_types' + +class OlympiaImagesUploader < CarrierWave::Uploader::Base + + include CarrierWave::MimeTypes + + process :set_content_type + + # Include RMagick or ImageScience support: + # include CarrierWave::RMagick + # include CarrierWave::ImageScience + + # Choose what kind of storage to use for this uploader: + # storage :file + # storage :s3 + + # Override the directory where uploaded files will be stored. + # This is a sensible default for uploaders that are meant to be mounted: + def store_dir + return "uploads/#{model.class.to_s.underscore}/olympia_students" + end + + # override + def filename + @original_filename + end + + def cache_dir + "#{Rails.root}/tmp/uploads" + end + +end diff --git a/app/models/olympia_student_data_fields.rb b/app/models/olympia_student_data_fields.rb new file mode 100644 index 0000000..46bf0c7 --- /dev/null +++ b/app/models/olympia_student_data_fields.rb @@ -0,0 +1,32 @@ +class OlympiaStudentDataFields + include Mongoid::Document + include Mongoid::Timestamps + include OrbitModel::Status + include OrbitModel::Impression + # encoding: utf-8 + include OrbitTag::Taggable + include OrbitCategory::Categorizable + field :StudentIdentity , 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 :StudentBirthMonth , type: Fixnum , default: Time.now.month + field :StudentBirthDay , type: Fixnum , default: Time.now.day + field :StudentClass , type: String , default: '' + field :StudentPhone , type: String , default: '' + field :StudentCode , type: String , default: '' + field :StudentAddress , type: String , default: '' + field :StudentArea , type: String , default: '' + mount_uploader :StudentFile, OlympiaImagesUploader + field :approved , type: Boolean , default: true + field :olympia_school_data_fields_id , type: String , default: '' + after_initialize do + if !self.new_record? + if self.approved.nil? + self.approved = true + self.save! + end + end + end +end \ No newline at end of file diff --git a/app/models/student_data_field.rb b/app/models/student_data_field.rb index e69de29..0b635ad 100644 --- a/app/models/student_data_field.rb +++ b/app/models/student_data_field.rb @@ -0,0 +1,23 @@ +class StudentDataField + include Mongoid::Document + include Mongoid::Timestamps + include OrbitModel::Status + include OrbitModel::Impression + # 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"}}, + {'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"}}, + {'StudentBirthYear'=>{'type'=>'Year','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true"}}, + {'StudentBirthMonth'=>{'type'=>'select_num','range'=>[1,12],'hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true"}}, + {'StudentBirthDay'=>{'type'=>'select_num','range'=>[1,31],'hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true"}}, + {'StudentClass'=>{'type'=>'String','size'=>'20','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true"}}, + {'StudentPhone'=>{'type'=>'String','size'=>'20','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true"}}, + {'StudentCode'=>{'type'=>'String','size'=>'10','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true"}}, + {'StudentAddress'=>{'type'=>'String','size'=>'40','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true"}}, + {'StudentArea'=>{'type'=>'select_string','hint'=>{'zh_tw'=>'','en'=>''},'values'=>{'zh_tw'=>['台北考區','新竹考區','台中考區','嘉義考區','高雄考區','花蓮考區','台東考區','金門考區','澎湖考區'], + 'en'=>['Taipei exam area','Hsinchu exam area','Taichung exam area','Chiayi exam area','Kaohsiung exam area','Hualien exam area','Taitung exam area','Kinmen exam area','Penghu exam area']},'required'=>"true"}}, + {'StudentFile'=>{'type'=>'File','hint'=>{'zh_tw'=>'','en'=>''},'required'=>"true"}}] +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 new file mode 100644 index 0000000..0a9f3d6 --- /dev/null +++ b/app/views/olympiamanagements/_add_student_data.html.erb @@ -0,0 +1,63 @@ + + + + \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 5db77b1..3f8b945 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -10,11 +10,26 @@ en: edit_password: Edit password sign_up_student_data_list: Sign up student data list add_sign_up_student_data: Add sign up student data + edit_sign_up_student_data: Edit sign up student data school_connection_data: School connection data export_school_connection_data: Export school connection data export_sign_up_student_data: Export sign up student data download_scan_file_of_certificate: Download scan file of certificate import_editing_number_of_school_class: Import editing number of school class + StudentIdentity: Identity + StudentName: Student Name + StudentSex: Sex + StudentIDNO: ID Number + birth_date: Birth Date + StudentBirthYear: Year + StudentBirthMonth: Month + StudentBirthDay: Day + StudentClass: Class + StudentPhone: Phone + StudentCode: Postal code + StudentAddress: Address + StudentArea: Exam area + StudentFile: Upload Certificate scan file(only Science fairs winner need to upload) class_number: Number of class in school spacing: spacing enrollment_available: Enrollment available diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 82dc90e..a89eac1 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -10,11 +10,26 @@ zh_tw: edit_password: 修改密碼 sign_up_student_data_list: 報名學生資料列表 add_sign_up_student_data: 新增報名學生資料 + edit_sign_up_student_data: 編輯報名學生資料 school_connection_data: 學校聯絡資料 export_school_connection_data: 匯出學校聯絡資料 export_sign_up_student_data: 匯出報名學生資料 download_scan_file_of_certificate: 下載獎狀掃描檔 import_editing_number_of_school_class: 匯入修改學校班級數 + StudentIdentity: 身份 + StudentName: 學生姓名 + StudentSex: 性別 + StudentIDNO: 身分證字號 + birth_date: 出生年月日 + StudentBirthYear: 年 + StudentBirthMonth: 月 + StudentBirthDay: 日 + StudentClass: 班級 + StudentPhone: 聯絡電話 + StudentCode: 郵遞區號 + StudentAddress: 地址 + StudentArea: 考區 + StudentFile: 上傳獎狀掃描檔(僅科展得獎者需要上傳) class_number: 全校班級數 spacing: 間距 enrollment_available: 可報名人數