File size: 6,342 Bytes
e1d589b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | "use strict"
String.prototype.replaceAll = function(target, replacement) {
return this.split(target).join(replacement);
};
/**
* 按钮确认
*/
$(function () {
$(".btn-confirm").click(function () {
var msg = $(this).attr("confirm-msg");
if (!msg) {
msg = "确定要执行此操作吗?";
}
return confirm(msg);
});
});
function parseRedirectUrl(search) {
if (search) {
return search.substr(1).split('=');
}
}
/**
* 表单提交
*/
var formSubmit = function() {
// 阻止回车自动提交
$("form input").keypress(function(event) {
if (event.which == 13) {
event.preventDefault();
return false;
}
});
var ajaxTimerId = 0;
$(".btn-submit").click(function() {
if (!$(this).is(":disabled")) {
// btn-submit-confirm
var form = $(this).parents('form'),
action = form.attr("action"),
method = form.attr("method"),
btn = $(this);
// prevent multiple clicks
btn.prop("disabled", true);
var formData = new FormData(form[0]);
var result = parseRedirectUrl(window.location.search);
if (result) {
formData.append(result[0], result[1]);
}
$(form).find("input, select, img, radio, textarea").each(function() {
if($(this).prop("type").toLowerCase()=='file') {
formData.append(name, $(this)[0]);
}
});
// Ajax submit function
var ajaxSubmit = function() {
if(ajaxTimerId != 0) {
return false;
}
ajaxTimerId = setTimeout(function() {
clearTimeout(ajaxTimerId);
ajaxTimerId = 0;
}, 3000);
var settings = {
method: method,
url: action,
dataType: "json",
processData: false,
contentType: false,
data: formData
};
$.ajax(settings).done(function(resp) {
// 请求 - 返回成功
if (resp.code == 0) {
btn.find(".label-success").removeClass("hide");
// 需要延迟并显示成功信息
if (typeof(resp.data.delaySuccess) != "undefined") {
setTimeout(function () {
if (typeof(resp.data.href) != "undefined") {
window.location.href = resp.data.href;
} else if (typeof(resp.data.reload) != "undefined") {
window.location.reload();
}
btn.find(".label-success").addClass("hide");
btn.prop("disabled", false);
}, 3000);
} else {
if (typeof(resp.data.href) != "undefined") {
window.location.href = resp.data.href;
} else if (typeof(resp.data.reload) != "undefined") {
window.location.reload();
}
btn.prop("disabled", false);
}
} else {
btn.prop("disabled", false);
var k = resp.data['input'],
msg = resp.data['err_msg'];
var formGroup = form.find("[name='"+k+"']").parents(".form-group");
displayError(formGroup, msg);
}
(typeof(afterSubmit) != 'undefined' && afterSubmit != null) && afterSubmit(resp);
}).fail(function(jqXHR, textStatus) {
btn.prop("disabled", false);
(typeof(afterSubmit) != 'undefined' && afterSubmit != null) && afterSubmit(resp);
});
};
// execute beforeSubmit
if (typeof(beforeSubmit) != 'undefined' && beforeSubmit != null) {
beforeSubmit(function() {
ajaxSubmit();
});
} else {
ajaxSubmit();
}
}
});
// remove error message when the input focus
$("form input,form select,form textarea").focus(function() {
hideError($(this));
});
$("select").change(function() {
hideError($(this));
});
};
/**
* 显示/隐藏表单错误提示
*/
var displayError = function (formGroup, msg) {
formGroup.addClass("has-error");
formGroup.find(".help-block").text(msg);
},
hideError = function ($subEle) {
$subEle.parents(".form-group.has-error").find(".help-block").html(" ");
$subEle.parents(".form-group.has-error").removeClass("has-error");
};
/**
* 模态框
*/
$(function () {
// 关闭模态框
$(".modal").click(function (e) {
if($(e.target.target).hasClass("close") || $(e.target).hasClass("btn-close")) {
$(".modal-view").addClass("hide");
$("html").css("overflow-y", "auto");
}
});
// 打开模态框
$(".btn-modal-raise").click(function () {
var target = $(this).attr("modal-target");
$("#"+target).removeClass("hide");
$("html").css("overflow-y", "hidden");
$(".modal")
});
});
$(function () {
$(".btn-refresh").click(function() {
window.location.reload();
});
});
/**
* 版面切换
*/
$(function() {
$(".nav-tabs li").click(function () {
var $box = $(".tab-" + $(this).attr("role"));
$(".nav-tabs li").removeClass("active");
$(this).addClass("active");
$(".tab-box").addClass("hide");
$box.removeClass("hide");
});
});
$(document).ready(function() {
formSubmit();
});
/**
* 删除视频资料
*/
$(function() {
$('.video-delete-confirm').click(function(e){
var sure_delete = confirm("确定删除?");
if (sure_delete) {
window.global_video_id = $(this).parent().parent()[0].id;
e.preventDefault();
var data = {
'id': window.global_video_id
}
$.post('/admin/video/delete', data, function(resp, status) {
var r = JSON.parse(resp);
if (r['code'] == 0) {
alert("删除成功");
}
window.location.reload();
});
}
});
});
/**
* 删除机构学生
*/
$(function() {
$('.student-delete-confirm').click(function(e){
var sure_delete = confirm("确定删除?");
if (sure_delete) {
window.global_stu_id = $(this).parent().parent()[0].id;
e.preventDefault();
var data = {
'id': window.global_stu_id
}
$.post('/school/student/delete', data, function(resp, status) {
var r = JSON.parse(resp);
if (r['code'] == 0) {
alert("删除成功");
}
window.location.reload();
});
}
});
});
|