diff --git a/app/assets/images/close.gif b/app/assets/images/close.gif new file mode 100644 index 0000000..0fb8c83 Binary files /dev/null and b/app/assets/images/close.gif differ diff --git a/app/assets/images/fhi.png b/app/assets/images/fhi.png new file mode 100644 index 0000000..5d33e33 Binary files /dev/null and b/app/assets/images/fhi.png differ diff --git a/app/assets/images/view.gif b/app/assets/images/view.gif new file mode 100644 index 0000000..ad606f2 Binary files /dev/null and b/app/assets/images/view.gif differ diff --git a/app/assets/javascripts/admin/olympiamanagement.js b/app/assets/javascripts/admin/olympiamanagement.js index 14bc25e..000f6ac 100644 --- a/app/assets/javascripts/admin/olympiamanagement.js +++ b/app/assets/javascripts/admin/olympiamanagement.js @@ -1,11 +1,24 @@ $(document).ready(function(){ - $('.fieldset_block input[type="reset"]').off('click').on('click',function(){ + $('.class_setting_block input[type="reset"]').off('click').on('click',function(){ $('.col_input').val(''); }); - $('.fieldset_block input[type="submit"]').off('click').on('click',function(){ + $('.class_setting_block input[type="submit"]').off('click').on('click',function(){ var class_number_range = []; - class_number_range.push($('.col_input input[name="MinClass"]').val()); - class_number_range.push($('.col_input input[name="MaxClass"]').val()); + 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=""; + }); }); + var $el = $('.fieldset_block select'); + for(var i = 0 ; i < $el.length ; i++) + $el.eq(i).find('option[value='+$el.eq(i).attr('value')+']').attr('selected','selected'); }); \ No newline at end of file diff --git a/app/assets/stylesheets/admin/olympiamanagement.scss b/app/assets/stylesheets/admin/olympiamanagement.scss index 765bc1a..e8a7eab 100644 --- a/app/assets/stylesheets/admin/olympiamanagement.scss +++ b/app/assets/stylesheets/admin/olympiamanagement.scss @@ -16,8 +16,8 @@ .col { float: left; clear: both; - width: 8.125em; - margin: 0 0.625em 0px 0; + width: 9.125em; + margin: 0 0.625em 0em 0; padding: 0.0625em 0 0.0625em 0; } .col_r { @@ -43,22 +43,75 @@ color: #fff; vertical-align: top; background: #81ce25; - border-bottom: 1px solid #67ac14; + border-bottom: 0.0625em solid #67ac14; } -.ts_rowsonly .even { +.ts_rowsonly tbody tr:nth-child(odd){ + background: #fff; +} +.ts_rowsonly tbody tr:nth-child(even){ background: #f5f6e2; } .ts_rowsonly td { - border-bottom: 1px solid #e7eab9; + border-bottom: 0.0625em solid #e7eab9; padding: 0.375em 0.625em; text-align: left; color: #111; vertical-align: top; } .ts_rowsonly { - margin: 0.625em 0 5px 0; + margin: 0.625em 0 0.3125em 0; font-size: 1em; } +.PageDetails { + padding-top: 0.1875em; + padding-bottom: 0.1875em; + font-weight: bold; + font-size: 0.875em; + border-bottom: 0.0625em solid #ddd; + overflow: hidden; + text-align: right; + color: black; + font-size: 1.3em; +} +.PageList { + margin: 0em 0em 0 0.5em; + font-weight: bold; + font-size: 0.875em; + overflow: hidden; + list-style: none; + display: inline; + background: none; + color: #999; +} +ol { + margin: 0 0 0.5em 0; + min-height: 0.625em; + height: auto !important; + height: 0.625em; + padding: 0; + clear: both; + float: right; +} +.PageList li { + display: inline; +} +.wrap-inner{ + font-size: 1.1em; +} +.field-hint-inactive { + color: #999; + margin-left: 0.3125em; + padding-left: 1em; + padding-right: 0.5em; + background-image: url(/assets/fhi.png); + background-repeat: no-repeat; + background-position: left center; + float: left; +} +.required { + font-weight: bold; + width: auto; +} li{ display: block; } \ No newline at end of file diff --git a/app/controllers/admin/olympiamanagements_controller.rb b/app/controllers/admin/olympiamanagements_controller.rb index 3391dc3..94c7667 100644 --- a/app/controllers/admin/olympiamanagements_controller.rb +++ b/app/controllers/admin/olympiamanagements_controller.rb @@ -1,11 +1,59 @@ class Admin::OlympiamanagementsController < OrbitAdminController + helper Admin::OlympiamanagementsHelper def index end def add_school_data + SchoolDataFields.create if SchoolDataFields.all.count == 0 + @SchoolDataField = SchoolDataFields.first + @olympia_school_data_field = (params[:id].nil? ? OlympiaSchoolDataFields.new : ((OlympiaSchoolDataFields.find(params[:id]).nil? rescue true) ? OlympiaSchoolDataFields.new : OlympiaSchoolDataFields.find(params[:id]))) + end + def update_school_data + if params[:type] == 'class_setting' + @ClassSettingField = (params[:id].nil? ? ClassSettingFields.new : ((ClassSettingFields.find(params[:id]).nil? rescue true) ? ClassSettingFields.new : ClassSettingFields.find(params[:id]))) + @ClassSettingField.class_number_range = params[:class_number_range].map{|num| num.to_i} + @ClassSettingField.enrollment_available = params[:enrollment_available].to_i + @ClassSettingField.save + render :json => {'success'=>true} and return + elsif params[:type] == 'delete_class_setting' + if !params[:id].to_s.blank? + begin + ClassSettingFields.find(params[:id]).destroy + rescue + puts 'not_found id='+params[:id]+' in ClassSettingFields' + end + redirect_to :back + end + elsif params[:type] == 'delete_school_data' + if !params[:id].to_s.blank? + begin + OlympiaSchoolDataFields.find(params[:id]).destroy + rescue + puts 'not_found id='+params[:id]+' in OlympiaSchoolDataFields' + end + redirect_to :back + end + elsif params[:type] == 'add_school_data' + @olympia_school_data_field = (params[:id].nil? ? OlympiaSchoolDataFields.new : ((OlympiaSchoolDataFields.find(params[:id]).nil? rescue true) ? OlympiaSchoolDataFields.new : OlympiaSchoolDataFields.find(params[:id]))) + params['add_school_data'].keys.each do |field| + @olympia_school_data_field[field] = params['add_school_data'][field] + end + @olympia_school_data_field.save + redirect_to admin_olympiamanagements_school_data_list_path + end end def school_data_list + @SchoolDataField = SchoolDataFields.first + @SchoolDataname = @SchoolDataField.school_data_fields.map{|field| field.keys[0]} + page_num = params[:page] || 1 + @OlympiaSchoolDataFields = OlympiaSchoolDataFields.all.asc(:id) + @OlympiaSchoolDataFields = @OlympiaSchoolDataFields.where("school_name" => /#{params[:school_name]}/) if !params[:school_name].to_s.blank? + @OlympiaSchoolDataFields = @OlympiaSchoolDataFields.where("school_code" => /#{params[:school_code]}/) if !params[:school_code].to_s.blank? + @OlympiaSchoolDataFields = @OlympiaSchoolDataFields.page(page_num).per(10) end def class_setting + page_num = params[:page] || 1 + @class_setting_list = ClassSettingFields.all.asc(:enrollment_available).page(page_num).per(10) + @ClassSettingField = (params[:id].nil? ? nil : ((ClassSettingFields.find(params[:id]).nil? rescue true) ? nil : ClassSettingFields.find(params[:id]))) end def sign_up_setting end diff --git a/app/helpers/admin/olympiamanagements_helper.rb b/app/helpers/admin/olympiamanagements_helper.rb new file mode 100644 index 0000000..ff41f0f --- /dev/null +++ b/app/helpers/admin/olympiamanagements_helper.rb @@ -0,0 +1,11 @@ +module Admin::OlympiamanagementsHelper + def create_pagination(page=1,fields=ClassSettingFields) + page = 1 if page == 0 + per_page_num = 10 + all_page_num = fields.all.count / per_page_num + 1 + pagination = '
'+((I18n.locale.to_s == 'zh_tw') ? "第 #{page} 頁" : "page #{page}") +'/'+ ((I18n.locale.to_s == 'zh_tw') ? "共 #{all_page_num} 頁" : "Total #{all_page_num} page(s)")+'
    '+ + ((page == 1) ? '
  1. ['+t('olympiamanagement.prev_page')+']
  2. ' : '
  3. ['+t('olympiamanagement.prev_page')+']
  4. ') + (1..all_page_num).to_a.each{|page_num| pagination += ((page_num == page) ? '
  5. '+page_num.to_s+'
  6. ' : '
  7. '+page_num.to_s+'
  8. ')} + pagination += (((page==all_page_num) ? '
  9. ['+t('olympiamanagement.next_page')+']
  10. ' : '
  11. ['+t('olympiamanagement.next_page')+']
  12. ')+'
') + end +end \ No newline at end of file diff --git a/app/models/class_setting_fields.rb b/app/models/class_setting_fields.rb new file mode 100644 index 0000000..2dedee1 --- /dev/null +++ b/app/models/class_setting_fields.rb @@ -0,0 +1,11 @@ +class ClassSettingFields + include Mongoid::Document + include Mongoid::Timestamps + include OrbitModel::Status + include OrbitModel::Impression + # encoding: utf-8 + include OrbitTag::Taggable + 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 new file mode 100644 index 0000000..26be76e --- /dev/null +++ b/app/models/olympia_school_data_fields.rb @@ -0,0 +1,22 @@ +class OlympiaSchoolDataFields + include Mongoid::Document + include Mongoid::Timestamps + include OrbitModel::Status + include OrbitModel::Impression + # encoding: utf-8 + include OrbitTag::Taggable + include OrbitCategory::Categorizable + field :account_number , type: String , default: '' + field :password , type: String , default: '' + field :school_name , type: String , default: '' + field :school_code , type: String , default: '' + field :school_address , type: String , default: '' + field :class_number , type: Fixnum , default: 0 + field :enrollment_limited , type: Fixnum , default: 0 + field :school_contact_person_name , type: String , default: '' + field :department_job_title , type: String , default: '' + field :office_tel_number , type: String , default: '' + field :fax , type: String , default: '' + field :mobile_number , type: String , default: '' + field :email , type: String , default: '' +end \ No newline at end of file diff --git a/app/models/school_data_fields.rb b/app/models/school_data_fields.rb new file mode 100644 index 0000000..2656ae7 --- /dev/null +++ b/app/models/school_data_fields.rb @@ -0,0 +1,22 @@ +class SchoolDataFields + include Mongoid::Document + include Mongoid::Timestamps + include OrbitModel::Status + include OrbitModel::Impression + # encoding: utf-8 + include OrbitTag::Taggable + include OrbitCategory::Categorizable + field :school_data_fields , type: Array , default: [{'account_number'=>{'type'=>'String','size'=>'20','hint'=>{'zh_tw'=>'','en'=>''}}}, + {'password'=>{'type'=>'String','size'=>'','hint'=>{'zh_tw'=>'未修改即依照預設密碼','en'=>''}}}, + {'school_name'=>{'type'=>'String','size'=>'20','hint'=>{'zh_tw'=>'','en'=>''}}}, + {'school_code'=>{'type'=>'String','size'=>'20','hint'=>{'zh_tw'=>'','en'=>''}}}, + {'school_address'=>{'type'=>'String','size'=>'40','hint'=>{'zh_tw'=>'','en'=>''}}}, + {'class_number'=>{'type'=>'select','size'=>'','hint'=>{'zh_tw'=>'','en'=>''},'range'=>[1,200],'unit'=>{'zh_tw'=>'班','en'=>'class'}}}, + {'enrollment_limited'=>{'type'=>'Fixnum','size'=>'5','hint'=>{'zh_tw'=>'未修改即依照班級設定','en'=>''}}}, + {'school_contact_person_name'=>{'type'=>'String','size'=>'20','hint'=>{'zh_tw'=>'','en'=>''}}}, + {'department_job_title'=>{'type'=>'String','size'=>'20','hint'=>{'zh_tw'=>'','en'=>''}}}, + {'office_tel_number'=>{'type'=>'String','size'=>'20','hint'=>{'zh_tw'=>'','en'=>''}}}, + {'fax'=>{'type'=>'String','size'=>'20','hint'=>{'zh_tw'=>'','en'=>''}}}, + {'mobile_number'=>{'type'=>'String','size'=>'20','hint'=>{'zh_tw'=>'','en'=>''}}}, + {'email'=>{'type'=>'String','size'=>'40','hint'=>{'zh_tw'=>'','en'=>''}}}] +end \ No newline at end of file diff --git a/app/views/admin/olympiamanagements/add_school_data.html.erb b/app/views/admin/olympiamanagements/add_school_data.html.erb index e69de29..830efdb 100644 --- a/app/views/admin/olympiamanagements/add_school_data.html.erb +++ b/app/views/admin/olympiamanagements/add_school_data.html.erb @@ -0,0 +1,29 @@ + + + +
+ <%=t('olympiamanagement.'+(!@olympia_school_data_field.new_record? ? 'edit_school_data' : 'add_school_data'))%> + <%=form_for @olympia_school_data_field ,:url=>{:controller=>"olympiamanagements" ,:action=>"update_school_data",:type=>"add_school_data",:id=>params[:id]} do |form|%> + <% @SchoolDataField.school_data_fields.each do |field| %> +
+ <% if field.values[0][:type] != 'select' %> +
  • <%= t('olympiamanagement.'+field.keys[0]) %>
  • " value="<%= @olympia_school_data_field[field.keys[0]] %>" size="<%=field.values[0][:size]%>" type="text" id="<%= field.keys[0] %>" class="col_input"/>
  • + <% else%> + <% @please_choice = (I18n.locale.to_s == "zh_tw") ? "請選擇" : "Please select." %> +
  • <%= t('olympiamanagement.'+field.keys[0]) %>
  • + + <% end %> + <% if !field.values[0][:hint][I18n.locale.to_s].blank? %> + <%=field.values[0][:hint][I18n.locale.to_s]%> + <% end %> +
  • + <% end %> +
    + + + <% end %> +
    \ No newline at end of file diff --git a/app/views/admin/olympiamanagements/class_setting.html.erb b/app/views/admin/olympiamanagements/class_setting.html.erb index da9c36b..4e67302 100644 --- a/app/views/admin/olympiamanagements/class_setting.html.erb +++ b/app/views/admin/olympiamanagements/class_setting.html.erb @@ -1,16 +1,16 @@ -
    +
    <%=t('olympiamanagement.class_setting')%>
  • <%= t('olympiamanagement.class_number')+"(#{t('olympiamanagement.spacing')})"%>
  • -
  • +
  • >
  • ~ -
  • +
  • >
  • -
  • <%= t('olympiamanagement.enrollment_available') %>
  • +
  • <%= t('olympiamanagement.enrollment_available') %>
  • >
  • @@ -25,5 +25,16 @@ + <% @class_setting_list.each do |class_setting| %> + + <%= class_setting.class_number_range.join(' ~ ') %> + <%= class_setting.enrollment_available %> + + "><%= t('olympiamanagement.edit') %><%= t('olympiamanagement.edit') %> + "><%= t('olympiamanagement.delete') %><%= t('olympiamanagement.delete') %> + + + <%end%> - \ No newline at end of file + +<%=create_pagination(params[:page].to_i).html_safe%> \ No newline at end of file diff --git a/app/views/admin/olympiamanagements/school_data_list.html.erb b/app/views/admin/olympiamanagements/school_data_list.html.erb index e69de29..c11aa83 100644 --- a/app/views/admin/olympiamanagements/school_data_list.html.erb +++ b/app/views/admin/olympiamanagements/school_data_list.html.erb @@ -0,0 +1,44 @@ + + + +
    + <%=t('olympiamanagement.search')%> +
    +
    +
  • <%= t('olympiamanagement.school_name')%>
  • +
  • +
    +
    +
  • <%= t('olympiamanagement.school_code') %>
  • +
    +
    + +
    +
    +<% th_name_list = ['school_name','school_code','class_number','enrollment','account_number','action']%> + + + + <% th_name_list.each do |th_name|%> + + <% end %> + + + + <% @OlympiaSchoolDataFields.each do |field| %> + + <% th_name_list.each do |th_name|%> + <%if th_name != 'action'%> + + <% else %> + + <% end %> + <% end %> + + <%end%> + +
    <%= t('olympiamanagement.'+th_name) %>
    <%= field[th_name]%> + "><%= t('olympiamanagement.edit') %><%= t('olympiamanagement.edit') %> + "><%= t('olympiamanagement.delete') %><%= t('olympiamanagement.delete') %> +
    +<%=create_pagination(params[:page].to_i,OlympiaSchoolDataFields).html_safe%> \ No newline at end of file diff --git a/auto_create_Class_Setting.js b/auto_create_Class_Setting.js new file mode 100644 index 0000000..abf90ac --- /dev/null +++ b/auto_create_Class_Setting.js @@ -0,0 +1,13 @@ +for(var i=1;i<=133;i+=4){ + var class_number_range = [i,i+3]; + var enrollment_available = (i+3)/4; + var params_to_send = {'type':'add_school_data','class_number_range':class_number_range,'enrollment_available':enrollment_available}; + var post_data = $.post('/admin/olympiamanagements/update_school_data',params_to_send); +} +var class_number_range = [137,200]; +var enrollment_available = 35; +var params_to_send = {'type':'add_school_data','class_number_range':class_number_range,'enrollment_available':enrollment_available}; +var post_data = $.post('/admin/olympiamanagements/update_school_data',params_to_send); +post_data.done(function(){ + console.log('done'); +}); \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index d27d99c..4494854 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2,6 +2,7 @@ en: olympiamanagement: olympiamanagement: Olympia competition management add_school_data: Add school data + edit_school_data: Edit school data school_data_list: School data list class_setting: Class setting sign_up_setting: Sign up setting @@ -12,8 +13,26 @@ en: class_number: Number of class in school spacing: spacing enrollment_available: Enrollment available + enrollment_limited: Enrollment limited confirm: Confirm cancel: Cancel action: Action edit: Edit - delete: Delete \ No newline at end of file + delete: Delete + search: Search + school_name: School name + school_code: School code + school_address: School address + submit: Submit + enrollment: Enrollment + account_number: ID + password: PW + email: Email + fax: Fax + mobile_number: Mobile Number + office_tel_number: Office Tel No. + department_job_title: Department job title + school_contact_person_name: School contact person's name + prev_page: Previous page + next_page: Next page + \ No newline at end of file diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 27bcccd..3d9e94c 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -2,6 +2,7 @@ zh_tw: olympiamanagement: olympiamanagement: 奧林匹亞競賽 Management add_school_data: 新增學校資料 + edit_school_data: 編輯學校資料 school_data_list: 學校資料列表 class_setting: 班級設定 sign_up_setting: 報名設定 @@ -12,8 +13,25 @@ zh_tw: class_number: 全校班級數 spacing: 間距 enrollment_available: 可報名人數 + enrollment_limited: 報名人數上限 confirm: 確定 cancel: 取消 action: 動作 edit: 編輯 - delete: 刪除 \ No newline at end of file + delete: 刪除 + search: 搜尋 + school_name: 學校名稱 + school_code: 學校代碼 + school_address: 學校地址 + submit: 送出 + enrollment: 報名人數 + account_number: 帳號 + password: 密碼 + email: 信箱 + fax: 傳真 + mobile_number: 手機號碼 + office_tel_number: 聯絡電話 + department_job_title: 單位職稱 + school_contact_person_name: 學校聯絡人姓名 + prev_page: 上一頁 + next_page: 下一頁 \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 89310a8..1b0fd2a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -13,6 +13,9 @@ Rails.application.routes.draw do get 'olympiamanagements/export_sign_up_student_data' , to: 'olympiamanagements#export_sign_up_student_data' get 'olympiamanagements/download_scan_file_of_certificate' , to: 'olympiamanagements#download_scan_file_of_certificate' get 'olympiamanagements/import_editing_number_of_school_class' , to: 'olympiamanagements#import_editing_number_of_school_class' + post 'olympiamanagements/update_school_data' , to: 'olympiamanagements#update_school_data' + patch 'olympiamanagements/update_school_data' , to: 'olympiamanagements#update_school_data' + get 'olympiamanagements/update_school_data' , to: 'olympiamanagements#update_school_data' resources :olympiamanagements end end diff --git a/lib/olympiamanagement/engine.rb b/lib/olympiamanagement/engine.rb index c2a5e51..f371b60 100644 --- a/lib/olympiamanagement/engine.rb +++ b/lib/olympiamanagement/engine.rb @@ -14,13 +14,8 @@ module Olympiamanagement head_label_i18n 'olympiamanagement.olympiamanagement', icon_class: "icons-megaphone" available_for "users" active_for_controllers (['admin/olympiamanagement']) - head_link_path "admin_olympiamanagements_path" + head_link_path "admin_olympiamanagements_school_data_list_path" - context_link 'olympiamanagement.olympiamanagement', - :link_path=>"admin_olympiamanagements_path" , - :priority=>1, - :active_for_action=>{'admin/olympiamanagements'=>'index'}, - :available_for => 'users' context_link 'olympiamanagement.add_school_data', :link_path=>"admin_olympiamanagements_add_school_data_path" , :priority=>1,