diff options
| author | zhangwenqing <[email protected]> | 2019-04-19 17:44:12 +0800 |
|---|---|---|
| committer | zhangwenqing <[email protected]> | 2019-04-19 17:44:12 +0800 |
| commit | 99c3c8c84f1688f88ac11ea298e35fb1f7e0e3ff (patch) | |
| tree | b6d31f3cde3269ba1c7d40bb9afb0a75c77e9674 | |
| parent | 865811b9b219eb8dfcf2cb654bb828875dfa62ea (diff) | |
修正保护名单配置回车不提示、重复数据问题
7 files changed, 93 insertions, 20 deletions
diff --git a/src/main/java/com/nis/web/controller/basics/InnerProtectionListController.java b/src/main/java/com/nis/web/controller/basics/InnerProtectionListController.java index ae341bdf4..1b7a971ad 100644 --- a/src/main/java/com/nis/web/controller/basics/InnerProtectionListController.java +++ b/src/main/java/com/nis/web/controller/basics/InnerProtectionListController.java @@ -77,4 +77,31 @@ public class InnerProtectionListController extends BaseController{ public Map<String,List<String>> ajaxGetAllInfo(HttpServletRequest request, HttpServletResponse response){
return innerProtectionListService.ajaxGetAllInfo();
}
+
+ /**
+ * 校验配置是否已存在
+ * @param cfg
+ * @param request
+ * @param response
+ * @return
+ */
+ @ResponseBody
+ @RequestMapping(value = {"/checkKeywordExist"})
+ public boolean checkKeywordExist(ProtectionListInfo cfg, HttpServletRequest request, HttpServletResponse response){
+ if(!StringUtil.isEmpty(cfg.getProId())){ // 修改操作
+ ProtectionListInfo info = innerProtectionListService.getById(cfg.getProId());
+ if(info != null && info.getKeyword().equals(cfg.getKeyword()) && info.getTargetType().equals(cfg.getTargetType())){
+ return true;
+ }
+ }
+ Map<String, List<String>> map = innerProtectionListService.ajaxGetAllInfo();
+ List<String> list = map.get(cfg.getTargetType());
+ if(list != null) {
+ if(list.contains(cfg.getKeyword())) {
+ return false;
+ }
+ }
+
+ return true;
+ }
}
diff --git a/src/main/webapp/WEB-INF/views/basics/protectionInfoForm.jsp b/src/main/webapp/WEB-INF/views/basics/protectionInfoForm.jsp index 7daa83dfc..70ece9ec5 100644 --- a/src/main/webapp/WEB-INF/views/basics/protectionInfoForm.jsp +++ b/src/main/webapp/WEB-INF/views/basics/protectionInfoForm.jsp @@ -19,6 +19,26 @@ $(function(){ },
errorContainer: "#messageBox",
});
+
+ jQuery.validator.addMethod("protectedCfgUnique",function(value, element) {
+ var result = true;
+ var proId= $("[name='proId']").val();
+ var keyword = $("[name='keyword']").val();
+ var targetType = $("[name='targetType']").val();
+ var ctx=$(element).attr("ctx");
+ var url = ctx+"/basics/innerProtectionList/checkKeywordExist";
+ $.ajax({
+ type:'post',
+ async:false,
+ url: url,
+ data:{"proId":proId,"keyword":keyword,"targetType":targetType},
+ success:function(data){
+ result = data;
+ }
+ });
+
+ return result;
+ });
});
</script>
</head>
@@ -48,15 +68,6 @@ $(function(){ <div class="row">
<div class="col-md-6">
<div class="form-group">
- <label class="control-label col-md-3"><font color="red">*</font><spring:message code="keywords"/></label>
- <div class="col-md-6">
- <input class="form-control required" type="text" name="keyword" value="${_cfg.keyword}">
- </div>
- <div for="keyword"></div>
- </div>
- </div>
- <div class="col-md-6">
- <div class="form-group">
<label class="control-label col-md-3"><font color="red">*</font><spring:message code="type"/></label>
<div class="col-md-6">
<%-- <input class="form-control required" type="text" name="targetType" value="${_cfg.targetType}"> --%>
@@ -70,6 +81,15 @@ $(function(){ <div for="targetType"></div>
</div>
</div>
+ <div class="col-md-6">
+ <div class="form-group">
+ <label class="control-label col-md-3"><font color="red">*</font><spring:message code="keywords"/></label>
+ <div class="col-md-6">
+ <input class="form-control protectedCfgUnique required" ctx="${ctx}" type="text" name="keyword" value="${_cfg.keyword}">
+ </div>
+ <div for="keyword"></div>
+ </div>
+ </div>
</div>
<div class="row">
<div class="col-md-6">
diff --git a/src/main/webapp/WEB-INF/views/basics/protectionInfoList.jsp b/src/main/webapp/WEB-INF/views/basics/protectionInfoList.jsp index e582b2b99..8eba1aa75 100644 --- a/src/main/webapp/WEB-INF/views/basics/protectionInfoList.jsp +++ b/src/main/webapp/WEB-INF/views/basics/protectionInfoList.jsp @@ -216,8 +216,8 @@ <thead>
<tr>
<th><input type="checkbox" class="i-checks" id="checkAll"></th>
- <th column="keyword" ><spring:message code="keywords"/></th>
<th column="targetType" ><spring:message code="type"/></th>
+ <th column="keyword" ><spring:message code="keywords"/></th>
<th column="desc" ><spring:message code="desc"/></th>
<th column="creator" ><spring:message code="creator"/></th>
<th column="config_time" class="sort-column r.create_time"><spring:message code="config_time"/></th>
@@ -230,16 +230,16 @@ <tr>
<td><input type="checkbox" class="i-checks child-checks" id="${cfg.proId}"></td>
<td>
+ <c:if test="${cfg.targetType eq 'urlCheck'}"><spring:message code="URL"/></c:if>
+ <c:if test="${cfg.targetType eq 'domainCheck'}"><spring:message code="domain"/></c:if>
+ <c:if test="${cfg.targetType eq 'keywordSign'}"><spring:message code="keywords"/></c:if>
+ </td>
+ <td>
<a href="javascript:;" data-original-title="${cfg.keyword}"
class="tooltips" data-flag="false" data-html="true" data-placement="top">
${fns:abbr(cfg.keyword,20)}
</a>
</td>
- <td>
- <c:if test="${cfg.targetType eq 'urlCheck'}"><spring:message code="URL"/></c:if>
- <c:if test="${cfg.targetType eq 'domainCheck'}"><spring:message code="domain"/></c:if>
- <c:if test="${cfg.targetType eq 'keywordSign'}"><spring:message code="keywords"/></c:if>
- </td>
<td title="${cfg.description }">${fns:abbr(cfg.description,20)}</td>
<td>${cfg.creatorName }</td>
<td><fmt:formatDate value="${cfg.createTime }" pattern="yyyy-MM-dd HH:mm:ss"/></td>
diff --git a/src/main/webapp/static/global/plugins/jquery-validation/1.11.0/localization/messages_en.js b/src/main/webapp/static/global/plugins/jquery-validation/1.11.0/localization/messages_en.js index c666fec99..46e3d35f2 100644 --- a/src/main/webapp/static/global/plugins/jquery-validation/1.11.0/localization/messages_en.js +++ b/src/main/webapp/static/global/plugins/jquery-validation/1.11.0/localization/messages_en.js @@ -96,6 +96,7 @@ compileIdCheck:"Please enter the correct query format", compileIdCheckNum:"The number of queries should not be greater than 200", rangeCross0:"The IP {0} must not between {1} and {2}", - rangeCross1:"The IP range {0} has intersections with {1}" + rangeCross1:"The IP range {0} has intersections with {1}", + protectedCfgUnique:"Keyword already exists." }); }(jQuery)); diff --git a/src/main/webapp/static/global/plugins/jquery-validation/1.11.0/localization/messages_ru.js b/src/main/webapp/static/global/plugins/jquery-validation/1.11.0/localization/messages_ru.js index ba32542b1..d02cd04fc 100644 --- a/src/main/webapp/static/global/plugins/jquery-validation/1.11.0/localization/messages_ru.js +++ b/src/main/webapp/static/global/plugins/jquery-validation/1.11.0/localization/messages_ru.js @@ -96,6 +96,7 @@ compileIdCheck:"Please enter the correct query format", compileIdCheckNum:"The number of queries should not be greater than 200", rangeCross0:"The IP {0} must not between {1} and {2}", - rangeCross1:"The IP range {0} has intersections with {1}" + rangeCross1:"The IP range {0} has intersections with {1}", + protectedCfgUnique:"Keyword already exists." }); }(jQuery)); diff --git a/src/main/webapp/static/global/plugins/jquery-validation/1.11.0/localization/messages_zh.js b/src/main/webapp/static/global/plugins/jquery-validation/1.11.0/localization/messages_zh.js index 78d746925..12aa7df85 100644 --- a/src/main/webapp/static/global/plugins/jquery-validation/1.11.0/localization/messages_zh.js +++ b/src/main/webapp/static/global/plugins/jquery-validation/1.11.0/localization/messages_zh.js @@ -96,6 +96,7 @@ compileIdCheck:"请输入正确的查询格式", compileIdCheckNum:"查询个数不能大于200", rangeCross0:"IP{0}不能介于{1}和{2}", - rangeCross1:"IP范围{0}和IP范围{1}有交集" + rangeCross1:"IP范围{0}和IP范围{1}有交集", + protectedCfgUnique:"关键字已存在" }); }(jQuery)); diff --git a/src/main/webapp/static/global/scripts/common.js b/src/main/webapp/static/global/scripts/common.js index 4ce5dacdf..96e15ca3c 100644 --- a/src/main/webapp/static/global/scripts/common.js +++ b/src/main/webapp/static/global/scripts/common.js @@ -42,6 +42,7 @@ $(function(){ $("."+key).each(function(){
if(!$(this).hasClass("tags")){
this.setAttribute("onblur","protectedListWarn(this,'"+key+"')");
+ this.setAttribute("onkeypress","protectedListWarn(this,'"+key+"','keypress')");
}
protectedListWarn(this,key);
});
@@ -1556,13 +1557,20 @@ function addPrintTableCss(rowValue,cellValue,tableIdValue,cssName){ }
}
}
+
/**保护名单提醒**/
-function protectedListWarn(obj,tagKey){
+function protectedListWarn(obj,tagKey,flag){
+ // 值为空 或 非回车事件直接返回
+ if(($(obj).val() == '') || (flag != null && event.keyCode != 13)){
+ return false;
+ }
+
var pathName = window.document.location.pathname.substring(0,window.document.location.pathname.lastIndexOf("/nis")+4);
$.ajax({
type:'get',
url:pathName+'/basics/innerProtectionList/ajaxGetAllInfo',
dataType:"json",
+ async:false,
success:function(data){
if(data != null){
for(var key in data){
@@ -1570,6 +1578,7 @@ function protectedListWarn(obj,tagKey){ $("."+key).each(function(){
if(!$(this).hasClass("tags")){
this.setAttribute("onblur","protectedListWarn(this,'"+key+"')");
+ this.setAttribute("onkeypress","protectedListWarn(this,'"+key+"','keypress')");
}
});
}
@@ -1579,8 +1588,22 @@ function protectedListWarn(obj,tagKey){ var protectedList = data[tagKey];
if(value != "" && typeof(protectedList) != "undefined"){
if(protectedList.indexOf(value) >= 0){ // 关键字匹配则弹出提示框
- $.jBox.info($.validator.messages.protect_warn,$.validator.messages.info);
+ // 剪切事件属性,防止弹出多个提示框(回车事件会同时触发失去焦点事件)
+ var blurCopy = $(obj).attr("onblur");
+ var keypressCopy = $(obj).attr("onkeypress");
+ $(obj).attr("onblur","");
+ $(obj).attr("onkeypress","");
+
+ // 阻止表单提交
+ $.jBox.close();
+ $(obj).parents("form:first").find("button[type='submit']").attr("type","button");
+ $.jBox.info($.validator.messages.protect_warn,$.validator.messages.info, {closed:function(v,h,f){
+ $(obj).attr("onblur",blurCopy);
+ $(obj).attr("onkeypress",keypressCopy);
+ $(obj).parents("form:first").find("button[id='save']").attr("type","submit");
+ }});
$('.jbox-body .jbox-icon').css('top','55px');
+
}
}
|
