增强配置表单校验

This commit is contained in:
chenjinsong
2018-04-03 09:37:51 +08:00
parent 268ee25299
commit beded74891
6 changed files with 444 additions and 62 deletions

View File

@@ -1,7 +1,7 @@
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/include/taglib.jsp"%>
<h3 class="form-section">增强字符串<spring:message code="block_config"/><small><span class="glyphicon glyphicon-chevron-down" data-toggle="collapse" data-target=".complexCfg" title="add"></span></small></h3>
<div class="row complexCfg collapse">
<h3 class="form-section">增强字符串<spring:message code="block_config"/><!-- <small><span class="glyphicon glyphicon-chevron-down" data-toggle="collapse" data-target=".complexCfg" title="add"></span></small> --></h3>
<div class="row complexCfg">
<div class="col-md-6">
<div class="form-group">
<label class="control-label col-md-3"><spring:message code="config_describe"/></label>
@@ -15,7 +15,6 @@
</c:when>
</c:choose>
</div>
<div for="cfgDesc"></div>
</div>
</div>
<div class="col-md-6">
@@ -42,11 +41,18 @@
</c:choose>
<input type="hidden" name="" placeholder="请输入自定义域" class="otherValue form-control" value="${_cfg.complexCfg[mainTable].district}"/>
</div>
<div for="district"></div>
<c:choose>
<c:when test="${mainTableType eq '4' and otherTable==null}">
<div for="complexCfg[${mainTable}].district"></div>
</c:when>
<c:when test="${otherTable!=null and otherTable.tableType eq '4'}">
<div for="complexCfg[${otherTable.tableName}].district"></div>
</c:when>
</c:choose>
</div>
</div>
</div>
<div class="row complexCfg collapse">
<div class="row complexCfg">
<div class="col-md-6">
<div class="form-group ">
<label class="control-label col-md-3"><font color="red">*</font><spring:message code="key_word"/></label>
@@ -60,7 +66,14 @@
</c:when>
</c:choose>
</div>
<div for="keywords"></div>
<c:choose>
<c:when test="${mainTableType eq '4' and otherTable==null}">
<div for="complexCfg[${mainTable}].keywords"></div>
</c:when>
<c:when test="${otherTable!=null and otherTable.tableType eq '4'}">
<div for="complexCfg[${otherTable.tableName}].keywords"></div>
</c:when>
</c:choose>
</div>
</div>
<div class="col-md-6">
@@ -94,11 +107,18 @@
</c:when>
</c:choose>
</div>
<div for="isAreaEffective"></div>
<c:choose>
<c:when test="${mainTableType eq '4' and otherTable==null}">
<div for="complexCfg[${mainTable}].exprType"></div>
</c:when>
<c:when test="${otherTable!=null and otherTable.tableType eq '4'}">
<div for="complexCfg[${otherTable.tableName}].exprType"></div>
</c:when>
</c:choose>
</div>
</div>
</div>
<div class="row complexCfg collapse">
<div class="row complexCfg">
<div class="col-md-6">
<div class="form-group ">
<label class="control-label col-md-3"><font color="red">*</font><spring:message code="match_method"/></label>
@@ -124,7 +144,14 @@
</c:when>
</c:choose>
</div>
<div for="matchMethod"></div>
<c:choose>
<c:when test="${mainTableType eq '4' and otherTable==null}">
<div for="complexCfg[${mainTable}].matchMethod"></div>
</c:when>
<c:when test="${otherTable!=null and otherTable.tableType eq '4'}">
<div for="complexCfg[${otherTable.tableName}].matchMethod"></div>
</c:when>
</c:choose>
</div>
</div>
<div class="col-md-6">
@@ -150,6 +177,14 @@
</c:when>
</c:choose>
</div>
<c:choose>
<c:when test="${mainTableType eq '4' and otherTable==null}">
<div for="complexCfg[${mainTable}].isHexbin"></div>
</c:when>
<c:when test="${otherTable!=null and otherTable.tableType eq '4'}">
<div for="complexCfg[${otherTable.tableName}].isHexbin"></div>
</c:when>
</c:choose>
</div>
</div>
<c:choose>

