You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
educoder/app/assets/javascripts/admins/competition_settings/index.js

200 lines
9.2 KiB

5 years ago
$(document).on('turbolinks:load', function(){
if ($('body.admins-competition-settings-index-page').length > 0) {
5 years ago
var dateOptions = {
5 years ago
autoclose: true,
language: 'zh-CN',
format: 'yyyy-mm-dd',
5 years ago
startDate: '2017-04-01'
5 years ago
};
5 years ago
var timeOptions = {
autoclose: true,
language: 'zh-CN',
format: 'yyyy-mm-dd hh:ii:ss',
minuteStep: 30
};
var defineDateRangeSelect = function (element) {
var options = $.extend({inputs: $(element).find('.start-date, .end-date')}, dateOptions);
5 years ago
$(element).datepicker(options);
5 years ago
$(element).find('.start-date').datepicker().on('changeDate', function (e) {
5 years ago
$(element).find('.end-date').datepicker('setStartDate', e.date);
});
};
5 years ago
// var defineTimeRangeSelect = function (element) {
// var options = $.extend({inputs: $(element).find('.start-date, .end-date')}, timeOptions);
// $(element).datetimepicker(options);
//
// $(element).find('.start-date').datetimepicker().on('changeDate', function (e) {
// $(element).find('.end-date').datetimepicker('setStartDate', e.date);
// });
// };
5 years ago
5 years ago
defineDateRangeSelect('.teaching-mode-date');
5 years ago
defineDateRangeSelect('.competition-start-end-date');
5 years ago
5 years ago
var $basicForm = $('form.basic-setting-form');
5 years ago
5 years ago
$basicForm.validate({
5 years ago
errorElement: 'span',
errorClass: 'danger text-danger',
rules: {
name: "required",
subTitle: "required",
startTime: "required",
endTime: "required",
mode: "required",
identifier: "required"
}
});
// 保存按钮
5 years ago
$basicForm.on('click', ".submit-btn", function () {
5 years ago
$basicForm.find('.submit-btn').attr('disabled', 'disabled');
$basicForm.find('.error').html('');
var valid = $basicForm.valid();
5 years ago
5 years ago
if ($("input[name='mode']:checked").val() == 2) {
5 years ago
var $courseId = $("input[name='course_id'");
5 years ago
if ($courseId.val() === undefined || $course_id.val().length === 0) {
5 years ago
$courseId.addClass('danger text-danger');
valid = false;
} else {
$courseId.removeClass('danger text-danger');
}
5 years ago
} else if ($("input[name='mode']:checked").val() == 4) {
5 years ago
var $techStartTime = $("input[name='teach_start_time'");
var $techEndTime = $("input[name='teach_end_time'");
5 years ago
if ($techStartTime.val() === undefined || $techStartTime.val().length === 0) {
5 years ago
$techStartTime.addClass('danger text-danger');
valid = false;
} else {
$techStartTime.removeClass('danger text-danger');
}
5 years ago
5 years ago
if ($techEndTime.val() === undefined || $techEndTime.val().length === 0) {
5 years ago
$techEndTime.addClass('danger text-danger');
5 years ago
valid = false;
} else {
5 years ago
$techEndTime.removeClass('danger text-danger');
5 years ago
}
5 years ago
}
5 years ago
5 years ago
if (!valid) return;
5 years ago
$.ajax({
5 years ago
method: 'POST',
5 years ago
dataType: 'json',
5 years ago
url: $basicForm.attr('action'),
data: new FormData($basicForm[0]),
5 years ago
processData: false,
contentType: false,
5 years ago
success: function (data) {
$.notify({message: '保存成功'});
// window.location.reload();
5 years ago
},
5 years ago
error: function (res) {
5 years ago
var data = res.responseJSON;
5 years ago
$basicForm.find('.error').html(data.message);
5 years ago
},
5 years ago
complete: function () {
5 years ago
$basicForm.find('.submit-btn').attr('disabled', false);
5 years ago
}
});
});
5 years ago
}
});
$(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+'">&nbsp;</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();
})
//链接
$("#linkForm").on("click",".add_linkBtn",function () {
var length=$("#linkForm").find(".linkFormItem").length + 1;
var html='<div class="row mt-2 lineFromItem">\n' +
' <div class="col-1 text-right">\n' +
' <label class="checkbox checkbox-primary mt-1">\n' +
' <input id="link_'+length+'" type="checkbox" name="link_'+length+'" />\n' +
' <label for="link_'+length+'">&nbsp;</label>\n' +
' </label>\n' +
' </div>\n' +
' <div class="col-md-label mt-1"><input type="text" name="link_name_'+length+'" class="form-control"></div>\n' +
' <div class="col-md-1 mt-1"><input type="text" name="link_index_'+length+'" class="form-control"></div>\n' +
' <div class="col-md-3 mt-1"><input type="text" name="link_info_'+length+'" class="form-control"></div>\n' +
' <button class="btn btn-primary waves-effect waves-light btn-xs setBtn_s add_linkBtn">+</button>\n' +
' <button class="btn btn-icon waves-effect btn-default waves-light setBtn_s ml10 del_linkBtn">×</button>\n' +
' </div>'
$("#linkForm").append(html)
})
$("#linkForm").on("click",".del_linkBtn",function () {
$(this).parents(".lineFromItem").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">&nbsp;&nbsp;</div>\n' +
' <div class="col-1 text-left mt-1">\n' +
' <input type="text" class="form-control" name="min_'+length+'" />\n' +
' </div>\n' +
' <span class="mt-2">~</span>\n' +
' <div class="col-1 mt-1">\n' +
' <input type="text" class="form-control" name="max_'+length+'" />\n' +
' </div>\n' +
' <span class="mt-2">人</span>\n' +
' <div class="col-2 mt-1">\n' +
' <select class="form-control" name="choice_'+length+'" >\n' +
' <option>不限</option>\n' +
' <option>教师</option>\n' +
' <option>学生</option>\n' +
' <option>专业人士</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" name="require_1" type="radio">\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" name="require_1" type="radio">\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();
})
})