|
|
$(document).on('turbolinks:load', function(){
|
|
|
if ($('body.admins-competition-settings-index-page').length > 0) {
|
|
|
|
|
|
var dateOptions = {
|
|
|
autoclose: true,
|
|
|
language: 'zh-CN',
|
|
|
format: 'yyyy-mm-dd',
|
|
|
startDate: '2017-04-01'
|
|
|
};
|
|
|
|
|
|
var timeOptions = {
|
|
|
autoclose: 1,
|
|
|
language: 'zh-CN',
|
|
|
format: 'yyyy-mm-dd hh:ii',
|
|
|
minuteStep: 30
|
|
|
};
|
|
|
|
|
|
var defineDateRangeSelect = function (element) {
|
|
|
var options = $.extend({inputs: $(element).find('.start-date, .end-date')}, dateOptions);
|
|
|
$(element).datepicker(options);
|
|
|
|
|
|
$(element).find('.start-date').datepicker().on('changeDate', function (e) {
|
|
|
$(element).find('.end-date').datepicker('setStartDate', e.date);
|
|
|
});
|
|
|
};
|
|
|
$(".competition-start-end-date .start-date").datetimepicker(timeOptions);
|
|
|
|
|
|
$(".competition-start-end-date .end-date").datetimepicker(timeOptions);
|
|
|
|
|
|
$(".nav-setting-form .enroll_end_time").datetimepicker(timeOptions);
|
|
|
|
|
|
$(".stage-update-form .section-start-time").datetimepicker(timeOptions);
|
|
|
$(".stage-update-form .section-end-time").datetimepicker(timeOptions);
|
|
|
|
|
|
defineDateRangeSelect('.teaching-mode-date');
|
|
|
// defineTimeRangeSelect('.competition-start-end-date');
|
|
|
|
|
|
var $basicForm = $('form.basic-setting-form');
|
|
|
|
|
|
$basicForm.validate({
|
|
|
errorElement: 'span',
|
|
|
errorClass: 'danger text-danger',
|
|
|
rules: {
|
|
|
name: "required",
|
|
|
subTitle: "required",
|
|
|
startTime: "required",
|
|
|
endTime: "required",
|
|
|
mode: "required",
|
|
|
identifier: "required"
|
|
|
}
|
|
|
});
|
|
|
|
|
|
// 保存按钮
|
|
|
$basicForm.on('click', ".submit-btn", function () {
|
|
|
$basicForm.find('.submit-btn').attr('disabled', 'disabled');
|
|
|
$basicForm.find('.error').html('');
|
|
|
var valid = $basicForm.valid();
|
|
|
|
|
|
if ($("input[name='mode']:checked").val() == 2) {
|
|
|
var $courseId = $("input[name='course_id'");
|
|
|
if ($courseId.val() === undefined || $courseId.val().length === 0) {
|
|
|
$courseId.addClass('danger text-danger');
|
|
|
valid = false;
|
|
|
} else {
|
|
|
$courseId.removeClass('danger text-danger');
|
|
|
}
|
|
|
} else if ($("input[name='mode']:checked").val() == 3) {
|
|
|
var $techStartTime = $("input[name='teach_start_time'");
|
|
|
var $techEndTime = $("input[name='teach_end_time'");
|
|
|
if ($techStartTime.val() === undefined || $techStartTime.val().length === 0) {
|
|
|
$techStartTime.addClass('danger text-danger');
|
|
|
valid = false;
|
|
|
} else {
|
|
|
$techStartTime.removeClass('danger text-danger');
|
|
|
}
|
|
|
|
|
|
if ($techEndTime.val() === undefined || $techEndTime.val().length === 0) {
|
|
|
$techEndTime.addClass('danger text-danger');
|
|
|
valid = false;
|
|
|
} else {
|
|
|
$techEndTime.removeClass('danger text-danger');
|
|
|
}
|
|
|
} else {
|
|
|
$("input[name='course_id'").removeClass('danger text-danger');
|
|
|
$("input[name='teach_start_time'").removeClass('danger text-danger');
|
|
|
$("input[name='teach_end_time'").removeClass('danger text-danger');
|
|
|
}
|
|
|
|
|
|
if (!valid) return;
|
|
|
$.ajax({
|
|
|
method: 'POST',
|
|
|
dataType: 'json',
|
|
|
url: $basicForm.attr('action'),
|
|
|
data: new FormData($basicForm[0]),
|
|
|
processData: false,
|
|
|
contentType: false,
|
|
|
success: function (data) {
|
|
|
$.notify({message: '保存成功'});
|
|
|
// window.location.reload();
|
|
|
},
|
|
|
error: function (res) {
|
|
|
var data = res.responseJSON;
|
|
|
$basicForm.find('.error').html(data.message);
|
|
|
},
|
|
|
complete: function () {
|
|
|
$basicForm.find('.submit-btn').attr('disabled', false);
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
|
|
|
//添加主办方或者开放范围
|
|
|
function addSponsor(item){
|
|
|
var html='<div class="sponsor_label">\n' +
|
|
|
' <input type="hidden" value="school_id" />\n' +
|
|
|
' <span>caicai</span>\n' +
|
|
|
' <a href="javascript:void(0)" onclick="del_sponsor(this)">×</a>\n' +
|
|
|
' </div>';
|
|
|
$(item).parents(".sponsorPanel").append(html);
|
|
|
}
|
|
|
//删除
|
|
|
function del_sponsor(item){
|
|
|
$(item).parents(".sponsor_label").remove();
|
|
|
}
|
|
|
|
|
|
$(function () {
|
|
|
//MD编辑
|
|
|
// $("#MD_typeFrom").on("click",".add_MD_type",function () {
|
|
|
//
|
|
|
// var length=$(".MD_type").find(".add_MD_type").length + 1;
|
|
|
// var html='<div class="row MD_type mt-2">\n' +
|
|
|
// ' <div class="col-1 text-right">\n' +
|
|
|
// ' <label class="checkbox checkbox-primary mt-1">\n' +
|
|
|
// ' <input id="checkbox_MD_'+length+'" type="checkbox" name="checkbox_MD_'+length+'">\n' +
|
|
|
// ' <label for="checkbox_MD_'+length+'"> </label>\n' +
|
|
|
// ' </label>\n' +
|
|
|
// ' </div>\n' +
|
|
|
// ' <div class="col-md-4"><input type="text" class="form-control" name="MD_type_value_'+length+'" placeholder="导航名称"></div>\n' +
|
|
|
// ' <div class="col-md-1"><input type="text" class="form-control" name="MD_type_index_'+length+'" /></div>\n' +
|
|
|
// ' <button class="btn btn-primary waves-effect waves-light btn-xs setBtn_s add_MD_type">+</button>\n' +
|
|
|
// ' <button class="btn btn-icon waves-effect btn-default waves-light setBtn_s ml10 del_MD_type">×</button>\n' +
|
|
|
// ' </div>';
|
|
|
// $("#MD_typeFrom").append(html);
|
|
|
// })
|
|
|
// $("#MD_typeFrom").on("click",".del_MD_type",function () {
|
|
|
// $(this).parents(".MD_type").remove();
|
|
|
// })
|
|
|
|
|
|
//链接
|
|
|
$(".nav-setting-form").on("click",".add_linkBtn",function () {
|
|
|
var length=$(".nav-setting-form").find(".linkFormItem").length + 1;
|
|
|
var html='<div class="row mt-2 align-items-center linkFormItem">\n' +
|
|
|
' <div class="col-1 text-right">\n' +
|
|
|
' <label class="checkbox checkbox-primary mt-1">\n' +
|
|
|
' <input type="checkbox" name="navbar[][hidden]" value="0" class="font-16" checked="checked">\n' +
|
|
|
' </label>\n' +
|
|
|
' </div>\n' +
|
|
|
' <div class="col-md-label mt-1"><input type="hidden" value="md" name="navbar[][module_type]">\n' +
|
|
|
' <input type="text" name="navbar[][name]" value="" class="form-control" placeholder="模块名称"></div>\n' +
|
|
|
' <div class="col-md-1 mt-1"><input type="text" name="navbar[][position]" value="" class="form-control" placeholder="位置"></div>\n' +
|
|
|
' <div class="col-md-3 mt-1"><input type="text" name="navbar[][url]" value="" class="form-control" placeholder="请输入资料下载地址"></div>\n' +
|
|
|
' <a class="mt-1 btn btn-primary waves-effect waves-light btn-xs setBtn_s add_linkBtn" href="javascript:void(0)">+</a>\n' +
|
|
|
' <a class="mt-1 btn btn-icon waves-effect btn-default waves-light setBtn_s ml10 del_linkBtn" href="javascript:void(0)">×</a>\n' +
|
|
|
' </div>';
|
|
|
$(this).parents(".linkFormItem").after(html);
|
|
|
});
|
|
|
|
|
|
$(".nav-setting-form").on("click", ".del_linkBtn", function () {
|
|
|
$(this).parents(".linkFormItem").remove();
|
|
|
});
|
|
|
|
|
|
//有关报名要求
|
|
|
$(".addRequireBtn").on("click",function () {
|
|
|
var length=$("#requireForm").find(".requireForm_item").length + 1;
|
|
|
var html='<div class="row mt-2 mb-4 requireForm_item">\n' +
|
|
|
' <div class="col-1 text-right"> </div>\n' +
|
|
|
' <div class="col-1 text-left mt-1">\n' +
|
|
|
' <input type="text" class="form-control" name="competition_staffs[][minimum]" value="0">\n' +
|
|
|
' </div>\n' +
|
|
|
' <span class="mt-2">~</span>\n' +
|
|
|
' <div class="col-1 mt-1">\n' +
|
|
|
' <input type="text" class="form-control" name="competition_staffs[][maximum]" value="1">\n' +
|
|
|
' </div>\n' +
|
|
|
' <span class="mt-2">人</span>\n' +
|
|
|
' <div class="col-2 mt-1">\n' +
|
|
|
' <select class="form-control" name="competition_staffs[][category]">\n' +
|
|
|
' <option value="student">学生</option>\n' +
|
|
|
' <option value="teacher">教师</option>\n' +
|
|
|
' </select>\n' +
|
|
|
' </div>\n' +
|
|
|
' <div class="col-2 mt-1">\n' +
|
|
|
' <label class="radio checkbox-primary mt-1" value="require_'+length+'_1">\n' +
|
|
|
' <input id="require_'+length+'_1" class="mutiple-limited-radio" value="false" checked name="competition_staffs[][mutiple_limited]" type="checkbox">\n' +
|
|
|
' <label for="require_'+length+'_1">可多次报名</label>\n' +
|
|
|
' </label>\n' +
|
|
|
' </div>\n' +
|
|
|
' <div class="col-2 mt-1">\n' +
|
|
|
' <label class="radio checkbox-primary mt-1" value="require_'+length+'_2">\n' +
|
|
|
' <input id="require_'+length+'_2" class="mutiple-limited-radio" value="true" name="competition_staffs[][mutiple_limited]" type="checkbox">\n' +
|
|
|
' <label for="require_'+length+'_2">不可多次报名</label>\n' +
|
|
|
' </label>\n' +
|
|
|
' <a href="javascript:void(0)" class="ml20 delRequrieBtn">\n' +
|
|
|
' <i class="fa fa-times-circle font-20 color-grey-c"></i>\n' +
|
|
|
' </a>\n' +
|
|
|
' </div>\n' +
|
|
|
' </div>';
|
|
|
$("#requireForm").append(html);
|
|
|
});
|
|
|
|
|
|
$("#requireForm").on("click",".delRequrieBtn",function () {
|
|
|
$(this).parents(".requireForm_item").remove();
|
|
|
});
|
|
|
|
|
|
$('.competition-staff-settings').on('click', '.mutiple-limited-radio', function(){
|
|
|
var radio = $(this);
|
|
|
if (radio.is(':checked')) {
|
|
|
radio.parent().parent().siblings().find('.mutiple-limited-radio').attr('checked', false)
|
|
|
} else {
|
|
|
radio.parent().parent().siblings().find('.mutiple-limited-radio').attr('checked', true)
|
|
|
}
|
|
|
});
|
|
|
|
|
|
var $navForm = $('form.nav-setting-form');
|
|
|
$navForm.on('click', ".submit-btn", function () {
|
|
|
$navForm.find('.submit-btn').attr('disabled', 'disabled');
|
|
|
$navForm.find('.error').html('');
|
|
|
var valid = $navForm.valid();
|
|
|
|
|
|
if (!valid) return;
|
|
|
$.ajax({
|
|
|
method: 'POST',
|
|
|
dataType: 'json',
|
|
|
url: $navForm.attr('action'),
|
|
|
data: new FormData($navForm[0]),
|
|
|
processData: false,
|
|
|
contentType: false,
|
|
|
success: function (data) {
|
|
|
$.notify({message: '保存成功'});
|
|
|
// window.location.reload();
|
|
|
},
|
|
|
error: function (res) {
|
|
|
var data = res.responseJSON;
|
|
|
$navForm.find('.error').html(data.message);
|
|
|
},
|
|
|
complete: function () {
|
|
|
$navForm.find('.submit-btn').attr('disabled', false);
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
|
|
|
// 排行榜设置
|
|
|
//删除小阶段
|
|
|
$("#large_panel").on("click",".small_panel_item_del",function () {
|
|
|
var list = $(this).parents(".small_panel");
|
|
|
$(this).parents(".small_panel_item").remove();
|
|
|
|
|
|
for(var i=0;i < $(list).find(".subName").length;i++){
|
|
|
console.log(i);
|
|
|
$(list).find(".subName").eq(i).html("第"+parseInt(i+1)+"阶段");
|
|
|
}
|
|
|
});
|
|
|
|
|
|
$('form.stage-update-form').validate({
|
|
|
errorElement: 'span',
|
|
|
errorClass: 'danger text-danger',
|
|
|
rules: {
|
|
|
stage_name: "required",
|
|
|
"stage[][start_time]": "required",
|
|
|
"stage[][end_time]": "required",
|
|
|
"stage[][mission_count]": {
|
|
|
required: true,
|
|
|
min: 1
|
|
|
},
|
|
|
"stage[][entry]": {
|
|
|
required: true,
|
|
|
min: 1
|
|
|
},
|
|
|
score_rate: {
|
|
|
required: true,
|
|
|
range: [0, 100]
|
|
|
}
|
|
|
},
|
|
|
messages: {
|
|
|
"stage[][mission_count]": {
|
|
|
min: ">=1"
|
|
|
},
|
|
|
"stage[][entry]": {
|
|
|
min: ">=1"
|
|
|
},
|
|
|
}
|
|
|
});
|
|
|
|
|
|
$('form.stage-update-form').on('click', ".update-stage", function () {
|
|
|
var updateForm = $(this).parents("form");
|
|
|
$(this).attr('disabled', 'disabled');
|
|
|
updateForm.find('.error').html('');
|
|
|
var valid = updateForm.valid();
|
|
|
|
|
|
updateForm.find('input[name="stage[][identifiers][]"]').each(function(_, e){
|
|
|
var $ele = $(e);
|
|
|
if($ele.val() === undefined || $ele.val().length === 0){
|
|
|
$ele.addClass('danger text-danger');
|
|
|
valid = false;
|
|
|
} else {
|
|
|
$ele.removeClass('danger text-danger');
|
|
|
}
|
|
|
});
|
|
|
|
|
|
if (!valid) return;
|
|
|
|
|
|
updateForm.find('input[name="stage[][mission_count]"]').each(function(_, e){
|
|
|
var $missionCount = $(e);
|
|
|
var $entryCount = $(e).parents("div.row").find('input[name="stage[][mission_count]"]');
|
|
|
if(parseInt($missionCount.val()) > parseInt($entryCount.val()) ){
|
|
|
$missionCount.addClass('danger text-danger');
|
|
|
$missionCount.after('<span class="danger text-danger">不能大于总任务数</span>');
|
|
|
valid = false;
|
|
|
} else {
|
|
|
$missionCount.removeClass('danger text-danger');
|
|
|
$missionCount.siblings().remove();
|
|
|
}
|
|
|
});
|
|
|
|
|
|
$.ajax({
|
|
|
method: 'POST',
|
|
|
dataType: 'json',
|
|
|
url: updateForm.attr('action'),
|
|
|
data: new FormData(updateForm[0]),
|
|
|
processData: false,
|
|
|
contentType: false,
|
|
|
success: function (data) {
|
|
|
$.notify({message: '保存成功'});
|
|
|
// window.location.reload();
|
|
|
},
|
|
|
error: function (res) {
|
|
|
var data = res.responseJSON;
|
|
|
$navForm.find('.error').html(data.message);
|
|
|
},
|
|
|
complete: function () {
|
|
|
$navForm.find('.submit-btn').attr('disabled', false);
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
//新增子阶段
|
|
|
function add_task_sub(item){
|
|
|
var index = $(item).parents(".large_panel_part").attr("attr_line");
|
|
|
var count= 0;
|
|
|
|
|
|
console.log("sdfsf");
|
|
|
console.log($("#small_panel_"+index).find(".small_panel_item").length > 0);
|
|
|
|
|
|
if($("#small_panel_"+index).find(".small_panel_item").length > 0){
|
|
|
count = parseInt($("#small_panel_"+index).find(".small_panel_item").last().attr("count")) + 1;
|
|
|
|
|
|
console.log($("#small_panel_"+index).find(".small_panel_item").last().attr("count"));
|
|
|
}else{
|
|
|
count = 1;
|
|
|
}
|
|
|
|
|
|
var showCount=parseInt($("#small_panel_"+index).find(".small_panel_item").length) + 1;
|
|
|
|
|
|
|
|
|
var html='<div class="row d-flex small_panel_item" attr_line="sub_'+index+'_'+count+'" count="'+count+'">\n' +
|
|
|
' <span class="col-1 mt-2 subName">第'+showCount+'阶段</span>\n' +
|
|
|
' <div class="flex-1">\n' +
|
|
|
' <div class="row">\n' +
|
|
|
' <span class="mt-2 ml20">有效时间:</span>\n' +
|
|
|
' <div class="col-2 no_padding input_middle">\n' +
|
|
|
' <input class="use_time_begin_'+index+'_'+count+' form-control" placeholder="有效开始时间"/>\n' +
|
|
|
' </div>\n' +
|
|
|
' <span class="mt-2">~</span>\n' +
|
|
|
' <div class="col-2 no_padding input_middle">\n' +
|
|
|
' <input class="use_time_end_'+index+'_'+count+' form-control" placeholder="有效结束时间"/>\n' +
|
|
|
' </div>\n' +
|
|
|
' <span class="col-2 text-right mt-2 no_padding">任务完成要求:</span>\n' +
|
|
|
' <div class="col-1 no_padding input_small">\n' +
|
|
|
' <input type="number" class="form-control" name="task_require_small_'+index+'_'+count+'"/>\n' +
|
|
|
' </div>\n' +
|
|
|
' <span class="mt-2 ml10 mr10">/</span>\n' +
|
|
|
' <div class="col-1 no_padding input_small">\n' +
|
|
|
' <input type="number" class="form-control task_all" onchange="change_total(this)" name="task_require_all_'+index+'_'+count+'"/>\n' +
|
|
|
' </div>\n' +
|
|
|
' <span class=" mt-2">(总任务)</span>\n' +
|
|
|
' <span class="col-1 text-right mt-2 no_padding">成绩来源:</span>\n' +
|
|
|
' <div class="col-2 no_padding input_middle">\n' +
|
|
|
' <select class="form-control" name="source_'+index+'_'+count+'">\n' +
|
|
|
' <option>经验值</option>\n' +
|
|
|
' <option>预测准确率</option>\n' +
|
|
|
' </select>\n' +
|
|
|
' </div>\n' +
|
|
|
' </div>\n' +
|
|
|
' <div class="row mt-2" id="task_Input_sub_'+index+'_'+count+'"></div>\n' +
|
|
|
' </div>\n' +
|
|
|
' <span>\n' +
|
|
|
' <a href="javascript:void(0)" class="btn btn-default ml20 small_panel_item_del">删除</a>\n' +
|
|
|
' </span>\n' +
|
|
|
' </div>';
|
|
|
$("#small_panel_"+index).append(html);
|
|
|
}
|
|
|
|
|
|
// 小阶段修改总任务数
|
|
|
function change_total(item) {
|
|
|
var count=parseInt($(item).val());
|
|
|
|
|
|
|
|
|
var index = $(item).parents(".small_panel_item").attr("attr_line");
|
|
|
var indexLarge = $(item).parents(".large_panel_part").attr("attr_line");
|
|
|
console.log(indexLarge);
|
|
|
console.log(index);
|
|
|
|
|
|
var divCount=parseInt($("#task_Input_"+index).find(".task_Input_div").length);
|
|
|
|
|
|
|
|
|
var html = "";
|
|
|
if(count > divCount){
|
|
|
for(var i=0;i < count-divCount ;i++){
|
|
|
html+='<div class="col-4 row task_Input_div"><span class="col-3 text-center mt-3">任务'+(divCount+i+1)+'</span>\n' +
|
|
|
'<div class="col-8">\n' +
|
|
|
'<input type="text" class="form-control mt-2" name="input_'+index+'_'+(divCount+i+1) +'" placeholder="请填写实训ID">\n' +
|
|
|
'</div>\n' +
|
|
|
'</div>';
|
|
|
}
|
|
|
$("#task_Input_"+index).append(html);
|
|
|
}else{
|
|
|
var delCount = divCount - count ;
|
|
|
console.log(divCount);
|
|
|
console.log(count);
|
|
|
var _max=parseInt($("#task_Input_"+index).find(".task_Input_div:last").index());
|
|
|
|
|
|
console.log(_max);
|
|
|
var _get= _max - delCount;
|
|
|
|
|
|
console.log(_get);
|
|
|
if(count == 0){
|
|
|
$("#task_Input_"+index).empty();
|
|
|
}else{
|
|
|
$("#task_Input_"+index).find(".task_Input_div:gt("+_get+")").remove();
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//删除tab
|
|
|
function Del_tab(item) {
|
|
|
$(item).parents(".large_panel_part").remove();
|
|
|
}
|
|
|
//新增tab
|
|
|
function addNewTab() {
|
|
|
var count = parseInt($("#large_panel").find(".large_panel_part").length)+1;
|
|
|
var html = '<div class="large_panel_part" attr_line="'+count+'"><div class="row d-flex mt-3">\n' +
|
|
|
' <span class="col-1 mt-2">tab标题</span>\n' +
|
|
|
' <div class="col-2 no_padding">\n' +
|
|
|
' <input type="text" class="form-control" name="stage_name"/>\n' +
|
|
|
' </div>\n' +
|
|
|
' <span class="col-1 text-right mt-2 no_padding">总排行榜占比:</span>\n' +
|
|
|
' <div class="col-1 no_padding">\n' +
|
|
|
' <input type="number" class="form-control" name="score_rate" value="100"/>\n' +
|
|
|
' </div><span class=" mt-2">%</span>\n' +
|
|
|
' <div class="flex-1">\n' +
|
|
|
' <a href="javascript:void(0)"class="btn btn-outline-primary export-action ml20 add_task_sub" onclick="add_task_sub(this)">新增子阶段</a>\n' +
|
|
|
' </div>\n' +
|
|
|
' <a href="javascript:void(0)" class="btn btn-default ml20" onclick="Del_tab(this)">删除</a>\n' +
|
|
|
' <a href="javascript:void(0)" class="btn btn-outline-primary export-action ml20">保存</a>\n' +
|
|
|
' </div>\n' +
|
|
|
' <div id="small_panel_'+count+'" class="small_panel"></div></div>';
|
|
|
$("#large_panel").append(html);
|
|
|
|
|
|
} |