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(''); }); }); } //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); } } } }); }); //delete confrim $(function () { $("th button.delete,td button.delete").click(function () { var form = $(this).parents("form"); layer.confirm("确认删除?", { title: '警告', icon: 3, btn: ['确认', '取消'], btnAlign: 'c' }, function () { form.submit(); }, function () { }); return false; }); $("button.confirm").click(function () { var form = $(this).parents("form"); form.attr('action', $(this).attr('data-action')); var msg = "确认" + $(this).text() + "?"; layer.confirm(msg, { title: '警告', icon: 3, btn: ['确认', '取消'], btnAlign: 'c' }, function () { form.submit(); }, function () { }); return false; }); }); //image box $(function () { $('.fancybox').fancybox(); }); //edit date datetime function InitControls() { // if ($.datetimepicker) { $.datetimepicker.setLocale('zh'); $('.edit-date').datetimepicker({ timepicker: false, format: 'Y-m-d' }); $('.edit-datetime').datetimepicker({ format: 'Y-m-d H:i' }); } // $(".edit-multiSelect").treeMultiselect({ enableSelectAll: true, searchable: true, selectAllText: "全选", unselectAllText: "反选" }); // $('select.search').select2({ theme: "bootstrap4", language: "zh-CN" }); // $('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 = K.editor({ allowImageUpload: true, formatUploadUrl: false, uploadJson: uploadUrl }); KindEditor(btn_id).click(function () { editor.loadPlugin('insertfile', function () { editor.plugin.fileDialog({ fileUrl: K('#' + 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 = K.editor({ allowImageUpload: true, formatUploadUrl: false, uploadJson: uploadUrl }); KindEditor(btn_id).click(function () { editor.loadPlugin('insertfile', function () { editor.plugin.fileDialog({ fileUrl: K('#' + 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 = K.editor({ allowFileManager: false, allowImageUpload: true, formatUploadUrl: false, uploadJson: uploadUrl }); KindEditor(btn_id).click(function () { editor.loadPlugin('image', function () { editor.plugin.imageDialog({ showRemote: false, imageUrl: K(id).val(), clickFn: function (url, title, width, height, border, align) { K('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('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 update(url, parent, targetId) { $(targetId).find('option').not('[value=""]').remove(); if (url !== null) { url += '?parentId=' + encodeURI(parent); $.getJSON(url, function (data) { $.each(data, function (i, v) { $(targetId).append(''); }); }); } } function reset() { $('form').removeData('validator'); $('form').removeData('unobtrusiveValidation'); $.validator.unobtrusive.parse('form'); }