$(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: 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); $(element).datepicker(options); $(element).find('.start-date').datepicker().on('changeDate', function (e) { $(element).find('.end-date').datepicker('setStartDate', e.date); }); }; // 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); // }); // }; defineDateRangeSelect('.teaching-mode-date'); defineDateRangeSelect('.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 || $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'); } if ($techEndTime.val() === undefined || $techEndTime.val().length === 0) { $techEndTime.addClass('danger text-danger'); valid = false; } else { $techEndTime.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 () { //MD编辑 $("#MD_typeFrom").on("click",".add_MD_type",function () { var length=$(".MD_type").find(".add_MD_type").length + 1; var html='
\n' + '
\n' + ' \n' + '
\n' + '
\n' + '
\n' + ' \n' + ' \n' + '
'; $("#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='
\n' + '
\n' + ' \n' + '
\n' + '
\n' + '
\n' + '
\n' + ' \n' + ' \n' + '
' $("#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='
\n' + '
  
\n' + '
\n' + ' \n' + '
\n' + ' ~\n' + '
\n' + ' \n' + '
\n' + ' \n' + '
\n' + ' \n' + '
\n' + '
\n' + ' \n' + '
\n' + '
\n' + ' \n' + ' \n' + ' \n' + ' \n' + '
\n' + '
'; $("#requireForm").append(html); }) $("#requireForm").on("click",".delRequrieBtn",function () { $(this).parents(".requireForm_item").remove(); }) })