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("服务器正忙!");
}
});
}
});