finish add_school_data and class_setting(include auto_create_Class_Setting.js) and part of school_data_list(search and edit and delete)

This commit is contained in:
BOHUNG 2020-01-29 19:26:44 +08:00
parent 9e74d57d66
commit 994c117220
18 changed files with 335 additions and 23 deletions

BIN
app/assets/images/close.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

BIN
app/assets/images/fhi.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 468 B

BIN
app/assets/images/view.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@ -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');
});

View File

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

View File

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

View File

@ -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 = '<div class="PageDetails">'+((I18n.locale.to_s == 'zh_tw') ? "#{page}" : "page #{page}") +'/'+ ((I18n.locale.to_s == 'zh_tw') ? "#{all_page_num}" : "Total #{all_page_num} page(s)")+'<ol class="PageList">'+
((page == 1) ? '<li>['+t('olympiamanagement.prev_page')+']</li>' : '<li><a href="?page='+(page-1).to_s+'"> ['+t('olympiamanagement.prev_page')+'] </a></li>')
(1..all_page_num).to_a.each{|page_num| pagination += ((page_num == page) ? '<li>'+page_num.to_s+'</li>' : '<li><a href="?page='+page_num.to_s+'"> '+page_num.to_s+' </a></li>')}
pagination += (((page==all_page_num) ? '<li>['+t('olympiamanagement.next_page')+']</li>' : '<li><a href="?page='+(page+1).to_s+'"> ['+t('olympiamanagement.next_page')+'] </a></li>')+'</ol></div>')
end
end

View File

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

View File

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

View File

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

View File

@ -0,0 +1,29 @@
<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_school_data_field.new_record? ? 'edit_school_data' : 'add_school_data'))%></legend>
<%=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| %>
<div class="col_text">
<% if field.values[0][:type] != 'select' %>
<li class="col" for="<%=field.keys[0]%>"><%= t('olympiamanagement.'+field.keys[0]) %></li><li class="col_r"><input name="<%="[add_school_data][#{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"/></li>
<% else%>
<% @please_choice = (I18n.locale.to_s == "zh_tw") ? "請選擇" : "Please select." %>
<li class="col" for="<%=field.keys[0]%>"><%= t('olympiamanagement.'+field.keys[0]) %></li><li class="col_r">
<select name="<%="[add_school_data][#{field.keys[0]}]"%>" id="<%=field.keys[0]%>" class="required" value="<%= @olympia_school_data_field[field.keys[0]] %>" ><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] + '</option>').html_safe %>
<% end %>
</select>
<% end %>
<% 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

@ -1,16 +1,16 @@
<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">
<fieldset class="fieldset_block class_setting_block">
<legend class="fieldset_title"><%=t('olympiamanagement.class_setting')%></legend>
<div class="col_text">
<li class="col" for="MinClass"><%= t('olympiamanagement.class_number')+"(#{t('olympiamanagement.spacing')})"%></li>
<li class="col_r"><input name="MinClass" type="text" id="MinClass" value="" size="5" class="col_input"></li>
<li class="col_r"><input name="MinClass" type="text" id="MinClass" size="5" class="col_input" <%= @ClassSettingField.nil? ? nil : "value=#{@ClassSettingField.class_number_range[0]}"%>></li>
<span style="float:left;">~</span>
<li class="col_r"><input name="MaxClass" type="text" id="MaxClass" value="" size="5" class="col_input"></li>
<li class="col_r"><input name="MaxClass" type="text" id="MaxClass" size="5" class="col_input" <%= @ClassSettingField.nil? ? nil : "value=#{@ClassSettingField.class_number_range[1]}"%>></li>
</div>
<div class="col_text">
<li class="col" for="Person"><%= t('olympiamanagement.enrollment_available') %></li><li class="col_r"><input name="Person" type="text" id="Person" value="" size="5" class="col_input"></li>
<li class="col" for="Person"><%= t('olympiamanagement.enrollment_available') %></li><li class="col_r"><input name="Person" type="text" id="Person" size="5" class="col_input" <%= @ClassSettingField.nil? ? nil : "value=#{@ClassSettingField.enrollment_available}"%>></li>
</div>
<div style="clear:both;"></div>
<input type="submit" name="Submit" value="<%=t('olympiamanagement.confirm')%>">
@ -25,5 +25,16 @@
</tr>
</thead>
<tbody>
<% @class_setting_list.each do |class_setting| %>
<tr>
<td><%= class_setting.class_number_range.join(' ~ ') %></td>
<td><%= class_setting.enrollment_available %></td>
<td>
<a href="<%=admin_olympiamanagements_class_setting_path+"?id=#{class_setting.id}"%>"><img src="/assets/edit.gif" alt="<%= t('olympiamanagement.edit') %>" align="top" width="24"><%= t('olympiamanagement.edit') %></a>
<a href="<%=admin_olympiamanagements_update_school_data_path+"?id=#{class_setting.id}&type=delete_class_setting"%>"><img src="/assets/trash.gif" alt="<%= t('olympiamanagement.delete') %>" align="top" width="24"><%= t('olympiamanagement.delete') %></a>
</td>
</tr>
<%end%>
</tbody>
</table>
</table>
<%=create_pagination(params[:page].to_i).html_safe%>

View File

@ -0,0 +1,44 @@
<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 search_block">
<legend class="fieldset_title"><%=t('olympiamanagement.search')%></legend>
<form>
<div class="col_text">
<li class="col" for="school_name"><%= t('olympiamanagement.school_name')%></li>
<li class="col_r"><input name="school_name" type="text" id="school_name" class="col_input" value="<%=params[:school_name].to_s%>"></li>
</div>
<div class="col_text">
<li class="col" for="school_code"><%= t('olympiamanagement.school_code') %></li><li class="col_r"><input name="school_code" type="text" id="school_code" class="col_input" value="<%=params[:school_code].to_s%>"></li>
</div>
<div style="clear:both;"></div>
<input type="submit" name="Submit" value="<%=t('olympiamanagement.submit')%>">
</form>
</fieldset>
<% th_name_list = ['school_name','school_code','class_number','enrollment','account_number','action']%>
<table cellspacing="0" class="ts_rowsonly" width="100%" id="RSS_Table_page_contest_admin_1">
<thead>
<tr>
<% th_name_list.each do |th_name|%>
<th><%= t('olympiamanagement.'+th_name) %></th>
<% end %>
</tr>
</thead>
<tbody>
<% @OlympiaSchoolDataFields.each do |field| %>
<tr>
<% th_name_list.each do |th_name|%>
<%if th_name != 'action'%>
<td><%= field[th_name]%></td>
<% else %>
<td>
<a href="<%=admin_olympiamanagements_add_school_data_path+"?id=#{field.id}"%>"><img src="/assets/edit.gif" alt="<%= t('olympiamanagement.edit') %>" align="top" width="24"><%= t('olympiamanagement.edit') %></a>
<a href="<%=admin_olympiamanagements_update_school_data_path+"?id=#{field.id}&type=delete_school_data"%>"><img src="/assets/trash.gif" alt="<%= t('olympiamanagement.delete') %>" align="top" width="24"><%= t('olympiamanagement.delete') %></a>
</td>
<% end %>
<% end %>
</tr>
<%end%>
</tbody>
</table>
<%=create_pagination(params[:page].to_i,OlympiaSchoolDataFields).html_safe%>

View File

@ -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');
});

View File

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

View File

@ -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: 刪除
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: 下一頁

View File

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

View File

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