UI彈窗與提示框外掛
阿新 • • 發佈:2019-02-03
UI彈窗外掛
(function (window, $, undefined) { /******************************************UI****************************** */ var _UI = function () { var _message = function () { var createAlert = function (type, msg, timeout) { if (timeout === undefined) timeout = 2000; var div = $( '<div class="cntenalert" >' + '<div class="alert-icons"></div>' + '<div class="alert-close">×</div>' + '<div class="alert-msg"></div></div>'); var winWidth = ($(window).width() - 200) / 2; div.css("left", winWidth); div.addClass(type); var close = div.find(".alert-close"); var divmsg = div.find(".alert-msg"); close.click(function () { div.fadeOut(function () { div.remove(); }); }); divmsg.text(msg); div.fadeIn(function () { }); $("body").append(div); if (timeout > 0) setTimeout(function () { div.fadeOut(function () { div.remove(); }); }, timeout); } /** * 成功提示 * @param {any} msg */ this.success = function (msg) { createAlert("alert", msg); } /** * 錯誤的提示 * @param {any} msg */ this.error = function (msg) { createAlert("alert-error", msg, 5000); } /** * 提醒 * @param {any} msg */ this.warning = function (msg) { createAlert("alert-warning", msg, 3000); } /** * 清除所有提示資訊 * */ this.clear = function () { $(".cntenalert").fadeOut(function () { $(".cntenalert").remove(); }); } } this.message = new _message(); /** * 開啟一個url 的Dialog 對話方塊 * @param {any} id 指定一個名字 * @param {any} url 頁面地址 * @param {any} options Dialog 引數 */ this.openDialog = function (id, url, options) { var frameid = id + "_frame"; var win = $("#" + id); if (url.indexOf("?") > -1) url = url + "&_r=" + Math.random(); else url = url + "?_r=" + Math.random(); var getframe = function (id, url) { var f = $('<iframe id="{0}" src="{1}" width="100%" height="100%" scrolling="no" frameborder="0" ></iframe>'.format(id, url)); return f; }; if (win.size() == 0) { var $frame = getframe(frameid, url); //$frame.height(options.height - 43); var defaultOptions = { maximizable: true, resizable: true, closed: false, cache: false, modal: true, constrain: true, width: "80%", height: "90%" }; if (options) { $.extend(defaultOptions, options, { onClose: function () { win.remove(); if ($.isFunction(options.onClose)) { options.onClose.apply(this); } } }); } defaultOptions.content = $frame; var dd = $("<div id='" + id + "' style='overflow:hidden' />"); return dd.dialog(defaultOptions); } else { $("#" + frameid).attr("src", url); return win.dialog("open"); } } /** * 重新設定datagrid 排序狀態 * @param {any} dg jquery物件 */ this.resetDataGridSort = function (dg, psotrName, psortOrder) { var opt = dg.datagrid('options'); opt.sortName = psotrName || ""; opt.sortOder = psortOrder || ""; var panel = dg.datagrid("getPanel"); var sortcell = panel.find(".datagrid-sort"); $.each(sortcell, function (i, n) { var targer = $(n); targer.removeClass("datagrid-sort-asc datagrid-sort-desc"); }); } }; $Core.UI = new _UI(); })(window, jQuery);
$Core.UI.openDialog("approve", url,
{
title: '稽核',
width: '30%',
height: '45%',
onClose: function () {
$("#dglist").datagrid("load");
}
});
if (rows.length == 0) { $Core.UI.message.warning("請選擇要提交的資料!"); return false; } $.messager.confirm('提示', '您確定提交嗎?', function (r) { debugger; if (r) { var ids = ""; $.each(rows, function (k, j) { ids += (ids == "" ? j[$id] : "," + j[$id]); }); var paras = { ids: ids }; $.post(url, paras, function (data) { if (data.code == "0") { $Core.UI.message.success("提交成功!"); $dg.datagrid("load"); } else { $Core.UI.message.error("伺服器正忙!"); } }); } });