finish add student field

This commit is contained in:
BOHUNG 2020-02-03 23:24:43 +08:00
parent 97d4e79d80
commit 0ad22b9fa6
7 changed files with 202 additions and 10 deletions

View File

@ -1,10 +1,16 @@
class OlympiamanagementsController < ApplicationController class OlympiamanagementsController < ApplicationController
include ActionView::Context #vary important (only add this can access @@session from view) 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 prepend_view_path "app/templates" #for_render_pages
layout :get_layout #for_render_pages layout :get_layout #for_render_pages
before_action :check_login, except: :login 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 def check_login
begin begin
@@error @@error
@ -34,10 +40,6 @@ class OlympiamanagementsController < ApplicationController
redirect_to params[:PreviousPage].to_s redirect_to params[:PreviousPage].to_s
end end
end end
def initialize
super
@app_title = "olympiamanagement"
end
def set_sign_up_setting def set_sign_up_setting
@key = Site.first.template rescue "" #for_render_pages @key = Site.first.template rescue "" #for_render_pages
@sign_up_setting = SignUpSetting.last @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(' ') 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(' ') end_time_str = @time_arr.map{|t| @sign_up_setting["end_"+t]}.join(' ')
time_now_str = Time.now.strftime("%Y %m %d %H %M") 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?) if !(!(time_now_str <= end_time_str && time_now_str >= start_time_str) || session[:olympia_login_id].to_s.blank?)
redirect_to :back redirect_to :back
else else
@ -196,12 +195,17 @@ class OlympiamanagementsController < ApplicationController
I18n.t('olympiamanagement.please_set_school_connect_data') I18n.t('olympiamanagement.please_set_school_connect_data')
render_contents_in_index_page(@breadcumb+"<p><a href=#{school_connection_data_olympiamanagements_path}>#{I18n.t('olympiamanagement.please_set_school_connect_data')}</a></p>".html_safe) render_contents_in_index_page(@breadcumb+"<p><a href=#{school_connection_data_olympiamanagements_path}>#{I18n.t('olympiamanagement.please_set_school_connect_data')}</a></p>".html_safe)
else 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 end
#if @flag = false #if @flag = false
end end
end end
def sign_up_student_data_list def sign_up_student_data_list
@student_fields = OlympiaStudentDataFields.all
render_contents_in_index_page
end end
def edit_password def edit_password
if !session[:olympia_login_id].to_s.blank? 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) #render_contents_in_index_page(@olympia_school_data_field.attributes.to_s)
end end
def updata_student_data 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' #render :html => '123'
end end
end end

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,63 @@
<link rel="stylesheet" media="screen" type="text/css" href="/assets/admin/olympiamanagement.scss">
<link rel="stylesheet" media="print" type="text/css" href="/assets/admin/olympiamanagement.scss">
<script src="/assets/admin/olympiamanagement.js"></script>
<fieldset class="fieldset_block">
<legend class="fieldset_title"><%=t('olympiamanagement.'+(!@olympia_student_data.new_record? ? 'edit_sign_up_student_data' : 'add_sign_up_student_data'))%></legend>
<%=form_for @olympia_student_data ,:url=>{:controller=>"olympiamanagements" ,:action=>"updata_student_data",:type=>"add_student_data",:id=>params[:id]}, :html => {:multipart => true} do |form|%>
<% @student_data_field.student_data_fields.each do |field| %>
<div class="col_text">
<% @extra_class = ((field.values[0]["required"] == "true")? " required" : "")%>
<% @extra_text = ((field.values[0]["required"] == "true")? "*" : "")%>
<%if !["StudentBirthYear","StudentBirthMonth","StudentBirthDay"].include?(field.keys[0]) %>
<li class="col<%=@extra_class%>" for="<%=field.keys[0]%>"><%= @extra_text+t('olympiamanagement.'+field.keys[0]) %></li>
<%elsif field.keys[0]=="StudentBirthYear"%>
<li class="col<%=@extra_class%>" for="<%=field.keys[0]%>"><%= @extra_text+t('olympiamanagement.birth_date') %></li>
<%end%>
<li class="col_r">
<% if field.values[0][:type] == 'String' %>
<input type="text" name="<%="[add_student_data][#{field.keys[0]}]"%>" value="<%= (field.keys[0]=="enrollment_limited"&&(@olympia_student_data[field.keys[0]].nil? || @olympia_school_data_field[field.keys[0]] == 0) ) ? "" : @olympia_school_data_field[field.keys[0]] %>" size="<%=field.values[0][:size]%>" id="<%= field.keys[0] %>" class="col_input<%= @extra_class%>"/>
<% elsif field.values[0][:type] == 'select_num' %>
<% @please_choice = (I18n.locale.to_s == "zh_tw") ? "請選擇" : "Please select." %>
<select name="<%="[add_student_data][#{field.keys[0]}]"%>" id="<%=field.keys[0]%>" class="required" value="<%= @olympia_student_data[field.keys[0]] %>" style="width: auto;"><option value=""><%=@please_choice%></option>
<% for @num in field.values[0]["range"][0] .. field.values[0]["range"][1] %>
<%= ('<option value="' + @num.to_s + '">' + @num.to_s + (field.values[0][:unit][I18n.locale.to_s] rescue "") + '</option>').html_safe %>
<% end %>
</select>
<%if ["StudentBirthMonth","StudentBirthDay"].include?(field.keys[0]) %>
<%=t('olympiamanagement.'+field.keys[0])%>
<%end%>
<% elsif field.values[0][:type] == 'Year' %>
<%=t('olympiamanagement.a_d_')%>
<% @please_choice = (I18n.locale.to_s == "zh_tw") ? "請選擇" : "Please select." %>
<select name="<%="[add_student_data][#{field.keys[0]}]"%>" id="<%=field.keys[0]%>" class="required" value="<%= @olympia_student_data[field.keys[0]] %>" style="width: auto;"><option value=""><%=@please_choice%></option>
<% for @num in (Time.now.year.to_i-10) .. (Time.now.year.to_i+10) %>
<%= ('<option value="' + @num.to_s + '">' + @num.to_s + (field.values[0][:unit][I18n.locale.to_s] rescue "") + '</option>').html_safe %>
<% end %>
</select>
<%=t('olympiamanagement.year')%>
<% elsif field.values[0][:type] == 'select_string' %>
<% @please_choice = (I18n.locale.to_s == "zh_tw") ? "請選擇" : "Please select." %>
<select name="<%="[add_student_data][#{field.keys[0]}]"%>" id="<%=field.keys[0]%>" class="required" value="<%= @olympia_student_data[field.keys[0]] %>" style="width: auto;"><option value=""><%=@please_choice%></option>
<% field.values[0]["values"][I18n.locale.to_s].each_with_index do |value,i| %>
<%= ('<option value="' + ((value.class == String) ? i.to_s : value) + '">' + value.to_s + '</option>').html_safe %>
<% end %>
</select>
<% elsif field.values[0][:type] == 'radio' %>
<%field.values[0][:choices].each_with_index do |choice,i|%>
<input type="radio" size="<%=field.values[0][:size]%>" name="<%="[add_student_data][#{field.keys[0]}]"%>" id="<%="#{field.keys[0]}_#{choice}"%>" class="required" value="<%=choice%>" "<%= (@olympia_student_data[field.keys[0]]== choice) ? 'checked' : '' %>">
<label for="<%="#{field.keys[0]}_#{choice}"%>"><%=field.values[0][:values][I18n.locale.to_s][i]%></label>
<% end %>
<% elsif field.values[0][:type] == 'File' %>
<input type="file" name="<%="[add_student_data][#{field.keys[0]}]"%>" value="<%= (field.keys[0]=="enrollment_limited"&&(@olympia_student_data[field.keys[0]].nil? || @olympia_school_data_field[field.keys[0]] == 0) ) ? "" : @olympia_school_data_field[field.keys[0]] %>" size="<%=field.values[0][:size]%>" id="<%= field.keys[0] %>" style="margin-top: 1em;" class="col_input<%= @extra_class%>"/>
<% end %>
</li>
<% if !field.values[0][:hint][I18n.locale.to_s].blank? %>
<span id="-H" class="field-hint-inactive"><%=field.values[0][:hint][I18n.locale.to_s]%></span>
<% end %>
</div>
<% end %>
<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>

View File

@ -10,11 +10,26 @@ en:
edit_password: Edit password edit_password: Edit password
sign_up_student_data_list: Sign up student data list sign_up_student_data_list: Sign up student data list
add_sign_up_student_data: Add sign up student data 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 school_connection_data: School connection data
export_school_connection_data: Export school connection data export_school_connection_data: Export school connection data
export_sign_up_student_data: Export sign up student data export_sign_up_student_data: Export sign up student data
download_scan_file_of_certificate: Download scan file of certificate download_scan_file_of_certificate: Download scan file of certificate
import_editing_number_of_school_class: Import editing number of school class 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 class_number: Number of class in school
spacing: spacing spacing: spacing
enrollment_available: Enrollment available enrollment_available: Enrollment available

View File

@ -10,11 +10,26 @@ zh_tw:
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: 編輯報名學生資料
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: 身份
StudentName: 學生姓名
StudentSex: 性別
StudentIDNO: 身分證字號
birth_date: 出生年月日
StudentBirthYear:
StudentBirthMonth:
StudentBirthDay:
StudentClass: 班級
StudentPhone: 聯絡電話
StudentCode: 郵遞區號
StudentAddress: 地址
StudentArea: 考區
StudentFile: 上傳獎狀掃描檔(僅科展得獎者需要上傳)
class_number: 全校班級數 class_number: 全校班級數
spacing: 間距 spacing: 間距
enrollment_available: 可報名人數 enrollment_available: 可報名人數