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.
iot/labs/Teacher/TeacherExt/wwwroot/js/site.js

415 lines
14 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

if (!String.prototype.endsWith) {
String.prototype.endsWith = function (endStr) {
var d = this.length - endStr.length;
return (d >= 0 && this.lastIndexOf(endStr) == d);
};
}
function urlContent2(baseUrl, path) {
if (!path.startsWith("/dfs/")) {
return baseUrl + path;
}
return path;
}
//agree with
jQuery.validator.addMethod("mustbetrue", function (value, element) {
return element.checked;
});
jQuery.validator.unobtrusive.adapters.addBool("mustbetrue");
function clearSelectList() {
for (var i = 0; i < arguments.length; i++) {
$(arguments[i]).find('option').not('[value=""]').remove();
}
}
//radio list
$.validator.unobtrusive.adapters.addBool("radio", "required");
function updateSelectList(url, id) {
$.getJSON(url, function (data) {
$.each(data, function (i, v) {
$(id).append('<option value="' + v.value + '">' + v.text + '</option>');
});
});
}
//scroll to top
(function ($) {
$.fn.backTop = function () {
var backBtn = this;
var position = 200;
var speed = 900;
$(document).scroll(function () {
var pos = $(window).scrollTop();
if (pos >= position) {
backBtn.fadeIn(speed);
} else {
backBtn.fadeOut(speed);
}
});
backBtn.click(function () {
$("html, body").animate({ scrollTop: 0 }, 500);
});
};
}(jQuery));
//ajax cache
$(function () {
$.ajaxSetup({
cache: false
});
$('.fancybox').fancybox();
});
//paged
$(function () {
$('.pagination #PageSize').change(function () {
var pageSize = $(this).find(':selected').val();
var url = new URI(window.location.href);
window.location.href = url.removeQuery("PageIndex").setQuery("PageSize", pageSize).removeQuery("PageIndex").setQuery("PageIndex", 1);
});
});
//delete select
$(function () {
$('th :checkbox').change(function () {
if ($(this).is(':checked')) {
$(this).parents('table').find(':checkbox').not(':checked').prop("checked", true);
}
else {
$(this).parents('table').find(':checkbox').filter(':checked').prop("checked", false);
}
});
$('td :checkbox').change(function () {
var parent = $(this).parents('table').find('th :checkbox');
var children = $(this).parents('table').find('td :checkbox');
if ($(this).is(':checked')) {
if (parent.not(':checked')) {
if (children.not(':checked').length === 0) {
parent.prop("indeterminate", false);
parent.prop("checked", true);
}
else {
parent.prop("indeterminate", true);
}
}
}
else {
if (parent.is(':checked')) {
if (children.filter(':checked').length === 0) {
parent.prop("indeterminate", false);
parent.prop("checked", false);
}
else {
parent.prop("indeterminate", true);
}
}
}
});
});
//query
$(function () {
$("button.action.query").click(function () {
var form = $(this).parents("form");
form.attr('action', $(this).attr('data-action'));
form.attr('method', 'get');
form[0].submit();
});
});
//delete confrim
$(function () {
$("button.action.confirm").click(function () {
var form = $(this).parents("form");
var list = form.find('tbody input:checked[name]');
form.attr('action', $(this).attr('data-action'));
form.attr('method', 'post');
var msg = "确认" + $(this).text() + "";
if (!list.length) {
Swal.fire('没有选中任何记录!');
}
else {
Swal.fire({
text: msg,
confirmButtonText: '确定',
cancelButtonText: '取消',
showCancelButton: true
}).then(function (value) {
if (value.isConfirmed) {
form[0].submit();
}
});
}
return false;
});
});
//image box
$(function () {
$('.fancybox').fancybox();
});
//edit date datetime
function InitControls() {
//
if ($.datetimepicker) {
$.datetimepicker.setLocale('zh');
$('.edit-date').each(function () {
var picker = $(this).datetimepicker({
closeOnDateSelect: true,
timepicker: false, format: 'Y-m-d',
onChangeDateTime: function (dp, $input) {
$($input).valid();
}
});
if ($(this).val()) {
$(this).val(moment($(this).datetimepicker('getValue')).format("YYYY-MM-DD"));
}
});
$('.edit-datetime').datetimepicker({ format: 'Y-m-d H:i' });
$('.edit-time').datetimepicker({ datepicker: false, format: 'H:i' });
}
//
$(".edit-multiSelect").each(function () {
$(this).treeMultiselect({ enableSelectAll: true, searchable: true, selectAllText: "全选", unselectAllText: "反选" });
});
//
$('select.select2bs4').each(function () {
if ($(this).attr('data-allow-input') === 'True') {
$(this).select2({
tags: true,
maximumInputLength: 20,
theme: "bootstrap4",
language: "zh-CN",
placeholder: '请选择',
allowClear: true
}).change(function () {
$(this).valid();
});;
}
});
$('select.select2bs4.search').each(function () {
var url = $(this).attr('data-search-url');
$(this).select2({
theme: "bootstrap4",
language: "zh-CN",
placeholder: '请选择',
allowClear: true,
minimumInputLength: 2,
ajax: {
url: url,
data: function (params) {
var query = {
search: params.term,
type: 'public'
}
return query;
},
dataType: 'json',
processResults: function (data) {
return {
results: Enumerable.from(data).select(function (o) { return { id: o.value, text: o.text }; }).toArray()
};
}
}
});
});
//
$('select[data-remote-target]').each(function () {
var sourceId = $(this).attr('data-remote-source');
var targetId = $(this).attr('data-remote-target');
var url = $(this).attr('data-remote-url');
change(sourceId, targetId, url);
});
//
$('input.cron').each(function () {
var cron = $(this).jqCron({
lang: 'cn',
enabled_year: true,
enabled_minute: true,
multiple_dom: true,
multiple_month: true,
multiple_mins: true,
multiple_dow: true,
multiple_time_hours: true,
multiple_time_minutes: true,
default_value: $(this).val().substr(2),
bind_method: {
set: function ($element, value) {
$element.val('0 ' + value);
}
},
no_reset_button: false
}).jqCronGetInstance();
if ($(this).hasClass('disable')) {
cron.disable();
}
});
}
function InitEditor(K) {
//edit editor
$('.edit-editor').each(function () {
var name = $(this).attr('name');
var uploadUrl = $(this).attr('data-uploadUrl');
KindEditor.create('textarea[name="' + name + '"]', {
allowImageUpload: true,
uploadJson: uploadUrl,
formatUploadUrl: false
});
});
//edit image file
$('.edit-image').each(function () {
var id = $(this).attr('id');
var btn_id = '#btn_' + id;
var image_id = '#image_' + id;
var rest_id = '#rest_' + id;
var uploadUrl = $(this).attr('data-uploadUrl');
var emtpyImage = $(this).attr('data-emptyImage');
var baseUrl = $(this).attr('data-baseUrl');
var isRequired = $(this).attr('data-val-required') !== undefined;
var editor = KindEditor.editor({
allowImageUpload: true,
formatUploadUrl: false,
uploadJson: uploadUrl
});
KindEditor(btn_id).click(function () {
editor.loadPlugin('insertfile', function () {
editor.plugin.fileDialog({
fileUrl: $('#' + id).val(),
clickFn: function (url, title) {
$('#' + id).attr('value', url);
if (isRequired) {
$('#' + id).parents('form').validate().element('#' + id);
}
$(image_id).attr('src', urlContent2(baseUrl, url));
$(image_id).parent('a').attr('href', urlContent2(baseUrl, url));
editor.hideDialog();
}
});
});
});
$('#' + id).attr("style", "visibility:hidden; position: absolute;");
$(rest_id).click(function () {
$('#' + id).attr('value', '');
$(image_id).attr('src', emtpyImage);
$(image_id).parent('a').attr('href', emtpyImage);
});
});
$('.edit-file').each(function () {
var id = $(this).attr('id');
var btn_id = '#btn_' + id;
var image_id = '#image_' + id;
var rest_id = '#rest_' + id;
var uploadUrl = $(this).attr('data-uploadUrl');
var baseUrl = $(this).attr('data-baseUrl');
var isRequired = $(this).attr('data-val-required') !== undefined;
var editor = KindEditor.editor({
allowImageUpload: true,
formatUploadUrl: false,
uploadJson: uploadUrl
});
KindEditor(btn_id).click(function () {
editor.loadPlugin('insertfile', function () {
editor.plugin.fileDialog({
fileUrl: $('#' + id).val(),
clickFn: function (url, title) {
$('#' + id).attr('value', url);
if (isRequired) {
$('#' + id).parents('form').validate().element('#' + id);
}
$(image_id).text(url);
editor.hideDialog();
}
});
});
});
$(rest_id).click(function () {
$('#' + id).attr('value', '');
$(image_id).text('');
});
});
$('.list-import').each(function () {
var id = '#file_' + $(this).attr('id');
var btn_id = '#' + $(this).attr('id');
var uploadUrl = $(this).attr('data-action');
var editor = KindEditor.editor({
allowFileManager: false,
allowImageUpload: true,
formatUploadUrl: false,
uploadJson: uploadUrl
});
KindEditor(btn_id).click(function () {
editor.loadPlugin('image', function () {
editor.plugin.imageDialog({
showRemote: false,
imageUrl: $(id).val(),
clickFn: function (url, title, width, height, border, align) {
$('id').val(url);
editor.hideDialog();
location.reload();
}
});
});
});
});
}
KindEditor.ready(function (K) {
InitEditor(K);
});
$(function () {
$("button.list-export").click(function () {
var form = $(this).parents("form");
form.attr('target', '_blank');
form.attr('action', $(this).attr('data-action'));
form.submit();
form.removeAttr('target');
return false;
});
});
$(function () {
InitControls();
});
$('body').on('change', 'select.organ.submit', function () {
$(this).parents('form').submit();
});
$('body').on('click', '.cmd', function () {
$.getJSON($(this).attr('href'), function (response) {
console.log(response);
}).fail(function (jqxhr, textStatus, error) {
var err = textStatus + ", " + error;
alert(err);
});
return false;
});
function change(sourceId, targetId, url) {
if (document.getElementById(targetId)) {
$('#' + sourceId).change(function () {
var id = $(this).find(':selected').val();
update(url, id, '#' + targetId);
});
}
if (document.getElementById('Query_'+targetId)) {
$('#Query_' + sourceId).change(function () {
var id = $(this).find(':selected').val();
update(url, id, '#Query_' + targetId);
});
}
}
function update(url, parent, targetId) {
if (!document.querySelector(targetId)) {
return;
}
$(targetId).find('option').not('[value=""]').remove().change();
if (url !== null) {
url = URI(url).addSearch("parentId", parent);
$('#loadingToast:hidden ').show();
$.getJSON(url, function (data) {
$.each(data, function (i, v) {
$(targetId).append('<option value="' + v.value + '">' + v.text + '</option>');
});
}).always(function () {
$('#loadingToast:visible').hide();
});
}
}
function reset() {
$('form').removeData('validator');
$('form').removeData('unobtrusiveValidation');
$.validator.unobtrusive.parse('form');
}