View File

@@ -1,11 +1,9 @@
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/include/taglib.jsp"%>
<style>
.ipCfg-hide{
display:none;
}
</style>
<h3 class="form-section">IP<spring:message code="block_config"/><small><span class="glyphicon glyphicon-plus" data-toggle="collapse" data-target=".ipCfg" title="add"></span></small></h3>
<h3 class="form-section">IP<spring:message code="block_config"/><small><span style="margin-left:10px"><input type="checkbox" id="ipSelect"/> 可选</span><!-- <span class="glyphicon glyphicon-plus" data-toggle="collapse" data-target=".ipCfg" title="add"></span> --></small></h3>
<div class="row ipCfg collapse">
<div class="col-md-6">
<div class="form-group">
@@ -20,7 +18,6 @@
</c:when>
</c:choose>
</div>
<div for="cfgDesc"></div>
</div>
</div>
<div class="col-md-6">
@@ -44,7 +41,14 @@
</c:when>
</c:choose>
</div>
<div for="ipType"></div>
<c:choose>
<c:when test="${mainTableType eq '1' and otherTable==null}">
<div for="ipCfg[${mainTable}].ipType"></div>
</c:when>
<c:when test="${otherTable!=null and otherTable.tableType eq '1'}">
<div for="ipCfg[${otherTable.tableName}].ipType"></div>
</c:when>
</c:choose>
</div>
</div>
</div>
@@ -62,7 +66,14 @@
</c:when>
</c:choose>
</div>
<div for="srcIp"></div>
<c:choose>
<c:when test="${mainTableType eq '1' and otherTable==null}">
<div for="ipCfg[${mainTable}].srcIp"></div>
</c:when>
<c:when test="${otherTable!=null and otherTable.tableType eq '1'}">
<div for="ipCfg[${otherTable.tableName}].srcIp"></div>
</c:when>
</c:choose>
</div>
</div>
<div class="col-md-6">
@@ -78,6 +89,14 @@
</c:when>
</c:choose>
</div>
<c:choose>
<c:when test="${mainTableType eq '1' and otherTable==null}">
<div for="ipCfg[${mainTable}].srcIpMask"></div>
</c:when>
<c:when test="${otherTable!=null and otherTable.tableType eq '1'}">
<div for="ipCfg[${otherTable.tableName}].srcIpMask"></div>
</c:when>
</c:choose>
<div for="srcIpMask"></div>
</div>
</div>
@@ -96,7 +115,14 @@
</c:when>
</c:choose>
</div>
<div for="srcPort"></div>
<c:choose>
<c:when test="${mainTableType eq '1' and otherTable==null}">
<div for="ipCfg[${mainTable}].srcPort"></div>
</c:when>
<c:when test="${otherTable!=null and otherTable.tableType eq '1'}">
<div for="ipCfg[${otherTable.tableName}].srcPort"></div>
</c:when>
</c:choose>
</div>
</div>
<div class="col-md-6">
@@ -112,7 +138,14 @@
</c:when>
</c:choose>
</div>
<div for="srcPortMask"></div>
<c:choose>
<c:when test="${mainTableType eq '1' and otherTable==null}">
<div for="ipCfg[${mainTable}].srcPortMask"></div>
</c:when>
<c:when test="${otherTable!=null and otherTable.tableType eq '1'}">
<div for="ipCfg[${otherTable.tableName}].srcPortMask"></div>
</c:when>
</c:choose>
</div>
</div>
</div>
@@ -130,7 +163,14 @@
</c:when>
</c:choose>
</div>
<div for="dstIp"></div>
<c:choose>
<c:when test="${mainTableType eq '1' and otherTable==null}">
<div for="ipCfg[${mainTable}].dstIp"></div>
</c:when>
<c:when test="${otherTable!=null and otherTable.tableType eq '1'}">
<div for="ipCfg[${otherTable.tableName}].dstIp"></div>
</c:when>
</c:choose>
</div>
</div>
<div class="col-md-6">
@@ -146,7 +186,14 @@
</c:when>
</c:choose>
</div>
<div for="dstIpMask"></div>
<c:choose>
<c:when test="${mainTableType eq '1' and otherTable==null}">
<div for="ipCfg[${mainTable}].dstIpMask"></div>
</c:when>
<c:when test="${otherTable!=null and otherTable.tableType eq '1'}">
<div for="ipCfg[${otherTable.tableName}].dstIpMask"></div>
</c:when>
</c:choose>
</div>
</div>
</div>
@@ -164,7 +211,14 @@
</c:when>
</c:choose>
</div>
<div for="dstPort"></div>
<c:choose>
<c:when test="${mainTableType eq '1' and otherTable==null}">
<div for="ipCfg[${mainTable}].dstPort"></div>
</c:when>
<c:when test="${otherTable!=null and otherTable.tableType eq '1'}">
<div for="ipCfg[${otherTable.tableName}].dstPort"></div>
</c:when>
</c:choose>
</div>
</div>
<div class="col-md-6">
@@ -180,7 +234,14 @@
</c:when>
</c:choose>
</div>
<div for="dstPortMask"></div>
<c:choose>
<c:when test="${mainTableType eq '1' and otherTable==null}">
<div for="ipCfg[${mainTable}].dstPortMask"></div>
</c:when>
<c:when test="${otherTable!=null and otherTable.tableType eq '1'}">
<div for="ipCfg[${otherTable.tableName}].dstPortMask"></div>
</c:when>
</c:choose>
</div>
</div>
</div>
@@ -207,7 +268,14 @@
</c:choose>
<%-- <input class="form-control" type="text" name="direction" value="${_cfg.ipCfg.direction}"> --%>
</div>
<div for="direction"></div>
<c:choose>
<c:when test="${mainTableType eq '1' and otherTable==null}">
<div for="ipCfg[${mainTable}].direction"></div>
</c:when>
<c:when test="${otherTable!=null and otherTable.tableType eq '1'}">
<div for="ipCfg[${otherTable.tableName}].direction"></div>
</c:when>
</c:choose>
</div>
</div>
<div class="col-md-6">
@@ -233,7 +301,14 @@
</c:when>
</c:choose>
</div>
<div for="protocol"></div>
<c:choose>
<c:when test="${mainTableType eq '1' and otherTable==null}">
<div for="ipCfg[${mainTable}].protocol"></div>
</c:when>
<c:when test="${otherTable!=null and otherTable.tableType eq '1'}">
<div for="ipCfg[${otherTable.tableName}].protocol"></div>
</c:when>
</c:choose>
</div>
</div>
<c:choose>

