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") field :end_month , type: String , default: Time.now.strftime("%m") field :start_day , type: String , default: Time.now.strftime("%d") field :end_day , type: String , default: Time.now.strftime("%d") field :start_o_clock , type: String , default: Time.now.strftime("%H") field :end_o_clock , type: String , default: Time.now.strftime("%H") field :start_minute , type: String , default: Time.now.strftime("%M") field :end_minute , type: String , default: Time.now.strftime("%M") field :default_password , type: String , default: "" field :set_default_password , type: Boolean , default: false field :remark_field , type: Hash , default: {:zh_tw=>'注意事項:
請於{{end_year}}年{{end_month}}月{{end_day}}日前(以郵戳為憑),將本報名表正本(需核章)以掛號方式郵寄至【11677台北市文山區汀州路4段88號科教中心,收件人: IJSO選訓委員會】,逾期概不受理報名。


',:en=>""} field :registration_instructions , type: Hash , default: {:zh_tw=>'

報名日期:{{start_year}}/{{start_month}}/{{start_day}}~{{end_year}}/{{end_month}}/{{end_day}}

1. 線上報名系統之各校登入帳號為學校代碼,密碼隨公文發至各校。(學校代碼查詢)

2. 登入系統後,請先填學校聯絡資料

3. 新增報名學生資料:
(1)學生姓名
(2)性別
(3) 身份證字號
(4) 出生年月日
(5) 班級
(6) 聯絡電話
(7) 郵遞區號
(8) 地址
(9) 身份(一般身份、科展得獎者) : 科展得獎者需要上傳獎狀掃描檔
(10) 考區

4. 列印報名表,由校長及教務主任核章後,以掛號郵寄至【11677台北市文山區汀州路488號科教中心,收件人:IJSO選訓委員會】。

', :en=>""} 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 end after_create do |record| SignUpSetting.where(:id.ne=>record.id).each{|record| record.update(:active=>false)} @sign_up_setting = SignUpSetting.where(:id.ne=>record.id).last @schools = OlympiaSchoolDataFields.where(:sign_up_setting_id=>@sign_up_setting.id).take_while{true} @schools.each do |school| OlympiaSchoolDataFields.create(school.attributes.except(*['_id','enrollment',"view_count","created_at","updated_at","sign_up_setting_id"]).merge({:sign_up_setting_id => record.id})) end end def change_all_password if self.set_default_password && !self.default_password.blank? OlympiaSchoolDataFields.where(:sign_up_setting_id=>self.id).each do |school_field| school_field.password = self.default_password school_field.save end self.set_default_password = false self.save end end def check_active if self.active SignUpSetting.where(:id.ne=>self.id).each do |setting| setting_copy = setting setting_copy.active = false setting_copy.save! end end end end