mirror of
https://gitlink.org.cn/Gitlink/forgeplus.git
synced 2026-05-03 03:40:49 +08:00
init project
This commit is contained in:
130
app/assets/javascripts/cooperative/carousels/index.js
Normal file
130
app/assets/javascripts/cooperative/carousels/index.js
Normal file
@@ -0,0 +1,130 @@
|
||||
$(document).on('turbolinks:load', function() {
|
||||
if ($('body.cooperative-carousels-index-page').length > 0) {
|
||||
var resetNo = function(){
|
||||
$('#carousels-container .custom-carousel-item-no').each(function(index, ele){
|
||||
$(ele).html(index + 1);
|
||||
})
|
||||
}
|
||||
// 删除后
|
||||
$(document).on('delete_success', resetNo);
|
||||
// ------------ 保存链接 -----------
|
||||
$('.carousels-card').on('click', '.save-data-btn', function(){
|
||||
var $link = $(this);
|
||||
var id = $link.data('id');
|
||||
var link = $('.custom-carousel-item-' + id).find('.link-input').val();
|
||||
var name = $('.custom-carousel-item-' + id).find('.name-input').val();
|
||||
if(!name || name.length == 0){
|
||||
$.notify({ message: '名称不能为空' },{ type: 'danger' });
|
||||
return;
|
||||
}
|
||||
$link.attr('disabled', true);
|
||||
|
||||
$.ajax({
|
||||
url: '/cooperative/carousels/' + id,
|
||||
method: 'PATCH',
|
||||
dataType: 'json',
|
||||
data: { link: link, name: name },
|
||||
success: function(data){
|
||||
$.notify({ message: '操作成功' });
|
||||
},
|
||||
error: ajaxErrorNotifyHandler,
|
||||
complete: function(){
|
||||
$link.removeAttr('disabled');
|
||||
}
|
||||
})
|
||||
});
|
||||
// -------------- 是否在首页展示 --------------
|
||||
$('.carousels-card').on('change', '.online-check-box', function(){
|
||||
var $checkbox = $(this);
|
||||
var id = $checkbox.data('id');
|
||||
var checked = $checkbox.is(':checked');
|
||||
$checkbox.attr('disabled', true);
|
||||
|
||||
$.ajax({
|
||||
url: '/cooperative/carousels/' + id,
|
||||
method: 'PATCH',
|
||||
dataType: 'json',
|
||||
data: { status: checked },
|
||||
success: function(data){
|
||||
$.notify({ message: '保存成功' });
|
||||
var box = $('.custom-carousel-item-' + id).find('.drag');
|
||||
if(checked){
|
||||
box.removeClass('not_active');
|
||||
}else{
|
||||
box.addClass('not_active');
|
||||
}
|
||||
},
|
||||
error: ajaxErrorNotifyHandler,
|
||||
complete: function(){
|
||||
$checkbox.removeAttr('disabled');
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
// ------------ 拖拽 -------------
|
||||
var onDropFunc = function(el, _target, _source, sibling){
|
||||
var moveId = $(el).data('id');
|
||||
var insertId = $(sibling).data('id') || '';
|
||||
|
||||
$.ajax({
|
||||
url: '/cooperative/carousels/drag',
|
||||
method: 'POST',
|
||||
dataType: 'json',
|
||||
data: { move_id: moveId, after_id: insertId },
|
||||
success: function(data){
|
||||
resetNo();
|
||||
},
|
||||
error: function(res){
|
||||
var data = res.responseJSON;
|
||||
$.notify({message: '移动失败,原因:' + data.message}, {type: 'danger'});
|
||||
}
|
||||
})
|
||||
};
|
||||
var ele1 = document.getElementById('carousels-container');
|
||||
dragula([ele1], { mirrorContainer: ele1 }).on('drop', onDropFunc);
|
||||
|
||||
|
||||
// ----------- 新增 --------------
|
||||
var $createModal = $('.modal.cooperative-add-carousel-modal');
|
||||
var $createForm = $createModal.find('form.cooperative-add-carousel-form');
|
||||
|
||||
$createForm.validate({
|
||||
errorElement: 'span',
|
||||
errorClass: 'danger text-danger',
|
||||
rules: {
|
||||
"portal_image[image]": {
|
||||
required: true
|
||||
},
|
||||
"portal_image[name]": {
|
||||
required: true
|
||||
},
|
||||
}
|
||||
});
|
||||
|
||||
$createModal.on('show.bs.modal', function(event){
|
||||
resetFileInputFunc($createModal.find('.img-file-input'));
|
||||
$createModal.find('.file-names').html('选择文件');
|
||||
});
|
||||
|
||||
$createModal.on('click', '.submit-btn', function() {
|
||||
$createForm.find('.error').html('');
|
||||
|
||||
if ($createForm.valid()) {
|
||||
$createForm.submit();
|
||||
} else {
|
||||
$createForm.find('.error').html('请选择图片');
|
||||
}
|
||||
});
|
||||
$createModal.on('change', '.img-file-input', function(){
|
||||
var file = $(this)[0].files[0];
|
||||
$createModal.find('.file-names').html(file ? file.name : '请选择文件');
|
||||
})
|
||||
|
||||
// -------------- 重新上传图片 --------------
|
||||
//replace_image_url
|
||||
$('.modal.cooperative-upload-file-modal').on('upload:success', function(e, data){
|
||||
var $carouselItem = $('.custom-carousel-item-' + data.source_id);
|
||||
$carouselItem.find('.custom-carousel-item-img img').attr('src', data.url);
|
||||
})
|
||||
}
|
||||
})
|
||||
803
app/assets/javascripts/cooperative/competition_settings/index.js
Normal file
803
app/assets/javascripts/cooperative/competition_settings/index.js
Normal file
@@ -0,0 +1,803 @@
|
||||
$(document).on('turbolinks:load', function(){
|
||||
if ($('body.cooperative-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);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var selectOptions = {
|
||||
theme: 'bootstrap4',
|
||||
placeholder: '请输入要添加的单位名称',
|
||||
multiple: true,
|
||||
minimumInputLength: 1,
|
||||
ajax: {
|
||||
delay: 500,
|
||||
url: '/api/schools/search.json',
|
||||
dataType: 'json',
|
||||
data: function(params){
|
||||
return { keyword: params.term };
|
||||
},
|
||||
processResults: function(data){
|
||||
return { results: data.schools }
|
||||
}
|
||||
},
|
||||
templateResult: function (item) {
|
||||
if(!item.id || item.id === '') return item.text;
|
||||
return item.name || item.text;
|
||||
},
|
||||
templateSelection: function(item){
|
||||
return item.name || item.text;
|
||||
}
|
||||
};
|
||||
|
||||
$('.sponsor-select').select2(selectOptions);
|
||||
$('.allow-school-select').select2(selectOptions);
|
||||
|
||||
$('.manager-select').select2({
|
||||
theme: 'bootstrap4',
|
||||
placeholder: '请输入要添加的管理员姓名',
|
||||
multiple: true,
|
||||
minimumInputLength: 1,
|
||||
ajax: {
|
||||
delay: 500,
|
||||
url: '/cooperative/users',
|
||||
dataType: 'json',
|
||||
data: function(params){
|
||||
return { keyword: params.term };
|
||||
},
|
||||
processResults: function(data){
|
||||
return { results: data.users }
|
||||
}
|
||||
},
|
||||
templateResult: function (item) {
|
||||
if(!item.id || item.id === '') return item.text;
|
||||
return $("<div class='row px-0'><span class='col-3'>" + item.real_name + "</span><span class='col-5 font-12'>" + item.school_name + "</span><span class='col-4 font-12'>" + item.hidden_phone + "</span></div>");
|
||||
},
|
||||
templateSelection: function(item){
|
||||
if (item.id) {
|
||||
}
|
||||
return item.real_name || item.text;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// 排行榜
|
||||
//链接
|
||||
$(".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" hidden class="font-16" checked="checked">\n' +
|
||||
' <input type="checkbox" value="0" class="font-16 module_hidden" 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();
|
||||
});
|
||||
|
||||
$('.nav-setting-form').on('click', '.module_hidden', function(){
|
||||
var checkEle = $(this);
|
||||
if (checkEle.is(':checked')) {
|
||||
checkEle.prev().val(0);
|
||||
} else {
|
||||
checkEle.prev().val(1);
|
||||
}
|
||||
});
|
||||
|
||||
$('.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"
|
||||
// },
|
||||
// }
|
||||
// });
|
||||
|
||||
$('.competition-chart-setting').on('click', ".update-stage", function () {
|
||||
var updateForm = $(this).parents("form");
|
||||
$(this).attr('disabled', 'disabled');
|
||||
updateForm.find('.error').html('');
|
||||
// var valid = updateForm.valid();
|
||||
var valid = true;
|
||||
|
||||
var $stageName = updateForm.find('input[name="stage_name"]');
|
||||
if($stageName.val() === undefined || $stageName.val().length === 0){
|
||||
$stageName.addClass('danger text-danger');
|
||||
valid = false;
|
||||
} else {
|
||||
$stageName.removeClass('danger text-danger');
|
||||
}
|
||||
|
||||
var $scoreRate = updateForm.find('input[name="score_rate"]');
|
||||
if($scoreRate.val() === undefined || $scoreRate.val().length === 0){
|
||||
$scoreRate.addClass('danger text-danger');
|
||||
valid = false;
|
||||
} else if (parseInt($scoreRate.val()) > 100 || parseInt($scoreRate.val()) < 0) {
|
||||
$scoreRate.addClass('danger text-danger');
|
||||
$scoreRate.after('<span class="danger text-danger">0-100之间的数值</span>');
|
||||
valid = false;
|
||||
} else {
|
||||
$scoreRate.removeClass('danger text-danger');
|
||||
$scoreRate.siblings().remove();
|
||||
}
|
||||
|
||||
updateForm.find('input[name="stage[][start_time]"]').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');
|
||||
}
|
||||
});
|
||||
|
||||
updateForm.find('input[name="stage[][end_time]"]').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');
|
||||
}
|
||||
});
|
||||
|
||||
updateForm.find('input[name="stage[][mission_count]"]').each(function(i, e){
|
||||
var $ele = $(e);
|
||||
var $entry = updateForm.find('input[name="stage[][entry]"]').eq(i);
|
||||
if($ele.val() === undefined || $ele.val().length === 0){
|
||||
$ele.addClass('danger text-danger');
|
||||
valid = false;
|
||||
} else if (parseInt($ele.val()) < 1) {
|
||||
$ele.addClass('danger text-danger');
|
||||
$ele.after('<span class="danger text-danger">大于等于1</span>');
|
||||
valid = false;
|
||||
} else if (parseInt($ele.val()) > parseInt($entry.val())) {
|
||||
$ele.addClass('danger text-danger');
|
||||
$ele.after('<span class="danger text-danger">不能大于总任务数</span>');
|
||||
valid = false;
|
||||
} else {
|
||||
$ele.removeClass('danger text-danger');
|
||||
$ele.siblings().remove();
|
||||
}
|
||||
});
|
||||
|
||||
updateForm.find('input[name="stage[][entry]"]').each(function(_, e){
|
||||
var $ele = $(e);
|
||||
if($ele.val() === undefined || $ele.val().length === 0){
|
||||
$ele.addClass('danger text-danger');
|
||||
valid = false;
|
||||
} else if (parseInt($ele.val()) < 1) {
|
||||
$ele.addClass('danger text-danger');
|
||||
$ele.after('<span class="danger text-danger">大于等于1</span>');
|
||||
valid = false;
|
||||
} else {
|
||||
$ele.removeClass('danger text-danger');
|
||||
$ele.siblings().remove();
|
||||
}
|
||||
});
|
||||
|
||||
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);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$(".competition-chart-stages").on("click", ".add-new-tab", function () {
|
||||
if($(".new-stage-form").length > 0){
|
||||
alert("请先保存上一个tab");
|
||||
} else {
|
||||
var count = parseInt($("#large_panel").find(".large_panel_part").length)+1;
|
||||
var html = '<form class="stage-update-form new-stage-form flex-1" action="/cooperative/competitions/'+$(this).attr("data-competition-id")+'/competition_stages" accept-charset="UTF-8" data-remote="true" method="post">' +
|
||||
'<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">新增子阶段</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 update-stage export-action ml20">保存</a>\n' +
|
||||
' </div>\n' +
|
||||
' <div id="small_panel_'+count+'" class="small_panel">\n' +
|
||||
' <div class="row d-flex small_panel_item" attr_line="sub_new_new" count="1">\n' +
|
||||
' <span class="mt-2 subName mr10">第1阶段</span>\n' +
|
||||
' <div class="flex-1">\n' +
|
||||
' <div class="row">\n' +
|
||||
' <div class="row col-6"><span class="mt-2 ml20">有效时间:</span>\n' +
|
||||
' <div class="col-4 no_padding">\n' +
|
||||
' <input type="text" name="stage[][start_time]" id="stage__start_time" value="" autocomplete="off" class="section-start-time form-control" placeholder="有效开始时间">\n' +
|
||||
' </div>\n' +
|
||||
' <span class="mt-2">~</span>\n' +
|
||||
' <div class="col-4 no_padding ">\n' +
|
||||
' <input type="text" name="stage[][end_time]" id="stage__end_time" value="" autocomplete="off" class="section-end-time form-control" placeholder="有效结束时间">\n' +
|
||||
' </div></div>\n' +
|
||||
' <div class="row col-3"><span class="col-4 text-right mt-2 no_padding">总任务数:</span>\n' +
|
||||
' <div class="col-6 no_padding ">\n' +
|
||||
' <input type="number" class="form-control" onchange="change_total(this)" value="3" name="stage[][entry]">\n' +
|
||||
' </div></div>\n' +
|
||||
' <div class="row col-3"><span class="col-4 text-right mt-2 no_padding">成绩来源:</span>\n' +
|
||||
' <div class="col-6 no_padding ">\n' +
|
||||
' <select class="form-control" name="stage[][score_source]">\n' +
|
||||
' <option value="0">经验值</option>\n' +
|
||||
' <option value="1">预测准确率</option>\n' +
|
||||
' </select>\n' +
|
||||
' </div></div>\n' +
|
||||
' </div>\n' +
|
||||
' <div class="row mt-2" id="task_Input_sub_new_new">\n' +
|
||||
' <div class="col-4 row task_Input_div">\n' +
|
||||
' <span class="col-4 text-right mt-3 no_padding mr10">任务1</span>\n' +
|
||||
' <div class="col-6 no_padding">\n' +
|
||||
' <input type="text" class="form-control mt-2" name="stage[][identifiers][]" placeholder="请填写实训ID">\n' +
|
||||
' </div>\n' +
|
||||
' </div>\n' +
|
||||
' <div class="col-4 row task_Input_div">\n' +
|
||||
' <span class="col-4 text-right mt-3 no_padding mr10">任务2</span>\n' +
|
||||
' <div class="col-6 no_padding">\n' +
|
||||
' <input type="text" class="form-control mt-2" name="stage[][identifiers][]" placeholder="请填写实训ID">\n' +
|
||||
' </div>\n' +
|
||||
' </div>\n' +
|
||||
' <div class="col-4 row task_Input_div">\n' +
|
||||
' <span class="col-4 text-right mt-3 no_padding mr10">任务3</span>\n' +
|
||||
' <div class="col-6 no_padding">\n' +
|
||||
' <input type="text" class="form-control mt-2" name="stage[][identifiers][]" placeholder="请填写实训ID">\n' +
|
||||
' </div>\n' +
|
||||
' </div>\n' +
|
||||
' </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>\n' +
|
||||
'</div></div></form>';
|
||||
$("#large_panel").append(html);
|
||||
|
||||
$(".stage-update-form .section-start-time").datetimepicker(timeOptions);
|
||||
$(".stage-update-form .section-end-time").datetimepicker(timeOptions);
|
||||
}
|
||||
});
|
||||
|
||||
//新增子阶段
|
||||
$(".competition-chart-stages").on("click", ".add-task-sub", function () {
|
||||
var index = $(this).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="mr10 mt-2 subName">第'+showCount+'阶段</span>\n' +
|
||||
' <div class="flex-1">\n' +
|
||||
' <div class="row">\n' +
|
||||
' <div class="row col-6"><span class="mt-2 ml20 mr10">有效时间:</span>\n' +
|
||||
' <div class="col-4 no_padding ">\n' +
|
||||
' <input type="text" name="stage[][start_time]" id="stage__start_time" value="" autocomplete="off" class="section-start-time form-control" placeholder="有效开始时间">\n' +
|
||||
' </div>\n' +
|
||||
' <span class="mt-2">~</span>\n' +
|
||||
' <div class="col-4 no_padding ">\n' +
|
||||
' <input type="text" name="stage[][end_time]" id="stage__end_time" value="" autocomplete="off" class="section-end-time form-control" placeholder="有效结束时间">\n' +
|
||||
' </div></div>\n' +
|
||||
' <div class="row col-3"><span class="col-4 text-right mt-2 no_padding mr10">总任务数:</span>\n' +
|
||||
' <div class="col-6 no_padding ">\n' +
|
||||
' <input type="number" class="form-control" onchange="change_total(this)" value="3" name="stage[][entry]">\n' +
|
||||
' </div></div>\n' +
|
||||
' <div class="row col-3"><span class="col-4 mr10 text-right mt-2 no_padding">成绩来源:</span>\n' +
|
||||
' <div class="col-6 no_padding ">\n' +
|
||||
' <select class="form-control" name="stage[][score_source]">\n' +
|
||||
' <option value="0">经验值</option>\n' +
|
||||
' <option value="1">预测准确率</option>\n' +
|
||||
' </select>\n' +
|
||||
' </div></div>\n' +
|
||||
' </div>\n' +
|
||||
' <div class="row mt-2" id="task_Input_sub_'+index+'_'+count+'">\n'+
|
||||
' <div class="col-4 row task_Input_div">\n' +
|
||||
' <span class="col-4 text-right mt-3 no_padding mr10">任务1</span>\n' +
|
||||
' <div class="col-6 no_padding">\n' +
|
||||
' <input type="text" class="form-control mt-2" name="stage[][identifiers][]" placeholder="请填写实训ID">\n' +
|
||||
' </div>\n' +
|
||||
' </div>\n' +
|
||||
' <div class="col-4 row task_Input_div">\n' +
|
||||
' <span class="col-4 text-right mt-3 no_padding mr10">任务2</span>\n' +
|
||||
' <div class="col-6 no_padding">\n' +
|
||||
' <input type="text" class="form-control mt-2" name="stage[][identifiers][]" placeholder="请填写实训ID">\n' +
|
||||
' </div>\n' +
|
||||
' </div>\n' +
|
||||
' <div class="col-4 row task_Input_div">\n' +
|
||||
' <span class="col-4 text-right mt-3 no_padding mr10">任务3</span>\n' +
|
||||
' <div class="col-6 no_padding">\n' +
|
||||
' <input type="text" class="form-control mt-2" name="stage[][identifiers][]" placeholder="请填写实训ID">\n' +
|
||||
' </div>\n' +
|
||||
' </div>\n' +
|
||||
' </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);
|
||||
|
||||
$(".stage-update-form .section-start-time").datetimepicker(timeOptions);
|
||||
$(".stage-update-form .section-end-time").datetimepicker(timeOptions);
|
||||
});
|
||||
|
||||
// 奖项设置
|
||||
var $prizeContainer = $('#competition-prize-card');
|
||||
var competitionId = $prizeContainer.data('id');
|
||||
$(document).on('prize.save.success', function(){
|
||||
$.ajax({
|
||||
method: 'GET',
|
||||
url: '/cooperative/competitions/' + competitionId + '/competition_prizes',
|
||||
dataType: 'script'
|
||||
})
|
||||
});
|
||||
|
||||
$('.modal.cooperative-upload-file-modal').on('upload:success', function(e, data){
|
||||
var $imageElement;
|
||||
if(data.suffix === '_member'){
|
||||
$imageElement = $('.prize-member-image-' + data.source_id);
|
||||
} else if(data.suffix === '_team'){
|
||||
$imageElement = $('.prize-team-image-' + data.source_id);
|
||||
} else {
|
||||
$imageElement = $('.prize-teacher-image-' + data.source_id);
|
||||
}
|
||||
$imageElement.attr('src', data.url);
|
||||
$imageElement.show();
|
||||
$imageElement.next().html('重新上传');
|
||||
})
|
||||
|
||||
// 生成获奖记录
|
||||
$prizeContainer.on('click', '.generate-prize-user-action', function(){
|
||||
var $link = $(this);
|
||||
|
||||
var generateRequest = function(){
|
||||
return $.ajax({
|
||||
method: 'POST',
|
||||
url: '/cooperative/competitions/' + competitionId + '/competition_prize_users',
|
||||
dataType: 'json',
|
||||
success: function(data){
|
||||
if(data && data.status === 0){
|
||||
show_success_flash();
|
||||
$link.remove();
|
||||
} else {
|
||||
showErrorNotify(data.message);
|
||||
}
|
||||
},
|
||||
error: function(res){
|
||||
var data = res.responseJSON;
|
||||
showErrorNotify(data.message);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
customConfirm({
|
||||
content: '确认生成吗?',
|
||||
ok: function () {
|
||||
customLoading({
|
||||
ajax: generateRequest
|
||||
})
|
||||
}
|
||||
})
|
||||
});
|
||||
} else {
|
||||
$(document).unbind('prize.save.success');
|
||||
}
|
||||
});
|
||||
|
||||
//添加主办方或者开放范围
|
||||
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 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-4 text-right mt-3 no_padding mr10">任务'+(divCount+i+1)+'</span>\n' +
|
||||
'<div class="col-6 no_padding">\n' +
|
||||
'<input type="text" class="form-control mt-2" name="stage[][identifiers][]" 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(competition_id) {
|
||||
if($(".new-stage-form").length > 0){
|
||||
alert("请先保存上一个tab");
|
||||
} else {
|
||||
var count = parseInt($("#large_panel").find(".large_panel_part").length)+1;
|
||||
var html = '<form class="stage-update-form new-stage-form flex-1" action="/cooperative/competitions/'+competition_id+'/competition_stages" accept-charset="UTF-8" data-remote="true" method="post">' +
|
||||
'<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">新增子阶段</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 update-stage export-action ml20">保存</a>\n' +
|
||||
' </div>\n' +
|
||||
' <div id="small_panel_'+count+'" class="small_panel">\n' +
|
||||
' <div class="row d-flex small_panel_item" attr_line="sub_new_new" count="1">\n' +
|
||||
' <span class="mt-2 subName mr10">第1阶段</span>\n' +
|
||||
' <div class="flex-1">\n' +
|
||||
' <div class="row">\n' +
|
||||
' <div class="row col-6"><span class="mt-2 ml20 mr10">有效时间:</span>\n' +
|
||||
' <div class="col-4 no_padding ">\n' +
|
||||
' <input type="text" name="stage[][start_time]" id="stage__start_time" value="" autocomplete="off" class="section-start-time form-control" placeholder="有效开始时间">\n' +
|
||||
' </div>\n' +
|
||||
' <span class="mt-2">~</span>\n' +
|
||||
' <div class="col-4 no_padding input_middle">\n' +
|
||||
' <input type="text" name="stage[][end_time]" id="stage__end_time" value="" autocomplete="off" class="section-end-time form-control" placeholder="有效结束时间">\n' +
|
||||
' </div></div>\n' +
|
||||
' <div class="row col-3"><span class="col-4 text-right mt-2 no_padding mr10">总任务数:</span>\n' +
|
||||
' <div class="col-6 no_padding ">\n' +
|
||||
' <input type="number" class="form-control" onchange="change_total(this)" value="3" name="stage[][entry]">\n' +
|
||||
' </div></div>\n' +
|
||||
' <div class="row col-3"><span class="col-4 text-right mt-2 no_padding mr10">成绩来源:</span>\n' +
|
||||
' <div class="col-6 no_padding ">\n' +
|
||||
' <select class="form-control" name="stage[][score_source]">\n' +
|
||||
' <option value="0">经验值</option>\n' +
|
||||
' <option value="1">预测准确率</option>\n' +
|
||||
' </select>\n' +
|
||||
' </div></div>\n' +
|
||||
' </div>\n' +
|
||||
' <div class="row mt-2" id="task_Input_sub_new_new">\n' +
|
||||
' <div class="col-4 row task_Input_div">\n' +
|
||||
' <span class="col-3 text-right mt-3 no_padding mr10">任务1</span>\n' +
|
||||
' <div class="col-8 no_padding">\n' +
|
||||
' <input type="text" class="form-control mt-2" name="stage[][identifiers][]" placeholder="请填写实训ID">\n' +
|
||||
' </div>\n' +
|
||||
' </div>\n' +
|
||||
' <div class="col-4 row task_Input_div">\n' +
|
||||
' <span class="col-3 text-right mt-3 no_padding mr10">任务2</span>\n' +
|
||||
' <div class="col-8 no_padding">\n' +
|
||||
' <input type="text" class="form-control mt-2" name="stage[][identifiers][]" placeholder="请填写实训ID">\n' +
|
||||
' </div>\n' +
|
||||
' </div>\n' +
|
||||
' <div class="col-4 row task_Input_div">\n' +
|
||||
' <span class="col-3 text-right no_padding mr10 mt-3">任务3</span>\n' +
|
||||
' <div class="col-8 no_padding">\n' +
|
||||
' <input type="text" class="form-control mt-2" name="stage[][identifiers][]" placeholder="请填写实训ID">\n' +
|
||||
' </div>\n' +
|
||||
' </div>\n' +
|
||||
' </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>\n' +
|
||||
'</div></div></form>';
|
||||
$("#large_panel").append(html);
|
||||
}
|
||||
}
|
||||
148
app/assets/javascripts/cooperative/competitions/index.js
Normal file
148
app/assets/javascripts/cooperative/competitions/index.js
Normal file
@@ -0,0 +1,148 @@
|
||||
$(document).on('turbolinks:load', function() {
|
||||
if ($('body.cooperative-competitions-index-page').length > 0) {
|
||||
$('.modal.cooperative-upload-file-modal').on('upload:success', function(e, data){
|
||||
var $imageElement = $('.competition-image-' + data.source_id);
|
||||
$imageElement.attr('src', data.url);
|
||||
$imageElement.show();
|
||||
$imageElement.next().html('重新上传');
|
||||
});
|
||||
}
|
||||
|
||||
$(".cooperative-competition-list-form").on("change", '.competitions-hot-select', function () {
|
||||
var s_value = $(this).get(0).checked ? 1 : 0;
|
||||
var json = {};
|
||||
json["hot"] = s_value;
|
||||
$.ajax({
|
||||
url: "/cooperative/competitions/hot_setting",
|
||||
type: "POST",
|
||||
dataType:'json',
|
||||
data: json,
|
||||
success: function(){
|
||||
$.notify({ message: '操作成功' });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// ============== 新增竞赛 ===============
|
||||
var $modal = $('.modal.cooperative-create-competition-modal');
|
||||
var $form = $modal.find('form.cooperative-create-competition-form');
|
||||
var $competitionNameInput = $form.find('input[name="competition_name"]');
|
||||
|
||||
$form.validate({
|
||||
errorElement: 'span',
|
||||
errorClass: 'danger text-danger',
|
||||
rules: {
|
||||
competition_name: {
|
||||
required: true
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// modal ready fire
|
||||
$modal.on('show.bs.modal', function () {
|
||||
$competitionNameInput.val('');
|
||||
});
|
||||
|
||||
$modal.on('click', '.submit-btn', function(){
|
||||
$form.find('.error').html('');
|
||||
|
||||
if ($form.valid()) {
|
||||
var url = $form.data('url');
|
||||
|
||||
$.ajax({
|
||||
method: 'POST',
|
||||
dataType: 'json',
|
||||
url: url,
|
||||
data: $form.serialize(),
|
||||
success: function(){
|
||||
$.notify({ message: '创建成功' });
|
||||
$modal.modal('hide');
|
||||
|
||||
setTimeout(function(){
|
||||
window.location.reload();
|
||||
}, 500);
|
||||
},
|
||||
error: function(res){
|
||||
var data = res.responseJSON;
|
||||
$form.find('.error').html(data.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// 导入学生
|
||||
var $importScoreModal = $('.modal.cooperative-import-competition-score-modal');
|
||||
var $importScoreForm = $importScoreModal.find('form.cooperative-import-competition-score-form');
|
||||
var $competitionIdInput = $importScoreForm.find('input[name="competition_id"]');
|
||||
|
||||
$importScoreModal.on('show.bs.modal', function(event){
|
||||
resetFileInputFunc($importScoreModal.find('.upload-file-input'));
|
||||
$importScoreModal.find('.file-names').html('选择文件');
|
||||
$importScoreModal.find('.upload-file-input').trigger('click');
|
||||
|
||||
var $link = $(event.relatedTarget);
|
||||
var competitionId = $link.data('competition-id');
|
||||
$competitionIdInput.val(competitionId);
|
||||
});
|
||||
|
||||
$importScoreModal.on('change', '.upload-file-input', function(e){
|
||||
var file = $(this)[0].files[0];
|
||||
$importScoreModal.find('.file-names').html(file ? file.name : '请选择文件');
|
||||
});
|
||||
|
||||
var importUserFormValid = function(){
|
||||
if($importScoreForm.find('input[name="file"]').val() == undefined || $importScoreForm.find('input[name="file"]').val().length == 0){
|
||||
$importScoreForm.find('.error').html('请选择文件');
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
var buildResultMessage = function(data){
|
||||
var messageHtml = "<div>导入结果:成功" + data.success + "条,失败"+ data.fail.length + "条</div>";
|
||||
|
||||
if(data.fail.length > 0){
|
||||
messageHtml += '<table class="table"><thead class="thead-light"><tr><th>数据</th><th>失败原因</th></tr></thead><tbody>';
|
||||
|
||||
data.fail.forEach(function(item){
|
||||
messageHtml += '<tr><td>' + item.data + '</td><td>' + item.message + '</td></tr>';
|
||||
});
|
||||
|
||||
messageHtml += '</tbody></table>'
|
||||
}
|
||||
|
||||
return messageHtml;
|
||||
};
|
||||
|
||||
$importScoreModal.on('click', '.submit-btn', function(){
|
||||
$importScoreForm.find('.error').html('');
|
||||
|
||||
if (importUserFormValid()) {
|
||||
$('body').mLoading({ text: '正在导入...' });
|
||||
|
||||
$.ajax({
|
||||
method: 'POST',
|
||||
dataType: 'json',
|
||||
url: '/cooperative/import_competition_scores',
|
||||
data: new FormData($importScoreForm[0]),
|
||||
processData: false,
|
||||
contentType: false,
|
||||
success: function(data){
|
||||
$('body').mLoading('destroy');
|
||||
$importScoreModal.modal('hide');
|
||||
|
||||
showMessageModal(buildResultMessage(data), function(){
|
||||
window.location.reload();
|
||||
});
|
||||
},
|
||||
error: function(res){
|
||||
$('body').mLoading('destroy');
|
||||
var data = res.responseJSON;
|
||||
$importScoreForm.find('.error').html(data.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
9
app/assets/javascripts/cooperative/enroll_lists/index.js
Normal file
9
app/assets/javascripts/cooperative/enroll_lists/index.js
Normal file
@@ -0,0 +1,9 @@
|
||||
$(document).on('turbolinks:load', function() {
|
||||
if($('body.cooperative-enroll-lists-index-page').length > 0){
|
||||
var search_form = $(".search-form");
|
||||
//导出
|
||||
$(".competition-enroll-list-form").on("click","#enroll-lists-export",function () {
|
||||
window.location.href = "/cooperative/competitions/"+$(this).attr("data-competition-id")+"/enroll_lists/export.xlsx?" + search_form.serialize();
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,86 @@
|
||||
$(document).on('turbolinks:load', function() {
|
||||
if ($('body.cooperative-laboratory-settings-edit-page, body.cooperative-laboratory-settings-update-page').length > 0) {
|
||||
var $container = $('.edit-laboratory-setting-container');
|
||||
var $form = $container.find('.edit_laboratory');
|
||||
|
||||
$('.logo-item-left, .banner-item-bottom').on("change", 'input[type="file"]', function () {
|
||||
var $fileInput = $(this);
|
||||
var file = this.files[0];
|
||||
var imageType = /image.*/;
|
||||
if (file && file.type.match(imageType)) {
|
||||
var reader = new FileReader();
|
||||
reader.onload = function () {
|
||||
var $box = $fileInput.parent();
|
||||
$box.find('img').attr('src', reader.result).css('display', 'block');
|
||||
$box.addClass('has-img');
|
||||
};
|
||||
reader.readAsDataURL(file);
|
||||
} else {
|
||||
}
|
||||
});
|
||||
|
||||
createMDEditor('laboratory-footer-editor', { height: 200, placeholder: '请输入备案信息' });
|
||||
|
||||
$form.validate({
|
||||
errorElement: 'span',
|
||||
errorClass: 'danger text-danger',
|
||||
errorPlacement:function(error,element){
|
||||
if(element.parent().hasClass("input-group")){
|
||||
element.parent().after(error);
|
||||
}else{
|
||||
element.after(error)
|
||||
}
|
||||
},
|
||||
rules: {
|
||||
identifier: {
|
||||
required: true,
|
||||
checkSite: true
|
||||
},
|
||||
name: {
|
||||
required: true
|
||||
}
|
||||
}
|
||||
});
|
||||
$.validator.addMethod("checkSite",function(value,element,params){
|
||||
var checkSite = /^(?=^.{3,255}$)[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+$/;
|
||||
return this.optional(element)||(checkSite.test(value + '.educoder.com'));
|
||||
},"域名不合法!");
|
||||
|
||||
$form.on('click', '.submit-btn', function(){
|
||||
$form.find('.submit-btn').attr('disabled', 'disabled');
|
||||
$form.find('.error').html('');
|
||||
var valid = $form.valid();
|
||||
|
||||
$('input[name="navbar[][name]"]').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;
|
||||
$.ajax({
|
||||
method: 'PATCH',
|
||||
dataType: 'json',
|
||||
url: $form.attr('action'),
|
||||
data: new FormData($form[0]),
|
||||
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);
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,60 @@
|
||||
$(document).on('turbolinks:load', function() {
|
||||
if ($('body.cooperative-laboratory-shixuns-index-page').length > 0) {
|
||||
var $searchForm = $('.laboratory-shixun-list-form .search-form');
|
||||
|
||||
$searchForm.find('select#tag_id').select2({
|
||||
placeholder: "请选择",
|
||||
allowClear: true
|
||||
});
|
||||
|
||||
// 上传图片
|
||||
$('.modal.cooperative-upload-file-modal').on('upload:success', function (e, data) {
|
||||
var $imageElement = $('.shixun-image-' + data.source_id);
|
||||
if($imageElement.length === 0) return;
|
||||
$imageElement.attr('src', data.url);
|
||||
$imageElement.show();
|
||||
$imageElement.next().html('重新上传');
|
||||
});
|
||||
|
||||
// 定义状态切换监听事件
|
||||
var defineStatusChangeFunc = function (doElement, undoElement, url, callback) {
|
||||
$('.laboratory-shixun-list-container').on('click', doElement, function () {
|
||||
var $doAction = $(this);
|
||||
var $undoAction = $doAction.siblings(undoElement);
|
||||
|
||||
var laboratoryShixunId = $doAction.data('id');
|
||||
customConfirm({
|
||||
content: '确认进行该操作吗?',
|
||||
ok: function () {
|
||||
$.ajax({
|
||||
url: '/cooperative/laboratory_shixuns/' + laboratoryShixunId + url,
|
||||
method: 'POST',
|
||||
dataType: 'json',
|
||||
success: function () {
|
||||
show_success_flash();
|
||||
$doAction.hide();
|
||||
$undoAction.show();
|
||||
if (callback && typeof callback === "function") {
|
||||
callback(laboratoryShixunId, url);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// 首页展示与取消首页展示
|
||||
var homepageShowCallback = function (laboratoryShixunId, url) {
|
||||
var $laboratoryShixunItem = $('.laboratory-shixun-list-container').find('.laboratory-shixun-item-' + laboratoryShixunId);
|
||||
|
||||
if (url === '/homepage') {
|
||||
$laboratoryShixunItem.find('.homepage-badge').show();
|
||||
} else {
|
||||
$laboratoryShixunItem.find('.homepage-badge').hide();
|
||||
}
|
||||
}
|
||||
defineStatusChangeFunc('.homepage-show-action', '.homepage-hide-action', '/homepage', homepageShowCallback);
|
||||
defineStatusChangeFunc('.homepage-hide-action', '.homepage-show-action', '/cancel_homepage', homepageShowCallback);
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,83 @@
|
||||
$(document).on('turbolinks:load', function() {
|
||||
if ($('body.cooperative-laboratory-subjects-index-page').length > 0) {
|
||||
var $searchForm = $('.laboratory-subject-list-form .search-form');
|
||||
|
||||
// ************** 学校选择 *************
|
||||
$searchForm.find('.school-select').select2({
|
||||
theme: 'bootstrap4',
|
||||
placeholder: '请选择创建者单位',
|
||||
allowClear: true,
|
||||
minimumInputLength: 1,
|
||||
ajax: {
|
||||
delay: 500,
|
||||
url: '/api/schools/search.json',
|
||||
dataType: 'json',
|
||||
data: function (params) {
|
||||
return {keyword: params.term};
|
||||
},
|
||||
processResults: function (data) {
|
||||
return {results: data.schools}
|
||||
}
|
||||
},
|
||||
templateResult: function (item) {
|
||||
if (!item.id || item.id === '') return item.text;
|
||||
return item.name;
|
||||
},
|
||||
templateSelection: function (item) {
|
||||
if (item.id) {
|
||||
}
|
||||
return item.name || item.text;
|
||||
}
|
||||
});
|
||||
|
||||
// 上传图片
|
||||
$('.modal.cooperative-upload-file-modal').on('upload:success', function (e, data) {
|
||||
var $imageElement = $('.subject-image-' + data.source_id);
|
||||
if($imageElement.length === 0) return;
|
||||
$imageElement.attr('src', data.url);
|
||||
$imageElement.show();
|
||||
$imageElement.next().html('重新上传');
|
||||
});
|
||||
|
||||
// 定义状态切换监听事件
|
||||
var defineStatusChangeFunc = function (doElement, undoElement, url, callback) {
|
||||
$('.laboratory-subject-list-container').on('click', doElement, function () {
|
||||
var $doAction = $(this);
|
||||
var $undoAction = $doAction.siblings(undoElement);
|
||||
|
||||
var laboratorySubjectId = $doAction.data('id');
|
||||
customConfirm({
|
||||
content: '确认进行该操作吗?',
|
||||
ok: function () {
|
||||
$.ajax({
|
||||
url: '/cooperative/laboratory_subjects/' + laboratorySubjectId + url,
|
||||
method: 'POST',
|
||||
dataType: 'json',
|
||||
success: function () {
|
||||
show_success_flash();
|
||||
$doAction.hide();
|
||||
$undoAction.show();
|
||||
if (callback && typeof callback === "function") {
|
||||
callback(laboratorySubjectId, url);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// 首页展示与取消首页展示
|
||||
var homepageShowCallback = function (laboratoryShixunId, url) {
|
||||
var $laboratoryShixunItem = $('.laboratory-subject-list-container').find('.laboratory-subject-item-' + laboratoryShixunId);
|
||||
|
||||
if (url === '/homepage') {
|
||||
$laboratoryShixunItem.find('.homepage-badge').show();
|
||||
} else {
|
||||
$laboratoryShixunItem.find('.homepage-badge').hide();
|
||||
}
|
||||
}
|
||||
defineStatusChangeFunc('.homepage-show-action', '.homepage-hide-action', '/homepage', homepageShowCallback);
|
||||
defineStatusChangeFunc('.homepage-hide-action', '.homepage-show-action', '/cancel_homepage', homepageShowCallback);
|
||||
}
|
||||
})
|
||||
62
app/assets/javascripts/cooperative/laboratory_users/index.js
Normal file
62
app/assets/javascripts/cooperative/laboratory_users/index.js
Normal file
@@ -0,0 +1,62 @@
|
||||
$(document).on('turbolinks:load', function() {
|
||||
if ($('body.cooperative-laboratory-users-index-page').length > 0) {
|
||||
// ============= 添加管理员 ==============
|
||||
var $addMemberModal = $('.cooperative-add-laboratory-user-modal');
|
||||
var $addMemberForm = $addMemberModal.find('.cooperative-add-laboratory-user-form');
|
||||
var $memberSelect = $addMemberModal.find('.laboratory-user-select');
|
||||
|
||||
$addMemberModal.on('show.bs.modal', function(event){
|
||||
$memberSelect.select2('val', ' ');
|
||||
});
|
||||
|
||||
$memberSelect.select2({
|
||||
theme: 'bootstrap4',
|
||||
placeholder: '请输入要添加的管理员姓名',
|
||||
multiple: true,
|
||||
minimumInputLength: 1,
|
||||
ajax: {
|
||||
delay: 500,
|
||||
url: '/cooperative/users/for_select',
|
||||
dataType: 'json',
|
||||
data: function(params){
|
||||
return { name: params.term };
|
||||
},
|
||||
processResults: function(data){
|
||||
return { results: data.users }
|
||||
}
|
||||
},
|
||||
templateResult: function (item) {
|
||||
if(!item.id || item.id === '') return item.text;
|
||||
return $("<span>" + item.real_name + " <span class='font-12'>" + item.school_name + ' ' + item.hidden_phone + "</span></span>");
|
||||
},
|
||||
templateSelection: function(item){
|
||||
if (item.id) {
|
||||
}
|
||||
return item.real_name || item.text;
|
||||
}
|
||||
});
|
||||
|
||||
$addMemberModal.on('click', '.submit-btn', function(){
|
||||
$addMemberForm.find('.error').html('');
|
||||
|
||||
var memberIds = $memberSelect.val();
|
||||
if (memberIds && memberIds.length > 0) {
|
||||
$.ajax({
|
||||
method: 'POST',
|
||||
dataType: 'json',
|
||||
url: '/cooperative/laboratory_users',
|
||||
data: { user_ids: memberIds },
|
||||
success: function(data){
|
||||
if(data && data.status == 0){
|
||||
show_success_flash();
|
||||
$addMemberModal.modal('hide');
|
||||
window.location.reload();
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
$addMemberModal.modal('hide');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,18 @@
|
||||
$(document).on('turbolinks:load', function () {
|
||||
$('.cooperative-modal-container').on('show.bs.modal', '.modal.cooperative-edit-subject-modal', function () {
|
||||
var $modal = $('.modal.cooperative-edit-subject-modal');
|
||||
var $form = $modal.find('form.cooperative-edit-subject-form');
|
||||
|
||||
$modal.on('click', '.submit-btn', function () {
|
||||
$form.find('.error').html('');
|
||||
var url = $form.attr('action');
|
||||
|
||||
$.ajax({
|
||||
method: 'PATCH',
|
||||
dataType: 'script',
|
||||
url: url,
|
||||
data: $form.serialize()
|
||||
});
|
||||
});
|
||||
})
|
||||
});
|
||||
@@ -0,0 +1,62 @@
|
||||
$(document).on('turbolinks:load', function() {
|
||||
var $modal = $('.modal.cooperative-upload-file-modal');
|
||||
if ($modal.length > 0) {
|
||||
var $form = $modal.find('form.cooperative-upload-file-form')
|
||||
var $sourceIdInput = $modal.find('input[name="source_id"]');
|
||||
var $sourceTypeInput = $modal.find('input[name="source_type"]');
|
||||
|
||||
$modal.on('show.bs.modal', function(event){
|
||||
var $link = $(event.relatedTarget);
|
||||
var sourceId = $link.data('sourceId');
|
||||
var sourceType = $link.data('sourceType');
|
||||
|
||||
$sourceIdInput.val(sourceId);
|
||||
$sourceTypeInput.val(sourceType);
|
||||
|
||||
$modal.find('.upload-file-input').trigger('click');
|
||||
});
|
||||
|
||||
$modal.find('.upload-file-input').on('change', function(e){
|
||||
var file = $(this)[0].files[0];
|
||||
|
||||
if(file){
|
||||
$modal.find('.file-names').html(file.name);
|
||||
$modal.find('.submit-btn').trigger('click');
|
||||
}
|
||||
})
|
||||
|
||||
var formValid = function(){
|
||||
if($form.find('input[name="file"]').val() == undefined || $form.find('input[name="file"]').val().length == 0){
|
||||
$form.find('.error').html('请选择文件');
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
$modal.on('click', '.submit-btn', function(){
|
||||
$form.find('.error').html('');
|
||||
|
||||
if (formValid()) {
|
||||
var formDataString = $form.serialize();
|
||||
$.ajax({
|
||||
method: 'POST',
|
||||
dataType: 'json',
|
||||
url: '/cooperative/files?' + formDataString,
|
||||
data: new FormData($form[0]),
|
||||
processData: false,
|
||||
contentType: false,
|
||||
success: function(data){
|
||||
$.notify({ message: '上传成功' });
|
||||
$modal.trigger('upload:success', data);
|
||||
$modal.modal('hide');
|
||||
},
|
||||
error: function(res){
|
||||
var data = res.responseJSON;
|
||||
$form.find('.error').html(data.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
16
app/assets/javascripts/cooperative/sidebar.js
Normal file
16
app/assets/javascripts/cooperative/sidebar.js
Normal file
@@ -0,0 +1,16 @@
|
||||
$(document).on('turbolinks:load', function(){
|
||||
$('#sidebarCollapse').on('click', function () {
|
||||
$(this).toggleClass('active');
|
||||
$('#sidebar').toggleClass('active');
|
||||
$.cookie('cooperative_sidebar_collapse', $(this).hasClass('active'), {path: '/cooperative'});
|
||||
});
|
||||
|
||||
var sidebarController = $('#sidebar').data('current-controller');
|
||||
if (sidebarController.length > 0) {
|
||||
$('#sidebar a.active').removeClass('active');
|
||||
$('#sidebar ul.collapse.show').removeClass('show');
|
||||
var activeLi = $('#sidebar a[data-controller="' + sidebarController + '"]');
|
||||
activeLi.addClass('active');
|
||||
activeLi.parent().parent('ul.collapse').addClass('show');
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user