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

91 lines
3.4 KiB

5 years ago
$(document).on('turbolinks:load', function(){
if ($('body.admins-competition-settings-index-page').length > 0) {
var baseOptions = {
autoclose: true,
language: 'zh-CN',
format: 'yyyy-mm-dd',
5 years ago
startDate: '2017-04-01'
5 years ago
};
var defineDateRangeSelect = function(element){
var options = $.extend({inputs: $(element).find('.start-date, .end-date')}, baseOptions);
$(element).datepicker(options);
$(element).find('.start-date').datepicker().on('changeDate', function(e){
$(element).find('.end-date').datepicker('setStartDate', e.date);
});
};
defineDateRangeSelect('.teaching-mode-date');
5 years ago
defineDateRangeSelect('.competition-start-end-date');
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(){
$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) {
var $courseId = $("input[name='course_id'");
if($courseId.val() === undefined || $course_id.val().length === 0){
$courseId.addClass('danger text-danger');
valid = false;
} else {
$courseId.removeClass('danger text-danger');
}
} else if ($("input[name='mode'[checked]]").val() == 4) {
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');
}
5 years ago
5 years ago
if($techEndTime.val() === undefined || $techEndTime.val().length === 0){
$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
if(!valid) return;
$.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,
success: function(data){
$.notify({ message: '保存成功' });
window.location.reload();
},
error: function(res){
var data = res.responseJSON;
$form.find('.error').html(data.message);
},
complete: function(){
$form.find('.submit-btn').attr('disabled', false);
}
});
});
5 years ago
});