competition staff setting

dev_bj
p31729568 6 years ago
parent c2dee3b831
commit 070be6e895

@ -458,41 +458,51 @@ class CompetitionsController < ApplicationController
def competition_setting
# @competition = Competition.find params[:id]
if params[:md_name]
md_modules = @competition.competition_modules.where(:md_edit => true)
md_modules.destroy_all if md_modules
params[:md_name].each_with_index do |name, index|
hidden = params[:md_checked][index].to_i == 0 ? 1 : 0
cm = CompetitionModule.create(:competition_id => @competition.id,:name => name, :position => params[:md_position][index], :hidden => hidden, :md_edit => true)
# 创建md_contents
CompetitionModuleMdContent.create(:competition_module_id => cm.id)
ActiveRecord::Base.transaction do
if params[:md_name]
md_modules = @competition.competition_modules.where(:md_edit => true)
md_modules.destroy_all if md_modules
params[:md_name].each_with_index do |name, index|
hidden = params[:md_checked][index].to_i == 0 ? 1 : 0
cm = CompetitionModule.create(:competition_id => @competition.id,:name => name, :position => params[:md_position][index], :hidden => hidden, :md_edit => true)
# 创建md_contents
CompetitionModuleMdContent.create(:competition_module_id => cm.id)
end
end
end
if params[:competition_module]
@competition.competition_modules.where(:id => params[:competition_module], :md_edit => false).update_all(:hidden => 0)
none_modules = @competition.competition_modules.where("name != '首页' and md_edit = false").map(&:id).join(",").split(",") - params[:competition_module]
@competition.competition_modules.where(:id => none_modules).update_all(:hidden => 1)
end
if params[:name]
@competition.competition_modules.where("name not in ('首页', '报名', '通知公告', '排行榜', '资料下载') and md_edit = false").each_with_index do |mod, index|
mod.update_attribute("name", params[:name][index])
if params[:competition_module]
@competition.competition_modules.where(:id => params[:competition_module], :md_edit => false).update_all(:hidden => 0)
none_modules = @competition.competition_modules.where("name != '首页' and md_edit = false").map(&:id).join(",").split(",") - params[:competition_module]
@competition.competition_modules.where(:id => none_modules).update_all(:hidden => 1)
end
end
if params[:url]
@competition.competition_modules.where("name not in ('首页', '报名', '通知公告', '排行榜') and md_edit = false").each_with_index do |mod, index|
mod.update_attribute("url", params[:url][index])
if params[:name]
@competition.competition_modules.where("name not in ('首页', '报名', '通知公告', '排行榜', '资料下载') and md_edit = false").each_with_index do |mod, index|
mod.update_attribute("name", params[:name][index])
end
end
end
if params[:position]
@competition.competition_modules.where(:md_edit => false).each_with_index do |mod, index|
mod.update_attribute("position", params[:position][index])
if params[:url]
@competition.competition_modules.where("name not in ('首页', '报名', '通知公告', '排行榜') and md_edit = false").each_with_index do |mod, index|
mod.update_attribute("url", params[:url][index])
end
end
end
@competition.update_attributes(:identifier => params[:identifier], :min_num => params[:min_num], :max_num => params[:max_num], :enroll_end_time => params[:enroll_end_time])
if params[:new_name]
params[:new_name].each_with_index do |new_module, index|
@competition.competition_modules << CompetitionModule.new(:name => new_module, :position => params[:new_position][index], :hidden => 0, :url => params[:new_url][index])
if params[:position]
@competition.competition_modules.where(:md_edit => false).each_with_index do |mod, index|
mod.update_attribute("position", params[:position][index])
end
end
@competition.update_attributes(:identifier => params[:identifier], :enroll_end_time => params[:enroll_end_time])
if params[:competition_staffs].present?
@competition.competition_staffs.delete_all
params[:competition_staffs].each_with_index do |staff_params, index|
@competition.competition_staffs.create(staff_params.merge(position: index + 1))
end
end
if params[:new_name]
params[:new_name].each_with_index do |new_module, index|
@competition.competition_modules << CompetitionModule.new(:name => new_module, :position => params[:new_position][index], :hidden => 0, :url => params[:new_url][index])
end
end
end
end

@ -13,6 +13,7 @@ class Competition < ActiveRecord::Base
has_many :chart_rules, :dependent => :destroy
has_many :competition_scores, :dependent => :destroy
has_many :competition_text_configs, :dependent => :destroy
has_many :competition_staffs, dependent: :destroy
acts_as_attachable
after_create :create_competition_modules

@ -0,0 +1,22 @@
class CompetitionStaff < ActiveRecord::Base
default_scope order: 'position asc'
attr_accessible :minimum, :maximum, :category, :position
belongs_to :competition
validates :position, numericality: { only_integer: true }
validates :minimum, numericality: { only_integer: true, greater_than: 0 }
validates :maximum, numericality: { only_integer: true, greater_than_or_equal_to: lambda { |obj| obj.minimum } }
validates :category, presence: true, inclusion: { in: %w(all teacher student profession) }
def category_text
I18n.t("competition_staff.category.#{category}", locale: 'zh')
end
def self.category_options
%w(all teacher student profession).map do |category|
[I18n.t("competition_staff.category.#{category}", locale: 'zh'), category]
end
end
end

