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