View File

@@ -1,7 +1,7 @@
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/include/taglib.jsp"%>
<h3 class="form-section">字符串<spring:message code="block_config"/><small><span class="glyphicon glyphicon-chevron-down" data-toggle="collapse" data-target=".stringCfg" title="add"></span></small></h3>
<div class="row stringCfg collapse">
<h3 class="form-section">字符串<spring:message code="block_config"/><!-- <small><span class="glyphicon glyphicon-chevron-down" data-toggle="collapse" data-target=".stringCfg" title="add"></span></small> --></h3>
<div class="row stringCfg">
<div class="col-md-6">
<div class="form-group">
<label class="control-label col-md-3"><spring:message code="config_describe"/></label>
@@ -15,7 +15,6 @@
</c:when>
</c:choose>
</div>
<div for="cfgDesc"></div>
</div>
</div>
<div class="col-md-6">
@@ -31,11 +30,18 @@
</c:when>
</c:choose>
</div>
<div for="cfgKeywords"></div>
<c:choose>
<c:when test="${mainTableType eq '2' and otherTable==null}">
<div for="stringCfg[${mainTable}].cfgKeywords"></div>
</c:when>
<c:when test="${otherTable!=null and otherTable.tableType eq '2'}">
<div for="stringCfg[${otherTable.tableName}].cfgKeywords"></div>
</c:when>
</c:choose>
</div>
</div>
</div>
<div class="row stringCfg collapse">
<div class="row stringCfg">
<div class="col-md-6">
<div class="form-group">
<label class="control-label col-md-3"><font color="red">*</font><spring:message code="expression_type"/></label>
@@ -66,9 +72,15 @@
</label>
</c:when>
</c:choose>
</div>
<div for="exprType"></div>
<c:choose>
<c:when test="${mainTableType eq '2' and otherTable==null}">
<div for="stringCfg[${mainTable}].exprType"></div>
</c:when>
<c:when test="${otherTable!=null and otherTable.tableType eq '2'}">
<div for="stringCfg[${otherTable.tableName}].exprType"></div>
</c:when>
</c:choose>
</div>
</div>
<div class="col-md-6">
@@ -96,11 +108,18 @@
</c:when>
</c:choose>
</div>
<div for="matchMethod"></div>
<c:choose>
<c:when test="${mainTableType eq '2' and otherTable==null}">
<div for="stringCfg[${mainTable}].matchMethod"></div>
</c:when>
<c:when test="${otherTable!=null and otherTable.tableType eq '2'}">
<div for="stringCfg[${otherTable.tableName}].matchMethod"></div>
</c:when>
</c:choose>
</div>
</div>
</div>
<div class="row stringCfg collapse">
<div class="row stringCfg">
<div class="col-md-6">
<div class="form-group">
<label class="control-label col-md-3"><font color="red">*</font><spring:message code="whether_hexbinary"/></label>
@@ -124,7 +143,14 @@
</c:when>
</c:choose>
</div>
<div for="isHexbin"></div>
<c:choose>
<c:when test="${mainTableType eq '2' and otherTable==null}">
<div for="stringCfg[${mainTable}].isHexbin"></div>
</c:when>
<c:when test="${otherTable!=null and otherTable.tableType eq '2'}">
<div for="stringCfg[${otherTable.tableName}].isHexbin"></div>
</c:when>
</c:choose>
</div>
</div>
<c:choose>