@ -68,13 +68,29 @@
<% end %>
<% if com_module.name == "报名" %>
<div class="fl ContentFillinthebox">
<input type="text" autocomplete="off" class="Other_boxinput" name="min_num" placeholder="1" value="<%= @competition.min_num %>"/> ~
<input type="text" autocomplete="off" class="Other_boxinput" name="max_num" placeholder="1" value="<%= @competition.max_num %>"/> 人
</div>
<div class="fl ml20">
<span>报名截止:</span>
<input type="text" class="winput-240-30" readonly placeholder="请选择截止时间" value="<%= format_time @competition.enroll_end_time %>" name="enroll_end_time" id="enroll_end_time"/>
<div class="fl">
<div class="ContentFillinthebox mb10">
<span>报名截止时间:</span>
<input type="text" class="winput-240-30" readonly placeholder="请选择截止时间" value="<%= format_time @competition.enroll_end_time %>" name="enroll_end_time" id="enroll_end_time"/>
</div>
<div class="competition-staff">
<div>报名要求:<i class="fa fa-plus-circle color-green font-16 ml10 add-competition-staff-btn"></i></div>
<div class="competition-staff-settings mb10 ml30">
<% @competition.competition_staffs.each do |staff| %>
<div class="competition-staff-row mb10">
<%= select_tag('competition_staffs[][category]', options_for_select(CompetitionStaff.category_options, staff.category), class: 'winput-120-30') %>
<input type="text" autocomplete="off" class="Other_boxinput" name="competition_staffs[][minimum]" required="required" value="<%= staff.minimum %>"/>
&nbsp;&nbsp;~&nbsp;&nbsp;
<input type="text" autocomplete="off" class="Other_boxinput" name="competition_staffs[][maximum]" required="required" value="<%= staff.maximum %>"/>
<span class="competition-staff-operate ml10">
<i class="fa fa-trash-o ml5 font-16 delete-icon"></i>
<i class="fa fa-plus-circle color-green font-16 ml10 add-icon"></i>
</span>
</div>
<% end %>
</div>
</div>
</div>
<% end %>
<% if com_module.name != "首页" && com_module.name != "报名" && com_module.name != "通知公告" && com_module.name != "排行榜" %>
@ -149,6 +165,20 @@
</div>
</div>
<div class="competition-staff-row-example" style="display: none">
<div class="competition-staff-row mb10">
<%= select_tag('competition_staffs[][category]', options_for_select(CompetitionStaff.category_options, ''), class: 'winput-120-30') %>
<input type="text" autocomplete="off" class="Other_boxinput" name="competition_staffs[][minimum]" require="required" value="1"/>
&nbsp;&nbsp;~&nbsp;&nbsp;
<input type="text" autocomplete="off" class="Other_boxinput" name="competition_staffs[][maximum]" required="required" value="1"/>
<span class="competition-staff-operate ml10">
<i class="fa fa-trash-o ml5 font-16 delete-icon"></i>
<i class="fa fa-plus-circle color-green font-16 ml10 add-icon"></i>
</span>
</div>
</div>
<% content_for :header_tags do %>
@ -504,4 +534,17 @@
}
})
}
$(function(){
$('.add-competition-staff-btn').on('click', function(){
$('.competition-staff-settings').append($('.competition-staff-row-example').html());
});
$('.competition-staff-settings').on('click', '.add-icon', function(){
$('.competition-staff-settings').append($('.competition-staff-row-example').html());
});
$('.competition-staff-settings').on('click', '.delete-icon', function(){
$(this).parents('.competition-staff-row').remove();
});
})
</script>

@ -0,0 +1,7 @@
'zh':
competition_staff:
category:
all: 不限
teacher: 教师
student: 学生
profession: 专业人士

@ -0,0 +1,13 @@
class CreateCompetitionStaffs < ActiveRecord::Migration
def change
create_table :competition_staffs do |t|
t.references :competition
t.integer :position
t.string :category
t.integer :minimum
t.integer :maximum
t.timestamps
end
end
end

@ -104,4 +104,8 @@ a:hover.edu-admin-nav-a,.active a.edu-admin-nav-a{color: #5faee3;}
/*超级管理员----技术体系*/
.createsystem{cursor: pointer;width: 100%;height: 70px;line-height: 70px;border:1px dashed #FF7500;color: #FF7500;text-align: center;margin:15px 0px 20px 0px;border-radius: 4px;}
.infoul li{list-style-type: disc}
.infoul li{list-style-type: disc}
/* 竞赛配置 */
.competition-staff-settings .competition-staff-row .competition-staff-operate .add-icon { display: none; }
.competition-staff-settings .competition-staff-row:last-child .competition-staff-operate .add-icon { display: inline; }
Loading…
Cancel
Save