jQuery.ajaxSetup({
headers : {
ajax : "true"
}
});
jQuery.formVal = function(form, others) {
form = $(form);
var array = form.serializeArray();
var j = array.length;
var vals = {};
for ( var i = 0; i < j; i++) {
vals[array[i].name] = array[i].value;
}
if (others) {
for ( var i in others) {
vals[i] = others[i];
}
}
return vals;
};
jQuery.fillForm = function(form, data, all, except) {
if (typeof all == "undefined") {
all = true;
}
if (typeof except == "undefined") {
except = [];
}
var e = {};
for ( var i = 0; i < except.length; i++) {
e[except[i]] = true;
}
$("input,select,textarea", $(form)).each(function(i, node) {
node = $(node);
var name = node.attr("name");
if (e[name]) {
return;
}
if (all) {
node.val(data[name] ? data[name] : "");
} else {
if (!node.val()) {
node.val(data[name] ? data[name] : "");
}
}
});
};
ajax = function(url, data, callback, errorback) {
if (url.indexOf("?") >= 0) {
url = url + "&ts=" + (new Date()).getTime();
} else {
url = url + "?ts=" + (new Date()).getTime();
}
$.post(url, data, function(result) {
if (!(result instanceof Object)) {
result = eval("(" + result + ")");
}
if (result.hasError) {
if (result.errors) {
//对应后台的CJobBeanValidator.renderErrorsForJson(result,response)方法,返回结构体中没有message。li-shun。2014-01-03
//var errors = result.errors.message;
var errors = result.errors;
var msg = [];
if (errors instanceof Object) {
for ( var i in errors) {
if (errors[i] instanceof Array) {
for ( var j = 0; j < errors[i].length; j++) {
msg.push(errors[i][j]);
}
} else {
msg.push(errors[i]);
}
}
} else if (errors instanceof Array) {
for ( var i = 0; i < errors.length; i++) {
msg.push(errors[i]);
}
} else {
msg.push(errors);
}
var mb = null;
mb = mbox({
title : "提示",
message : msg.join("
"),
buttons : {
"关闭" : function() {
mb.close();
}
}
});
}
if (errorback) {
errorback(result);
} else if (callback) {
callback(result);
}
} else {
if (callback) {
callback(result);
}
}
}).error(function(a, b, c) {
if (a.status == 500) {
var mb = null;
mb = mbox({
title : "系统提示",
message : "系统发生内部错误,请稍后再试",
buttons : {
"关闭" : function() {
mb.close();
}
}
});
return;
}
if (a.status == 403) {
try {
var m = a.responseText;
m = eval("(" + m + ")");
mbox({
title : "系统提示",
message : "您还没有登录,或者登录超时,请重新登录",
buttons : {
"跳转至登录页面" : function() {
window.location.href = m["goto"];
}
}
});
} catch (e) {
var mb = null;
mb = mbox({
title : "系统提示",
message : "您未授权访问此资源",
buttons : {
"关闭" : function() {
mb.close();
}
}
});
}
return;
}
var mb = null;
mb = mbox({
title : "系统提示",
message : "系统发生未知错误,请稍后再试",
buttons : {
"关闭" : function() {
mb.close();
}
}
});
});
};
mbox = function(config) {
config = config ? config : {};
var btitle = config.title ? config.title : "";
var message = config.message ? config.message : "";
var width = config.width ? config.width : 300;
var height = config.height ? config.height : -1;
var onclose = config.onClose ? config.onClose : function() {
return true;
};
var buttons = config.buttons ? config.buttons : null;
var cover = $("
").css({
height : $(document.body).height() + "px"
}).appendTo(document.body);
var box = $("");
box.cover = cover;
box.css({
width : width + "px",
left : (document.body.clientWidth - width) / 2 + "px",
top : "-100000px"
});
var title = $("").appendTo(box);
$("" + btitle + "
").appendTo(title);
$("").click(function() {
box.close();
}).appendTo(title);
var content = $("");
if (typeof (message) == "string") {
content.html(message);
} else {
content.append(message);
}
//未设置height时,自动定位bug。li-shun。2013-11-29。
// if (height != -1) {
// content.css("height", height + "px").css("overflow", config.overflow ? config.overflow : "auto");
// }
content.appendTo(box);
var defaultButton = (typeof config.defaultButton == "undefined" ? true : false);
if (!buttons && defaultButton) {
buttons = {
"关闭" : function() {
box.close();
}
};
}
box.appendTo(document.body);
if (buttons) {
var focusButton = config.focusButton;
var bottom = $("").appendTo(box);
var bt = null;
for ( var i in buttons) {
bt = $("").click(function() {
//button内部添加a标签后,点击事件bug。li-shun。2013-11-18
//buttons[$(this).html()]();
//解绑click事件,避免多次点击造成数据错误(保存时会产生多条数据) update 刘成武 2016-01-20
$(this).unbind("click");
buttons[$(this).text()]();
}).appendTo(bottom);
if (i == focusButton) {
var fbt = bt[0];
setTimeout(function() {
fbt.focus();
}, 300);
}
}
if (!focusButton && bt) {
setTimeout(function() {
bt[0].focus();
}, 300);
}
}
//未设置height时,自动定位bug。li-shun。2013-11-29。
if (height != -1) {
if(height > $(window).height()-55){
height = $(window).height()-55;
}
content.css("height", height + "px").css("overflow", config.overflow ? config.overflow : "auto");
}else {
var inner_height = content.height();
if(inner_height > $(window).height()-55){
inner_height = $(window).height()-55;
}
content.css("height", inner_height + "px").css("overflow", config.overflow ? config.overflow : "auto");
}
//手动调用box的close方法不会触发config.onClose方法。li-shun。2013-11-20
box.close = function() {
if (false === onclose()) {
return;
}
box.remove();
cover.remove();
$(document.body).unbind("keyup", box.onKeyEvent);
};
//修改bug:在iframe中弹出mbox定位错误。li-shun。2013-09-23
//var tp = ($(window).height() - $(box).height()) / 2 + "px";
var tp ;
if(top == window){
tp = ($(window).height() - $(box).height()) / 2 + "px";
} else {
tp = ($('body').height() - $(box).height()) / 2 + $('body').scrollTop() + "px";
}
//if ($.browser.msie && $.browser.version == 6.0) {jQuery 1.9开始移除了$.browser.msie 的方法
if('undefined' == typeof(document.body.style.maxHeight)){
tp = ($(window).height() - $(box).height()) / 2 + $(window).scrollTop() + "px";
} else {
//修改bug:在iframe中弹出mbox定位错误。li-shun。2013-09-23
//box.css("position", "fixed");
box.css("position", "absolute");
}
box.css("display", "none").css({
top : tp
}).fadeIn();
box.onKeyEvent = function(e) {
if (e.keyCode == 27) {
e.stopPropagation();
box.close();
return false;
} else if (e.keyCode == 37) {
if (document.activeElement && document.activeElement.className == "mboxbtn") {
var prev = $(document.activeElement).prev();
if (prev.length > 0 && prev[0].className == "mboxbtn") {
prev[0].focus();
e.stopPropagation();
return false;
}
}
} else if (e.keyCode == 39) {
if (document.activeElement && document.activeElement.className == "mboxbtn") {
var next = $(document.activeElement).next();
if (next.length > 0 && next[0].className == "mboxbtn") {
next[0].focus();
e.stopPropagation();
return false;
}
}
}
};
$(document.body).bind("keyup", box.onKeyEvent);
return box;
};
var validator = function(name, config) {
if (!window["_vldts"]) {
window["_vldts"] = {};
}
this.name = name;
this.config = config ? config : (window[name] ? window[name] : {});
window["_vldts"][name] = this.config;
var self = this;
this.append = function(aconfig) {
for ( var i in aconfig) {
//对已有属性进行覆盖修改为进行扩展,li-shun,2013-06-15
//self.config[i] = aconfig[i];
if(typeof(self.config[i])=="object"){
$.extend(self.config[i],aconfig[i]);
}else {
self.config[i] = aconfig[i];
}
}
return self;
};
this._cleanNode = function(node) {
node.attr("title", "");
if (node.attr("_v_title")) {
node.attr("title", node.attr("_v_title"));
node.attr("_v_title", null);
}
if (!(node.attr("type") && (node.attr("type") == "radio" || node.attr("type") == "checkbox"))) {
node.css("borderColor", "");
//添加borderStyle,修改某些样式下校验边框特别宽的bug
node.css({"borderStyle":"solid","borderWidth":"1px"});
}
if (node.attr("_v_border")) {
if (!(node.attr("type") && (node.attr("type") == "radio" || node.attr("type") == "checkbox"))) {
node.css("borderColor", node.attr("_v_border"));
//添加borderStyle,修改某些样式下校验边框特别宽的bug
node.css({"borderStyle":"solid","borderWidth":"1px"});
}
node.attr("_v_border", null);
}
if (node.attr("_v_vname")) {
node.attr("_v_vname", "_null");
}
};
var fun = function(node, config, render) {
if (!config) {
return [];
}
if (typeof render == "undefined") {
render = true;
}
var v = node.val();
var e = [];
if (config.notNull) {
if (v == null || v == "" || $.trim(v) == "") {
e.push(config.notNull.msg ? config.notNull.msg : "此项不可为空");
}
}
if (v && config.length) {
if (!(config.dataType && config.dataType.type && (config.dataType.type == "date" || config.dataType.type == "timestamp"))) {
var p = true;
var l = v ? slength(v) : 0;
if (config.length.max) {
if (l > config.length.max) {
p = false;
}
}
if (config.length.min) {
if (l < config.length.min) {
p = false;
}
}
if (!p) {
e.push(config.length.msg ? config.length.msg : "输入长度不符合要求");
}
}
}
if (v && config.equalWith) {
if (v != $("#" + config.equalWith["id"]).val()) {
e.push(config.equalWith.msg ? config.equalWith.msg : "输入的值不符");
}
}
if (v && config.email) {
var reg = config.email.regexp ? config.email.regexp : /^\w+((-\w+)|(\.\w+))*\@{1}\w+\.{1}\w{2,4}(\.{0,1}\w{2}){0,1}/ig;
if (v.search(reg) == -1) {
e.push(config.email.msg ? config.email.msg : "输入的邮箱格式不正确");
}
}
if (v && config.url) {
var strRegex = "^((https|http|ftp|rtsp|mms)?://)?(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?"
+ "(([0-9]{1,3}\.){3}[0-9]{1,3}|([0-9a-z_!~*'()-]+\.)*([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\."
+ "[a-z]{2,6})(:[0-9]{1,4})?((/?)|(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$";
var reg = config.url.regexp ? config.url.regexp : new RegExp(strRegex);
if (v.search(reg) == -1) {
e.push(config.url.msg ? config.url.msg : "输入的网址格式不正确");
}
}
if (v && config.regexp) {
if(typeof(config.regexp.regexp)=="string")
config.regexp.regexp = eval("("+config.regexp.regexp+")");
if (v.search(config.regexp.regexp) == -1) {
e.push(config.regexp.msg ? config.regexp.msg : "输入的格式不正确");
}
}
if (v && config.dataType) {
if (config.dataType.type == "date" || config.dataType.type == "java.sql.Date" || config.dataType.type == "java.util.Date"
|| config.dataType.type == "timestamp" || config.dataType.type == "java.sql.Timestamp") {
var reg = new RegExp(
"^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$");
var regt = new RegExp("^([0-1]\\d|2[0-3]):[0-5]\\d:[0-5]\\d$");
var ts = v.split(" ");
if (ts.length > 2) {
e.push(config.dataType.msg ? config.dataType.msg : "输入的日期格式不正确");
} else {
if (ts.length == 1) {
if (ts[0].search(reg) == -1) {
e.push(config.dataType.msg ? config.dataType.msg : "输入的日期格式不正确");
}
} else {
if (ts[0].search(reg) == -1 || ts[1].search(regt) == -1) {
e.push(config.dataType.msg ? config.dataType.msg : "输入的日期格式不正确");
}
}
}
}
if (config.dataType.type == "big_decimal" || config.dataType.type == "java.math.BigDecimal") {
//var reg = new RegExp("^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*))$");
//正则校验错误bug。li-shun。2013-10-23
var reg = new RegExp("^(([0-9]+\\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\\.[0-9]+)|([1-9]\\d*|0))$");
if (v.search(reg) == -1) {
e.push(config.dataType.msg ? config.dataType.msg : "输入的数字格式不正确");
}
}
if (config.dataType.type == "long" || config.dataType.type == "java.lang.Long") {
var reg = new RegExp("^[0-9]*$");
if (v.search(reg) == -1) {
e.push(config.dataType.msg ? config.dataType.msg : "输入的数字格式不正确");
}
}
}
if (v && config.precision && (typeof config.precision.max != "undefined")) {
var pnum = v.split(".");
//修正带有小数位是精度计算未考虑的bug。li-shun。2013-7-17
if(config.scale && (typeof config.scale.max != "undefined")){
if (pnum[0].length > (config.precision.max-config.scale.max)) {
e.push(config.precision.msg ? config.precision.msg : "输入的数字整数部分不能超过" + (config.precision.max-config.scale.max) + "位");
}
}else {
if (pnum[0].length > config.precision.max) {
e.push(config.precision.msg ? config.precision.msg : "输入的数字整数部分不能超过" + config.precision.max + "位");
}
}
}
if (v && config.scale && (typeof config.scale.max != "undefined")) {
var pnum = v.split(".");
if (pnum.length > 1 && pnum[1].length > config.scale.max) {
e.push(config.scale.msg ? config.scale.msg : "输入的数字小数部分不能超过" + config.scale.max + "位");
}
}
if (config.custom) {
config.custom(node, e);
}
if (render) {
if (e.length > 0) {
if (!(node.attr("type") && (node.attr("type") == "radio" || node.attr("type") == "checkbox"))) {
node.css("borderColor", "red");
node.attr("title", e.join(","));
}
}
if (e.length == 0) {
if (!(node.attr("type") && (node.attr("type") == "radio" || node.attr("type") == "checkbox"))) {
node.attr("title", node.attr("_v_title") ? node.attr("_v_title") : "");
node.css("borderColor", node.attr("_v_border") ? node.attr("_v_border") : "");
//添加borderStyle,修改某些样式下校验边框特别宽的bug
node.css({"borderStyle":"solid","borderWidth":"1px"});
}
}
}
return e;
};
this._bindNode = function(node) {
node = $(node);
if (node.attr("title")) {
node.attr("_v_title", node.attr("title"));
}
if (node.css("borderColor")) {
node.attr("_v_border", node.css("borderColor"));
}
if (!node.attr("_v_vname")) {
if (node.attr("validUse")) {
var vu = node.attr("validUse").split(",");
for ( var i = 0; i < vu.length; i++) {
if (!vu[i]) {
continue;
}
node[vu[i]](function() {
if ($(this).attr("_v_vname") && $(this).attr("_v_vname") != "_null") {
fun($(this), window["_vldts"][$(this).attr("_v_vname")][$(this).attr("name")]);
}
});
}
} else {
node.blur(function() {
if ($(this).attr("_v_vname") && $(this).attr("_v_vname") != "_null") {
fun($(this), window["_vldts"][$(this).attr("_v_vname")][$(this).attr("name")]);
}
});
}
}
node.attr("_v_vname", self.name);
};
this.bind = function(formid) {
var form = $(formid);
$("input,select,textarea", form).each(function(i, node) {
node = $(node);
self._cleanNode(node);
if (node.attr("type") && (node.attr("type") == "radio" || node.attr("type") == "checkbox")) {
return;
}
self._bindNode(node);
});
return self;
};
this.unbind = function(formid) {
var form = $(formid);
$("input,select,textarea", form).each(function(i, node) {
node = $(node);
self._cleanNode(node);
});
return self;
};
this.validate = function(formid, show) {
var form = $(formid);
var r = {
hasError : false,
errors : {}
};
if (typeof show == "undefined") {
show = true;
}
$("input,select,textarea", form).each(function(i, node) {
node = $(node);
if (node.attr("type") && (node.attr("type") == "radio" || node.attr("type") == "checkbox")) {
var meta = window["_vldts"][self.name][node.attr("name")];
if (meta) {
if (meta.notNull) {
if ($("input[name='" + node.attr("name") + "']:checked", form).length == 0) {
r.hasError = true;
r["errors"][node.attr("name")] = [ meta.notNull.msg ? meta.notNull.msg : "请至少选择其中一项" ];
}
}
if (meta.length) {
var l = $("input[name='" + node.attr("name") + "']:checked", form).length;
if (meta.length.max && l > meta.length.max) {
r.hasError = true;
r["errors"][node.attr("name")] = [ meta.length.msg ? meta.length.msg : "此项选择数目过多" ];
}
if (meta.length.min && l < meta.length.min) {
r.hasError = true;
r["errors"][node.attr("name")] = [ meta.length.msg ? meta.length.msg : "此项选择数目过少" ];
}
}
}
} else {
var render = false;
if (node.attr("_v_vname") == self.name) {
render = true;
}
var e = fun(node, window["_vldts"][self.name][node.attr("name")], render);
if (e.length > 0) {
r.hasError = true;
r["errors"][node.attr("name")] = e;
}
}
});
if (r.hasError && show) {
var errors = r.errors;
var msg = [];
for ( var i in errors) {
for ( var j = 0; j < errors[i].length; j++) {
msg.push(errors[i][j]);
}
}
var mb = null;
mb = mbox({
title : "提示",
message : msg.join("
"),
buttons : {
"关闭" : function() {
mb.close();
}
}
});
}
return r;
};
};
function slength(inValue) {
inValue = inValue.toString();
if (inValue == null || inValue == "")
return 0;
var len = 0;
for ( var i = 0, l = inValue.length; i < l; i++) {
if (inValue.charCodeAt(i) < 128) {
len++;
continue;
}
len += 2;
}
return len;
}
function showDialog(src, title, width, height, callback) {
if ($("#frame1").length != 0) {
$("#frame1")[0].parentNode.removeChild($("#frame1")[0]);
}
$("")
.appendTo(document.body);
$("#frame1").attr("src", src);
$("#frame1").dialog({
title : title,
width : width,
height : height,
modal : true,
draggable : false,
resizable : false,
parameter : "",
close : function() {
if (callback) {
callback();
}
}
});
$("#frame1").dialog("option", "title", title);
$("#frame1").dialog("option", "width", width + 20);
$("#frame1").dialog("option", "height", height + 20);
$("#frame1").dialog("open");
$("#frame1").css("width", width);
$("#frame1").css("height", height);
}
String.prototype.getBytes = function() {
var cArr = this.match(/[^\x00-\xff]/ig);
return this.length + (cArr == null ? 0 : cArr.length);
}
function closeDialog(callback) {
var $dialog = $("#frame1");
if(callback) {
callback($dialog[0].contentWindow)
}
$dialog.dialog("close");
}
$(function(){
$(".Wdate").click(function(){
if(!((typeof WdatePicker)==="undefined")){
WdatePicker();
}
})
})
//获取QueryString的数组
function getQueryString() {
var result = location.search.match(new RegExp("[\?\&][^\?\&]+=[^\?\&]+", "g"));
if (result == null) {
return "";
}
for ( var i = 0; i < result.length; i++) {
result[i] = result[i].substring(1);
}
return result;
}
//根据QueryString参数名称获取值
function getQueryStringByName(name) {
var result = location.search.match(new RegExp("[\?\&]" + name + "=([^\&]+)", "i"));
if (result == null || result.length < 1) {
return "";
}
return result[1];
}
//根据QueryString参数索引获取值
function getQueryStringByIndex(index) {
if (index == null) {
return "";
}
var queryStringList = getQueryString();
if (index >= queryStringList.length) {
return "";
}
var result = queryStringList[index];
var startIndex = result.indexOf("=") + 1;
result = result.substring(startIndex);
return result;
}
//处理键盘事件 禁止后退键(Backspace)密码或单行、多行文本框除外
function forbidBackSpace(e) {
var ev = e || window.event;
//获取event对象
var obj = ev.target || ev.srcElement;
//获取事件源
//事件源为为空object时出现bug。li-shun。2013-10-24
if(obj.type === undefined && obj.getAttribute === undefined){
return ;
}
var t = obj.type || obj.getAttribute('type');
//获取事件源类型
//获取作为判断条件的事件类型
var vReadOnly = obj.readOnly;
var vDisabled = obj.disabled;
//处理undefined值情况
vReadOnly = (vReadOnly == undefined) ? false : vReadOnly;
vDisabled = (vDisabled == undefined) ? true : vDisabled;
//当敲Backspace键时,事件源类型为密码或单行、多行文本的,
//并且readOnly属性为true或disabled属性为true的,则退格键失效
var flag1 = ev.keyCode == 8
&& (t == "password" || t == "text" || t == "textarea")
&& (vReadOnly == true || vDisabled == true);
//当敲Backspace键时,事件源类型非密码或单行、多行文本的,则退格键失效
var flag2 = ev.keyCode == 8 && t != "password" && t != "text"
&& t != "textarea";
//判断
if (flag2 || flag1)
return false;
}
//cms模板用局部翻页
function agilewebCmsTemplatePageJump(page, element){
var $element = $(element),
$template = $element.parents(".agileweb-cmstemplate-content:first"),
agilewebTemplateId = $template.attr("agileweb-cms-templete-id"),
pd = window["agilewebCmsTempleteId_"+agilewebTemplateId];
cover = $("").css({
height : $template.height() + "px",
width: $template.width()+"px",
top: $template.offset().top,
left: $template.offset().left
}).appendTo(document.body);
$template.load("/ww/z/z/f/wwzzf_get_html.html",{data: pd, page: page},function(data){
cover.remove();
});
}
$(function() {
//禁止后退键 作用于Firefox、Opera
document.onkeypress = forbidBackSpace;
//禁止后退键 作用于IE、Chrome
document.onkeydown = forbidBackSpace;
});
function getCookie(c_name) {
if (document.cookie.length > 0) {
c_start = document.cookie.indexOf(c_name + "=")
if (c_start != -1) {
c_start = c_start + c_name.length + 1
c_end = document.cookie.indexOf(";", c_start)
if (c_end == -1)
c_end = document.cookie.length
return unescape(document.cookie.substring(c_start, c_end))
}
}
return ""
}
function showCoverMask(zIndex){
if(zIndex){
var cover = $("").css({
width : $(window).width(),
height : $(window).height(),
opacity : 0.7,
"z-index" : zIndex
}).appendTo($("body"));
$("body").append($("数据处理中,请稍等..."));
}else{
var cover = $("").css({
width : $(window).width(),
height : $(window).height(),
opacity : 0.7
}).appendTo($("body"));
$("body").append($("数据处理中,请稍等..."));
}
}
function hideCoverMask(){
$(".covermask,.loading,.loadingspan").remove();;
}