View File

@@ -43,7 +43,7 @@
<script src="${pageContext.request.contextPath}/static/global/plugins/jquery.blockui.min.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath}/static/global/plugins/bootstrap-switch/js/bootstrap-switch.min.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath}/static/global/plugins/jquery-validation/1.11.0/jquery.validate.min.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath}/static/global/plugins/jquery-validation/1.14.0/jquery.validate.min.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath}/static/global/plugins/jquery-validation/1.11.0/jquery.validate.method.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath}/static/global/plugins/jquery-jbox/2.3/jquery.jBox-2.3.src.js" type="text/javascript"></script>

View File

@@ -9,7 +9,7 @@ $(function(){
//$("[name^='stringCfg']").attr("disabled",true);
//$("[name^='complexCfg']").attr("disabled",true);
//$("[name^='numCfg']").attr("disabled",true);
$(".glyphicon").on("click",function(){
/* $(".glyphicon").on("click",function(){
var className=$(this).attr("data-target");
if($(this).hasClass("glyphicon-chevron-down")){
$(this).removeClass("glyphicon-chevron-down").addClass("glyphicon-chevron-up");
@@ -29,6 +29,128 @@ $(function(){
$(this).removeClass("glyphicon-remove").addClass("glyphicon-plus");
$("[name^='"+targetName+"']").attr("disabled",true);
}
}); */
$("#cfgFrom").validate({
rules: {
//基本配置校验开始
'isAreaEffective':{
required:true
},
'requestId': {
required: true
}
//基本配置校验结束
//maintable校验开始
,
'complexCfg[${mainTable}].district': {
required: true
}
,
'complexCfg[${mainTable}].keywords': {
required: true
}
,
'complexCfg[${mainTable}].exprType': {
required: true
}
,
'complexCfg[${mainTable}].matchMethod': {
required: true
}
,
'complexCfg[${mainTable}].isHexbin': {
required: true
}
,
'stringCfg[${mainTable}].cfgKeywords': {
required: true
}
,
'stringCfg[${mainTable}].exprType': {
required: true
}
,
'stringCfg[${mainTable}].matchMethod': {
required: true
}
,
'stringCfg[${mainTable}].isHexbin': {
required: true
}
//maintable校验结束
//othertable校验开始
<c:forEach items="${_cfg.otherTables}" var="otherTable">
,
'complexCfg[${otherTable.tableName}].district': {
required: true
}
,
'complexCfg[${otherTable.tableName}].keywords': {
required: true
}
,
'complexCfg[${otherTable.tableName}].exprType': {
required: true
}
,
'complexCfg[${otherTable.tableName}].matchMethod': {
required: true
}
,
'complexCfg[${otherTable.tableName}].isHexbin': {
required: true
}
,
'stringCfg[${otherTable.tableName}].cfgKeywords': {
required: true
}
,
'stringCfg[${otherTable.tableName}].exprType': {
required: true
}
,
'stringCfg[${otherTable.tableName}].matchMethod': {
required: true
}
,
'stringCfg[${otherTable.tableName}].isHexbin': {
required: true
}
</c:forEach>
//othertable校验结束
},
messages: {
'isAreaEffective':{
required:'<spring:message code="required"/>'
},
'requestId': {
required:'<spring:message code="required"/>'
}
},
errorPlacement: function(error,element){
$(element).parents(".form-group").find("div[for='"+element.attr("name")+"']").append(error);
},
submitHandler: function(form){
form.submit();
},
errorContainer: "#messageBox"
});
$("#ipSelect").change(function(){
if($(this).prop("checked")){
$("[name^='ipCfg']").removeProp("disabled");
//解决select插件disbale后无法恢复
$(".bootstrap-select").removeClass("disabled");
$(".bootstrap-select button").removeClass("disabled");
$(".collapse").addClass("in");
myValidate(true);//开启ip校验
}else{
myValidate(false);//关闭ip校验
$(".collapse").removeClass("in");
$("[name^='ipCfg']").attr("disabled",true);
}
});
$(".district").on("change",function(){
var val=$(this).val().toLowerCase();
@@ -105,33 +227,149 @@ $(function(){
$("#cancel").on("click",function(){
window.history.back();
});
$("#cfgFrom").validate({
rules: {
'isAreaEffective':{
required:true
},
'requestId': {
required: true
}
},
messages: {
'isAreaEffective':{
required:'<spring:message code="required"/>'
},
'requestId': {
required: '<spring:message code="required"/>'
}
},
errorPlacement: function(error,element){
$(element).parents(".form-group").find("div[for='"+element.attr("name")+"']").append(error);
},
submitHandler: function(form){
form.submit();
},
errorContainer: "#messageBox"
});
myValidate();
});
function myValidate(flag) {
if (flag) {
myValidate(false);
$("#cfgFrom").validate();
$("[name=ipCfg\\[http_ip_cfg\\]\\.ipType]").each(function(){
$(this).rules("add", {
required: true,
messages: {
required:'<spring:message code="required"/>'
}
});
});
$("[name=ipCfg\\[http_ip_cfg\\]\\.srcIp]").each(function(){
$(this).rules("add", {
required: true,
messages: {
required:'<spring:message code="required"/>'
}
});
});
$("[name=ipCfg\\[http_ip_cfg\\]\\.srcIpMask]").each(function(){
$(this).rules("add", {
required: true,
messages: {
required:'<spring:message code="required"/>'
}
});
});
$("[name=ipCfg\\[http_ip_cfg\\]\\.srcPort]").each(function(){
$(this).rules("add", {
required: true,
messages: {
required:'<spring:message code="required"/>'
}
});
});
$("[name=ipCfg\\[http_ip_cfg\\]\\.srcPortMask]").each(function(){
$(this).rules("add", {
required: true,
messages: {
required:'<spring:message code="required"/>'
}
});
});
$("[name=ipCfg\\[http_ip_cfg\\]\\.dstIp]").each(function(){
$(this).rules("add", {
required: true,
messages: {
required:'<spring:message code="required"/>'
}
});
});
$("[name=ipCfg\\[http_ip_cfg\\]\\.dstIpMask]").each(function(){
$(this).rules("add", {
required: true,
messages: {
required:'<spring:message code="required"/>'
}
});
});
$("[name=ipCfg\\[http_ip_cfg\\]\\.dstPort]").each(function(){
$(this).rules("add", {
required: true,
messages: {
required:'<spring:message code="required"/>'
}
});
});
$("[name=ipCfg\\[http_ip_cfg\\]\\.dstPortMask]").each(function(){
$(this).rules("add", {
required: true,
messages: {
required:'<spring:message code="required"/>'
}
});
});
$("[name=ipCfg\\[http_ip_cfg\\]\\.direction]").each(function(){
$(this).rules("add", {
required: true,
messages: {
required:'<spring:message code="required"/>'
}
});
});
$("[name=ipCfg\\[http_ip_cfg\\]\\.protocol]").each(function(){
$(this).rules("add", {
required: true,
messages: {
required:'<spring:message code="required"/>'
}
});
});
$("[name=ipCfg\\[http_ip_cfg\\]\\.isAreaEffective]").each(function(){
$(this).rules("add", {
required: true,
messages: {
required:'<spring:message code="required"/>'
}
});
});
} else {
$("[name=ipCfg\\[http_ip_cfg\\]\\.ipType]").each(function(){
$(this).rules("remove");
});
$("[name=ipCfg\\[http_ip_cfg\\]\\.srcIp]").each(function(){
$(this).rules("remove");
});
$("[name=ipCfg\\[http_ip_cfg\\]\\.srcIpMask]").each(function(){
$(this).rules("remove");
});
$("[name=ipCfg\\[http_ip_cfg\\]\\.srcPort]").each(function(){
$(this).rules("remove");
});
$("[name=ipCfg\\[http_ip_cfg\\]\\.srcPortMask]").each(function(){
$(this).rules("remove");
});
$("[name=ipCfg\\[http_ip_cfg\\]\\.dstIp]").each(function(){
$(this).rules("remove");
});
$("[name=ipCfg\\[http_ip_cfg\\]\\.dstIpMask]").each(function(){
$(this).rules("remove");
});
$("[name=ipCfg\\[http_ip_cfg\\]\\.dstPort]").each(function(){
$(this).rules("remove");
});
$("[name=ipCfg\\[http_ip_cfg\\]\\.dstPortMask]").each(function(){
$(this).rules("remove");
});
$("[name=ipCfg\\[http_ip_cfg\\]\\.direction]").each(function(){
$(this).rules("remove");
});
$("[name=ipCfg\\[http_ip_cfg\\]\\.protocol]").each(function(){
$(this).rules("remove");
});
$("[name=ipCfg\\[http_ip_cfg\\]\\.isAreaEffective]").each(function(){
$(this).rules("remove");
});
}
}
</script>
</head>
<body>
@@ -189,6 +427,10 @@ $(function(){
<c:when test="${otherTable.tableType eq '2'}">
<%@include file="/WEB-INF/include/form/multiple/stringInfo.jsp" %>
</c:when>
</c:choose>
</c:forEach>
<c:forEach items="${_cfg.otherTables}" var="otherTable">
<c:choose>
<c:when test="${otherTable.tableType eq '1'}">
<%@include file="/WEB-INF/include/form/multiple/ipInfo.jsp" %>
</c:when>

File diff suppressed because one or more lines are too long