使用jquery的js的页面实现例子

var validate;
var nodeId="";
var modifyappId="";
addExportTaskURL = ctx + "/xflow/addExportTaskXFLow.do",
$(document).ready(
function() {
var flag = true;
var searFlag = true;
/**
* initial the page.
*/
initBtn();
window.screen.width;
/**
* initial the table.
*/
appMappingGrid();
/**
* search button
*/
//search
$("#search").bind("focus", function() {
if (searFlag) {
$("#search").val(null);
searFlag = false;
}
});
$('#search').inspurSearchField(
{
watermark:lang.xflow.searchPromp,
onclick : function(val)
{
if(searFlag)
{
$("#search").val(null);
searFlag = false;
}

var searchvalue = $('#search').val();
// 首先校验查询参数,特殊字符和长度
if(searchvalue != "" && searchvalue != null)
{
var regex = new RegExp(/^[\w\_\-\(\)\.\/\#\$\%\~\@\s\:\=\,\;]*$/);
if(!regex.test(searchvalue)){
$.inspurMessageBox.alert({
type:"error",
title:"Info",
content:lang.xflow.searchtip
});
return false;
}
}
if(searchvalue.length > 128 )
{
$.inspurMessageBox.alert({
type:"error",
title:"Info",
content:lang.xflow.searchlength
});
}

if (searchvalue != null && searchvalue != "") {
$("#appMappingGrid")
.inspurTable(
"setData",
ctx+ "/xflow/searchAppMappingListXFlow.do?appName="
+ encodeURIComponent(searchvalue));
}
else
{
appMappingGrid();
}
}
});
/**
* 创建时候的校验
*/
addValidation(false);

});

/**
* 初始化按钮
*/
function initBtn() {
// 初始化Create按钮
$("#createAppMappingBtn").inspurButton({
iconCls : "m_icon_oper_add",
label : lang.xflow.createbtn,
onClick : function(event) {
/**
* 创建或修改域的对话框
*/
//表单重置
validate.resetForm();
//删除错误样式
validate.elements().removeClass("error-border");
validate.elements().removeClass("x-form-invalid");
nodeId = "create";
clearInput();
// 设置默认值
// 控件解禁用按钮
$("#port").attr("disabled", false);
$("#TLPType").inspurCombo("enable");
var input = $("#IPRadio").find("input:radio");
input.attr("disabled", false);
$("#IPv41").attr("disabled", false);
$("#IPv42").attr("disabled", false);
$("#IPv43").attr("disabled", false);
$("#IPv44").attr("disabled", false);
$("#IPv61").attr("disabled", false);
$("#IPv62").attr("disabled", false);
$("#IPv63").attr("disabled", false);
$("#IPv64").attr("disabled", false);
$("#IPv65").attr("disabled", false);
$("#IPv66").attr("disabled", false);
$("#IPv67").attr("disabled", false);
$("#IPv68").attr("disabled", false);

// $("#IPType").inspurCombo("value","IP Address");
$("#TLPType").inspurCombo("value", "TCP");
// IP隐藏
$("#IPAddressv4").hide();
$("#IPAddressv6").hide();
var dialog = $("#dialog-form").inspurWindow({
width : 700,
height : 300,
autoOpen : false,
modal : true,
resizable : false,
draggable : true,
onClose : function() {
create_form.reset();
}
});
// $("#port").attr("enable", true);
showDialog(dialog, lang.xflow.CreateAppMapping);
}
});

// 初始化modify按钮
$("#modifyAppMappingBtn")
.inspurButton(
{
iconCls : "m_icon_oper_edit",
greyIconCls : "m_icon_oper_edit_grey",
label : lang.xflow.modifybtn,
onClick : function(event) {
/**
* 创建或修改域的对话框
*/
//表单重置
validate.resetForm();
//删除错误样式
validate.elements().removeClass("error-border");
validate.elements().removeClass("x-form-invalid");
nodeId = "modify";
clearInput();
var records = $('#appMappingGrid').inspurTable(
'getSelections', true);
if (records.length == 1) {
modifyappId = records[0].appID;
port = records[0].dstPort;// 要回显的信息的port
appName = records[0].appName;
ipAddress = records[0].ipAddress;
protocolType = records[0].protocolType;
$("#modifyAppMappingBtn")
.inspurButton('enable');
}
// $('.errorMsg_leon').prev().removeClass("error-border");
// $('.errorMsg_leon').prev().removeClass("x-form-invalid");
// 获取弹出窗口的值
$.ajax({
dataType : "json",
async : false,
cache : false,
url : ctx
+ "/xflow/getOneAppMappingXFlow.do",
data : {
modifyAppID : modifyappId,
modifyPort : port,
modifyIPAddress : ipAddress,
modifyProtocolType: protocolType
},
success : function(oneData) {
var dialog = $("#dialog-form")
.inspurWindow({
width : 650,
height : 300,

autoOpen : false,
modal : true,
resizable : false,
draggable : true,
onClose : function() {
// parent.disgrey();
// 清除提示信息
// validate_parameter.resetForm();
}
});
showDialog(dialog, lang.xflow.ModifyAppMapping);
$("#port").val(escapeHtml(oneData.dstPort));
$("#TLPType").inspurCombo("value",escapeHtml(oneData.protocolType));
var ipResult = oneData.ipAddress;
if (ipResult.indexOf(".") > 0)
// 当为IPv4 的时候,判断为ALL 还是普通的IPv4
{
if (ipResult != "0.0.0.0") {
$('input[name=IPType]')
.get(1).checked = true;// 第2个radio被选中
// $("input[@type=radio]").attr("checked",'2');//设置value=2的项目为当前选中项
$("#IPAddressv4").show();
$("#IPAddressv6").hide();
var ipv4Array = ipResult.split(".");
$("#IPv41").val(ipv4Array[0]);
$("#IPv42").val(ipv4Array[1]);
$("#IPv43").val(ipv4Array[2]);
$("#IPv44").val(ipv4Array[3]);
} else if (ipResult == "0.0.0.0")

{
// $("input[@type=radio]").attr("checked",'1');//设置value=1的项目为当前选中项
$('input[name=IPType]').get(0).checked = true;// 第一个radio被选中
$("#IPAddressv4").hide();
$("#IPAddressv6").hide();
}
}// 当时ipv4的时候结束
// ipv6 的时候开始
else if (ipResult.indexOf(":") > 0) {
// $("input[@type=radio]").attr("checked",'3');//设置value=3的项目为当前选中项
$('input[name=IPType]').get(2).checked = true;// 第三个radio被选中
$("#IPAddressv4").hide();
$("#IPAddressv6").show();
var ipv6Array = ipResult.split(":");
$("#IPv61").val(ipv6Array[0]);
$("#IPv62").val(ipv6Array[1]);
$("#IPv63").val(ipv6Array[2]);
$("#IPv64").val(ipv6Array[3]);
$("#IPv65").val(ipv6Array[4]);
$("#IPv66").val(ipv6Array[5]);
$("#IPv67").val(ipv6Array[6]);
$("#IPv68").val(ipv6Array[7]);

} else {
alert(lang.xflow.IPerror);
}

$("#appName").val(escapeHtml(oneData.appName));
$("#description").val(escapeHtml(oneData.description))
// updatemoTypeID =
// escapeHtml(data.moTypeID);//点击next后会用这个值后台查询域的要显示的值
}// success

});

// 禁用前三个按钮(主键:port+protocolType+id)
// 控件禁用
$("#port").attr("disabled", true);
$("#TLPType").inspurCombo("disable");
var input = $("#IPRadio").find("input:radio");
input.attr("disabled", "disabled");

$("#IPv41").attr("disabled", true);
$("#IPv42").attr("disabled", true);
$("#IPv43").attr("disabled", true);
$("#IPv44").attr("disabled", true);
$("#IPv61").attr("disabled", true);
$("#IPv62").attr("disabled", true);
$("#IPv63").attr("disabled", true);
$("#IPv64").attr("disabled", true);
$("#IPv65").attr("disabled", true);
$("#IPv66").attr("disabled", true);
$("#IPv67").attr("disabled", true);
$("#IPv68").attr("disabled", true);
}
});

// 初始化Delete按钮
$("#deleteAppMappingBtn")
.inspurButton(
{
iconCls : "m_icon_oper_delete",
greyIconCls : "m_icon_oper_delete_grey",
label : lang.xflow.deletebtn,//lang.System.indicatormgt.deletebtn,
onClick : function(event) {
var records = $('#appMappingGrid').inspurTable(
'getSelections', true);
if (0 < records.length) {
$.inspurMessageBox
.confirm({
title : lang.xflow.confdel,
content :lang.xflow.confsure,
onClose : function(value) {
if (value) {
// 删除操作
var deletePort = "";
var deleteAppName = "";
var deleteIPAddress="";
var deleteProtocolType ="";
var deleteAppID= "";
$.each(
records,
function(idx,item) {
deletePort += item.dstPort
+ ",";
deleteProtocolType += item.protocolType
+ ",";
deleteIPAddress += item.ipAddress
+ ",";
deleteAppID += item.appID
+",";
deleteAppName += item.appName
+",";
});

if (deletePort.length > 0) {
deletePort = deletePort.substr(0,deletePort.length - 1);
}
if (deleteAppName.length > 0) {
deleteAppName = deleteAppName.substr(0,deleteAppName.length - 1);
}
if (deleteAppID.length > 0) {
deleteAppID = deleteAppID.substr(0,deleteAppID.length - 1);
}
if (deleteProtocolType.length > 0) {
deleteProtocolType = deleteProtocolType.substr(0,deleteProtocolType.length - 1);
}
$.ajax({
async : false,
cache : false,
url : ctx
+ "/xflow/delAppMappingXFlow.do",
dataType : "json",
data : {
deletePort : deletePort,
deleteProtocolType : deleteProtocolType,
deleteIPAddress : deleteIPAddress,
deleteAppID : deleteAppID,
deleteAppNames : deleteAppName
},
success : function(data)
{
if (data == true) {
$.inspurMessageBox.alert({
type : lang.xflow.confirmsuccesstip,
content : lang.xflow.confirmsuccesscontent,
onClose : function(value) {
if (value) {
$("#search").val(null);
value = false;
}

appMappingGrid();
// //删除成功后按钮置灰
$('#modifyAppMappingBtn').inspurButton('disable');
$('#deleteAppMappingBtn').inspurButton('disable');
}
});
} else if (data == false) {
$.inspurMessageBox
.alert({
content : lang.xflow.confirmfail
});
return;
} else {
$.inspurMessageBox
.alert({
type : lang.xflow.confirmfail,
content : lang.xflow.confirmfail
});
return;
}
}
})// ajax end
//
}// if(value) end
}
})
}// if() end
}
});

$('#deleteAppMappingBtn').inspurButton('disable');
$("#modifyAppMappingBtn").inspurButton('disable');

// 初始化import按钮
$("#importAppMappingBtn").inspurButton({
iconCls : "m_icon_oper_import",
greyIconCls : "m_icon_oper_import_grey",
label : lang.xflow.importbtn,
onClick : function(event) {
// $("#importForm").inspurWindow('open');
var filepath = $("#appMappingfileupload").val();
$("#importpath").val(filepath);
var dialog = $("#importForm").inspurWindow({
width : 450,
height : 150,
autoOpen : false,
modal : true,
resizable : false,
draggable : true,
onClose : function() {

}
});

showDialog(dialog, lang.xflow.ImportAppMapping);
$("#appMappingfileupload").val("");
}
});

// 初始化export按钮
$("#exportAppMappingBtn").inspurButton({
iconCls : "m_icon_oper_export",
greyIconCls : "m_icon_oper_export_grey",
label : lang.xflow.exportbtn,
onClick : function(event) {
$("#excelTypeCombo").inspurCombo("value", "excel2007");
var dialog = $("#exportForm").inspurWindow({
width : 400,
height : 100,
autoOpen : false,
modal : true,
resizable : false,
draggable : true,
onClose : function() {

}
});

showDialog(dialog, lang.xflow.ExportAppMapping);
}

});

$("#IPAddressv4").hide();
$("#IPAddressv6").hide();


$("#save")
.inspurButton(
{
width : 70,
label : lang.xflow.create.save,
onClick : function(event) {
addValidation(true);
if ($("#create_form").valid()) {
var port = $("#port").val();
var transportLayerProtocol = $("#TLPType")
.val();
var ipType = $("input[name=IPType]:checked")
.val();
var appName = $("#appName").val();
var description = $("#description").val();
// }
// 处理IP地址分类,拼接IP地址 start
if (ipType == 1) {
ip = "0.0.0.0";
} else if (ipType == 2) {
ip = $("#IPv41").val() + "."
+ $("#IPv42").val() + "."
+ $("#IPv43").val() + "."
+ $("#IPv44").val();
} else {
ip = $("#IPv61").val() + ":"
+ $("#IPv62").val() + ":"
+ $("#IPv63").val() + ":"
+ $("#IPv64").val() + ":"
+ $("#IPv65").val() + ":"
+ $("#IPv66").val() + ":"
+ $("#IPv67").val() + ":"
+ $("#IPv68").val();

}
// 处理IP地址分类,拼接IP地址 end
var path = "";
if (nodeId == "create") {
path = "/xflow/createAppMappingXFlow.do"
} else {
path = "/xflow/modifyAppMappingXFlow.do?modifyAppID="+modifyappId;
}
// 提交
$.ajax({
type : "post",
dataType : "json",
url : ctx + path,
async : false,
data : {
port : port,
transportLayerProtocol : transportLayerProtocol,
appName : appName,
description : description,
// startIP:startIP,
// endIP:endIP,
ip : ip
},
success : function(result) {
if (result == "success") {
$.inspurMessageBox
.alert({
type : lang.xflow.alertwindow,
title : lang.xflow.savewindowtitle,
content : lang.xflow.tipsuccess
})

$('#appMappingGrid').inspurTable("reload");// 表格刷新
$("#dialog-form").inspurWindow("close");// 关闭窗口
} else if(result =="fail"){
$.inspurMessageBox.alert({
type : lang.xflow.alertwindowtype,
title :lang.xflow.errorwindowtitle,
content :lang.xflow.savefail
})
} else if(result =="duplication")
{//主键重复报错
$.inspurMessageBox.alert({
type : lang.xflow.alertwindowtype,
title :lang.xflow.errorwindowtitle,
content :lang.xflow.keyduplication
})
}
//后台的校验不过,显示相关信息
else if(result == "error1")
{// error
$.inspurMessageBox.alert({
type : lang.xflow.alertwindowtype,
title :lang.xflow.errorwindowtitle,
content :lang.xflow.error1
})
}
else if(result == "error2")
{// error
$.inspurMessageBox.alert({
type : lang.xflow.alertwindowtype,
title :lang.xflow.errorwindowtitle,
content :lang.xflow.error2
})
}
else if(result == "error3")
{// error
$.inspurMessageBox.alert({
type : lang.xflow.alertwindowtype,
title :lang.xflow.errorwindowtitle,
content :lang.xflow.error3
})
}
else if(result == "error4")
{// error
$.inspurMessageBox.alert({
type : lang.xflow.alertwindowtype,
title :lang.xflow.errorwindowtitle,
content :lang.xflow.error4
})
}
else if(result == "error5")
{// error
$.inspurMessageBox.alert({
type : lang.xflow.alertwindowtype,
title :lang.xflow.errorwindowtitle,
content :lang.xflow.error5
})
}
}
})// ,
// submitDialog(dialog,validate);
return false; // 防止默认提交
}
}
});
$("#cancel").inspurButton({
width : 70,
label :lang.xflow.create.cancel,
onClick : function(event) {
//表单重置
validate.resetForm();
//删除错误样式
validate.elements().removeClass("error-border");
validate.elements().removeClass("x-form-invalid")
$("#dialog-form").inspurWindow("close");// 关闭窗口
}
});
// IP类型的选择输入框的显示
showIP();
$("input[name=IPType]").click(function() {
showIP();
});
// TransportLayerProtocol 下拉框
$("#TLPType").inspurCombo({
editable : false,
width : 150,

dataSource : [ {
"text" : "TCP",
"value" : "TCP"
}, {
"text" : "UDP",
"value" : "UDP"
}, {
"text" : "SCTP",
"value" : "SCTP"
} ]

// optionField :"ruleVersionCode" ,
// valueField : "ruleVersionID"
});

// AppName 下拉框
$("#excelTypeCombo").inspurCombo({
editable : false,
width : 150,
dataSource : [ {
"text" : "excel2007",
"value" : "excel2007"
}
// , {
// "text" : "excel2003",
// "value" : "excel2003"
// }
]
// optionField :"ruleVersionCode" ,
// valueField : "ruleVersionID"
});
$("import-result").inspurWindow({
title:lang.xflow.ImportResult,
autoOpen : false,
width : 950,
height : 450,
resizable : false,
draggable : true,
modal : true

});

$("#importBtn")
.inspurButton(
{
width : 70,
label :lang.xflow.importbtn,
onClick : function(event) {

var filepath = $("#appMappingfileupload").val();
var fileName = filepath.substring(filepath
.lastIndexOf('\\') + 1, filepath.length);

if (null == filepath || "" == filepath) {
$.inspurMessageBox.alert({
content : lang.xflow.windowtip
});
return;
} else {
var fileObject = $("input[id='appMappingfileupload']");
var fileArr = filepath.split("\\");
var fileTArr = fileArr[fileArr.length - 1]
.toLowerCase().split(".");
var filetype = fileTArr[fileTArr.length - 1];

if (filetype != "xls" && filetype != "xlsx") {
$.inspurMessageBox.alert({
content :lang.xflow.windowtiptype
});
return;
}
}

var actionPath = "/xflow/importAppMappingXFlow.do?fileName="
+ fileName;
$("#importForm").attr("action", actionPath);
var options = {
dataType : "json",
type : 'post',
url : ctx + actionPath,
beforeSubmit : function showRequest(formData,
jqForm, options) {
// 显示等待提示框
$.omMessageBox.waiting({
title : lang.xflow.tipwait,
content :lang.xflow.tipwaiting
});
// 在导入数据时禁用Cancel按钮
$("#importCancelBtn")
.attr('disabled', true);
},
success : function showResponse(data,
statusText) {

$("#importForm").resetForm();
if(data.countMessage == "0"){
$.inspurMessageBox.alert({
type : lang.xflow.windowtypeerror,
title : lang.xflow.windowtypeerrortitle,
content: lang.xflow.windowtypeerrorcontent
});
// 关闭等待提示框
$.omMessageBox.waiting('close');
}
else{

// 导入数据成功后启用Cancel按钮
$("#importCancelBtn").attr('disabled', false);
// 关闭等待提示框
$.omMessageBox.waiting('close');
$("#importForm").inspurWindow("close");
$("#import-result").show();
var dialog = $("#resultContainer").inspurWindow({
width : 950,
height : 450,
autoOpen : false,
modal : true,
resizable : false,
draggable : true,
onClose : function() {

}
});

showDialog(dialog, lang.xflow.ImportResult);
initImportResult(data);
$('#appMappingGrid').inspurTable("reload");// 表格刷新
// 初次进入页面,灰掉modify和delete按钮
$('#modifyAppMappingBtn').inspurButton('disable');
$('#deleteAppMappingBtn').inspurButton('disable');
}// if --else end

},// success end

clearForm : true
};
$("#importForm").ajaxSubmit(options);
// $("#appMappingfileupload").val("");
}
});
// import 的template 下载操作
$("#templatehref").bind('click', function() {
downloadTemplate();
});

$("#importCancelBtn").inspurButton({
width : 70,
label : lang.xflow.create.cancel,
onClick : function(event) {
if ($(this).attr('disabled') != 'disabled') {
$("#importForm").inspurWindow("close");
}
$("#appMappingfileupload").val("");
}
});

$("#exportBtn").inspurButton({
width : 70,
label : lang.xflow.create.save,
onClick : function(event) {

var versionVal = $("#excelTypeCombo").inspurCombo("value");
var dstPort = "";
var protocolType = "";
var ipAddress ="";
var appName = "";
var description ="";
// 导出search框的部分表格
if($("#search").val()!= null)
{
appName = $("#search").val();
}
$.post(ctx + "/xflow/exportXFlow.do?",{
protocolType : protocolType,
ipAddress : ipAddress,
appName :appName,
description : description,
versionVal : versionVal
},function(data){
{
$("#exportForm").attr("action",ctx+'/xflow/downloadXFlow.do?filePath=' + data.filePath ).submit();
}
// }
// $('body').hidemask();
},'json');
// --------
}
});
$("#exportCancelBtn").inspurButton({
width : 70,
label : lang.xflow.create.cancel,
onClick : function(event) {
$("#exportForm").inspurWindow("close");
}
});

}// 初始化的结束

/**
* 生成表格的函数
*/
var appMappingGrid = function() {
$("#appMappingGrid").inspurTable({
height : document.body.clientHeight * 0.80,
width : document.body.clientWidth * 0.99,
// height : window.screen.height - 400,
// width : window.screen.width - 275 - 90,
limit : 20,
singleSelect : false,
autoFit : true,
colModel : [ {
header : lang.xflow.header.DstPort,
name : "dstPort",
// width : 200,
align : "left"
}, {
header : lang.xflow.header.ProtocolType,
name : "protocolType",
// width : "autoExpand",
align : "left"
}, {
header : lang.xflow.header.IPAddress,
name : "ipAddress",
// width : 200,
align : "left"
}, {
header : lang.xflow.header.Application,
name : "appName",
// width : 200,
align : "left"
}, {
header : lang.xflow.header.Description,
name : "description",
// width : "autoExpand",
align : "left"
}, {
header : lang.xflow.header.ModifyTime,
name : "modifyTime",
// width : "autoExpand",
align : "left"

} ],
dataSource : ctx + "/xflow/getAppMappingListXFlow.do",

/**
* change of the radio
*/
onRowDeselect : function(rowIndex, rowData, event) {// 添加表格记录选择事件
var selections = $('#appMappingGrid').inspurTable('getSelections');
if (selections.length == 1) {
$('#modifyAppMappingBtn').inspurButton('enable');
} else {
$('#modifyAppMappingBtn').inspurButton('disable');
}
if (selections.length > 0) {
$('#deleteAppMappingBtn').inspurButton('enable');
} else {
$('#deleteAppMappingBtn').inspurButton('disable');
}
},
onRowSelect : function(rowIndex, rowData, event) {
var selections = $('#appMappingGrid').inspurTable('getSelections');
if (selections.length == 1) {
$('#modifyAppMappingBtn').inspurButton('enable');
} else {
$('#modifyAppMappingBtn').inspurButton('disable');
}
if (selections.length > 0) {
$('#deleteAppMappingBtn').inspurButton('enable');
} else {
$('#deleteAppMappingBtn').inspurButton('disable');
}
}
})
};

 

/**
* 用于修改,添加一个新域的对话框
*
* @param {}dialog
* 对话框
* @param {}title
* 标题
* @param {}rowData
* 被选择的行数据,如果为创建则为空
*/
var showDialog = function(dialog, title, rowData) {

rowData = rowData || {};
$("input[name='id']", dialog).val(rowData.domainID);
$("input[name='domainname_d']", dialog).val(escapeHtml(rowData.domainName));
$('#description').val(escapeHtml(rowData.remark));
dialog.inspurWindow("setTitle", title);
dialog.inspurWindow("open");// 打开Dialog

}

function addValidation(flag) {

// // ip 校验

var ipv4flag = false;
var ipv6flag = false;
if($("input[name=IPType]:checked").val()==2){
ipv4flag = true;
ipv6flag = false;
} else if ( $("input[name=IPType]:checked").val()==3){
ipv4flag = false;
ipv6flag = true;
} else {
ipv4flag = false;
ipv6flag = false;
}

$.validator.addMethod("appNameCheck",function(value, element)
{// AppName验证
return this.optional(element)|| /^[\w\_\-\(\)\.\/\#\$\%\~\@\s\:\,\;\=]*$/.test(value);
},
lang.xflow.appNameword);
$.validator.addMethod("descriptionCheck",function(value, element)
{// Description验证
return this.optional(element)|| /^[\x20-\x7F|\r\n]*$/.test(value);
},
lang.xflow.descriptionword);
//ipv4
$.validator.addMethod("ipv4Check",function(value, element)
{//ipv4 rule
return this.optional(element)|| /^(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])$/.test(value);
},
lang.xflow.IPerror);

$.validator.addMethod("ipv6Check",function(value, element)
{// ipv6验证
return this.optional(element)|| /^[0-9a-fA-F]{1,4}$/.test(value);
},
lang.xflow.validate.appname.show);
validate = $("#create_form").validate(
{
rules : {
port : {
required : true,
digits : true,
range : [0,65535]
},
description : {
descriptionCheck : true,
maxlength : 512
},
appName : {
appNameCheck : true,
maxlength : 128,
required : true
},
//ipv4
IPv41 : {
ipv4Check : true,
required: function()
{// ipv4验证
if($("input[name=IPType]:checked").val()==2){
return true;
}else{
return false;
}
},
range : [ 0, 255 ]
},
IPv42 : {
ipv4Check : true,
required: function()
{// ipv4验证
if($("input[name=IPType]:checked").val()==2){
return true;
}else{
return false;
}
},
range : [ 0, 255 ]
},
IPv43 : {
ipv4Check : true,
required: function()
{// ipv4验证
if($("input[name=IPType]:checked").val()==2){
return true;
}else{
return false;
}
},
range : [ 0, 255 ]
},
IPv44 : {
ipv4Check : true,
required: function()
{// ipv4验证
if($("input[name=IPType]:checked").val()==2){
return true;
}else{
return false;
}
},
range : [ 0, 255 ]
},
//
//ipv6
IPv61 : {
ipv6Check : true,
required: function()
{// ipv6验证
if($("input[name=IPType]:checked").val()==3){
return true;
}else{
return false;
}
},
minlength: 1,
maxlength: 4
},
IPv62 : {
ipv6Check : true,
minlength: 1,
maxlength: 4,
required: function()
{// ipv6验证
if($("input[name=IPType]:checked").val()==3){
return true;
}else{
return false;
}
}
},
IPv63 : {
ipv6Check : true,
minlength: 1,
maxlength: 4,
required: function()
{// ipv6验证
if($("input[name=IPType]:checked").val()==3){
return true;
}else{
return false;
}
}
},
IPv64 : {
ipv6Check : true,
minlength: 1,
maxlength: 4,
required: function()
{// ipv6验证
if($("input[name=IPType]:checked").val()==3){
return true;
}else{
return false;
}
}
},

IPv65 : {
ipv6Check : true,
minlength: 1,
maxlength: 4,
required: function()
{// ipv6验证
if($("input[name=IPType]:checked").val()==3){
return true;
}else{
return false;
}
}

},
IPv66 : {
ipv6Check : true,
minlength: 1,
maxlength: 4,
required: function()
{// ipv6验证
if($("input[name=IPType]:checked").val()==3){
return true;
}else{
return false;
}
}
},
IPv67 : {
ipv6Check : true,
minlength: 1,
maxlength: 4,
required: function()
{// ipv6验证
if($("input[name=IPType]:checked").val()==3){
return true;
}else{
return false;
}
}
},
IPv68 : {
ipv6Check : true,
minlength: 1,
maxlength: 4,
required: function()
{// ipv6验证
if($("input[name=IPType]:checked").val()==3){
return true;
}else{
return false;
}
}
}
},
messages : {
//增加ipv4 的校验
IPv41 : {
ipv4Check : lang.xflow.ipwarn
},
IPv42 : {
ipv4Check : lang.xflow.ipwarn
},
IPv43 : {
ipv4Check : lang.xflow.ipwarn
},
IPv44 : {
ipv4Check : lang.xflow.ipwarn
},
//ipv6
IPv61 : {
ipv6Check : lang.xflow.ipwarn
},
IPv62 : {
ipv6Check : lang.xflow.ipwarn
},
IPv63 : {
ipv6Check : lang.xflow.ipwarn
},
IPv64 : {
ipv6Check : lang.xflow.ipwarn
},
IPv65 : {
ipv6Check : lang.xflow.ipwarn
},
IPv66 : {
ipv6Check : lang.xflow.ipwarn
},
IPv67 : {
ipv6Check :lang.xflow.ipwarn
},
IPv68 : {
ipv6Check : lang.xflow.ipwarn
},

port : {
required : lang.xflow.validate.port.show,
range : lang.xflow.validate.port.showrang
},
description : {
maxlength :lang.xflow.validate.description.showrange
},
appName : {
required :lang.xflow.validate.appname.show,
maxlength : lang.xflow.validate.appname.showrange
}
},
submitHandler : function() {
$(this)[0].currentForm.reset()
return false;
},
errorPlacement : function(error, element) {
if (error.html()) {
$(element).parents().map(
function() {
var attentionElement = $(this).children().eq(1);
if (this.tagName.toLowerCase() == 'td') {
attentionElement.html(error);
attentionElement.css(
'display',
'none'); // 覆盖默认显示方法,先隐藏消息,等鼠标移动上去再显示
attentionElement.prev().addClass(
"error-border");
attentionElement.prev()
.children("input")
.addClass("x-form-invalid");
if (attentionElement.prev()
.children().length <= 0)
attentionElement.prev().addClass(
"x-form-invalid");
}
});
}
},
// 控制错误显示隐藏的方法,当自定义了显示方式之后一定要在这里做处理。
showErrors : function(errorMap, errorList) {
if(errorList && errorList.length > 0){
$.each(errorList,function(index,obj){
var msg = this.message;
$(obj.element).parents().map(function(){
if(this.tagName.toLowerCase()=='td'){
var attentionElement = $(this).children().eq(1);
attentionElement.show();
attentionElement.html(msg);
}
});
});
} else {
$(this.currentElements).parents().map(function(){
if(this.tagName.toLowerCase()=='td'){
$(this).children().eq(1).hide();
$(this).children().eq(0).removeClass("error-border");
}else{
$(this).removeClass("error-border");
}
$(this).children().eq(0).removeClass("x-form-invalid");
});
}
this.defaultShowErrors();
}
});
$('.errorMsg_leon').prev().bind('mouseover',function(e){
//要有错误才显示
if($(this).next().html().length > 0 && $(this).next().find("label").html().length > 0){
$(this).next().css('display','inline').css({'top':$(this).offset().top + $(this).height()+ 5 , 'left':$(this).offset().left});
if($(this).next().find("label").css('display') == 'none'){
$(this).next().hide();
}
}
}).bind('mouseout',function(){
$(this).next().css('display','none');
});
}

/**
* 清空新增界面
*/
function clearInput() {
$("#port").val("");
// $("#startIP").val("");
// $("#endIP").val("");
$("#IP").val("");
$("#IPv41").val("");
$("#IPv42").val("");
$("#IPv43").val("");
$("#IPv44").val("");
$("#IPv61").val("");
$("#IPv62").val("");
$("#IPv63").val("");
$("#IPv64").val("");
$("#IPv65").val("");
$("#IPv66").val("");
$("#IPv67").val("");
$("#IPv68").val("");
$('input:radio[name="IPType"][value="1"]').prop('checked', true);
$("#TLPType").inspurCombo("value", "TCP");
$("#appName").val("");
$("#description").val("");
}

// 清空表单
function clearForm(form) {
// iterate over all of the inputs for the form
// element that was passed in
$(':input', form).each(function() {
var type = this.type;
var tag = this.tagName.toLowerCase(); // normalize case
// it's ok to reset the value attr of text inputs,
// password inputs, and textareas
if (type == 'text' || type == 'password' || tag == 'textarea')
this.value = "";
// checkboxes and radios need to have their checked state cleared
// but should *not* have their 'value' changed
else if (type == 'checkbox' || type == 'radio')
this.checked = false;
// select elements need to have their 'selectedIndex' property set to -1
// (this works for both single and multiple select elements)
else if (tag == 'select')
this.selectedIndex = -1;
});
}

/**
* clear up form
*/
function clear_form() {
$(':input,#form').not(':button, :submit, :reset, :hidden').val('')
.removeAttr('checked').removeAttr('selected');
}
/**
* 根据IPType 选择显示和隐藏IPType 的输入框
*/
function showIP() {
switch ($("input[name=IPType]:checked").attr("id")) {
case "IPType1":
$("#IPAddressAll").hide();
$("#IPAddressv4").hide();
$("#IPAddressv6").hide();
break;
case "IPType2":
$("#IPAddressAll").hide();
$("#IPAddressv4").show();
$("#IPAddressv6").hide();
break;
case "IPType3":
$("#IPAddressAll").hide();
$("#IPAddressv4").hide();
$("#IPAddressv6").show();
break;
default:
break;

}
}

/**
* excel 下载模板
*/
function downloadTemplate() {
window.location.href = ctx + '/pages/xflow//xflowDownloadTemplate.jsp';
};

 

posted on 2015-02-05 15:57  gaomatlab  阅读(647)  评论(0编辑  收藏  举报

导航