Authored by jack.xue

add valid

@@ -143,6 +143,7 @@ @@ -143,6 +143,7 @@
143 <label class="control-label" style="float: left;">名称</label> 143 <label class="control-label" style="float: left;">名称</label>
144 <div class="controls"> 144 <div class="controls">
145 <input type="text" id="moName"/> 145 <input type="text" id="moName"/>
  146 +
146 </div> 147 </div>
147 </div> 148 </div>
148 <div class="control-group"> 149 <div class="control-group">
@@ -154,7 +155,7 @@ @@ -154,7 +155,7 @@
154 <div class="control-group"> 155 <div class="control-group">
155 <label class="control-label" style="float: left;">类型</label> 156 <label class="control-label" style="float: left;">类型</label>
156 <div class="controls"> 157 <div class="controls">
157 - <input type="text" readonly="readonly" id="moTypeName"/> 158 + <input type="text" readonly="readonly" id="moTypeName"/>
158 </div> 159 </div>
159 </div> 160 </div>
160 <div class="control-group"> 161 <div class="control-group">
@@ -201,10 +202,10 @@ @@ -201,10 +202,10 @@
201 <form action="#" method="post" class="form-horizontal" id="deleteForm"> 202 <form action="#" method="post" class="form-horizontal" id="deleteForm">
202 <div class="control-group" typeof="hidden" id="moId"> 203 <div class="control-group" typeof="hidden" id="moId">
203 </div> 204 </div>
204 - </form>  
205 - </div> 205 + </form>
206 </div> 206 </div>
207 </div> 207 </div>
  208 + </div>
208 <button type="button" class="btn btn-default" style="margin-right: auto" data-dismiss="modal">取消 209 <button type="button" class="btn btn-default" style="margin-right: auto" data-dismiss="modal">取消
209 </button> 210 </button>
210 211
@@ -249,9 +250,9 @@ @@ -249,9 +250,9 @@
249 250
250 //修改 251 //修改
251 var editBtn = $("<button data-target='#updateModal' data-toggle='modal'>").addClass("btn btn-primary btn-mini").html("修改").appendTo(div); 252 var editBtn = $("<button data-target='#updateModal' data-toggle='modal'>").addClass("btn btn-primary btn-mini").html("修改").appendTo(div);
252 - editBtn.click( function () {  
253 - updateMObject(rowData);  
254 - }); 253 + editBtn.click(function () {
  254 + updateMObject(rowData);
  255 + });
255 256
256 div.append("&nbsp;"); 257 div.append("&nbsp;");
257 div.append("&nbsp;"); 258 div.append("&nbsp;");
@@ -259,11 +260,10 @@ @@ -259,11 +260,10 @@
259 260
260 //删除 261 //删除
261 var delBtn = $("<button data-target='#deleteModal' data-toggle='modal'>").addClass("btn btn-danger btn-mini").html("删除").appendTo(div); 262 var delBtn = $("<button data-target='#deleteModal' data-toggle='modal'>").addClass("btn btn-danger btn-mini").html("删除").appendTo(div);
262 - delBtn.click( function() {  
263 - deleteMObject(rowData);  
264 - }  
265 -  
266 - ); 263 + delBtn.click(function () {
  264 + deleteMObject(rowData);
  265 + }
  266 + );
267 return div; 267 return div;
268 } 268 }
269 }], 269 }],
@@ -350,32 +350,71 @@ @@ -350,32 +350,71 @@
350 $("#updateModal #moId").val(rowData.moId); 350 $("#updateModal #moId").val(rowData.moId);
351 351
352 $("#updateModal #moTypeId").val(rowData.moTypeId); 352 $("#updateModal #moTypeId").val(rowData.moTypeId);
353 - 353 +
354 } 354 }
355 - 355 +
356 $("#updateModal #updateSubmit").click(function () { 356 $("#updateModal #updateSubmit").click(function () {
  357 +
  358 + if(!validEmpty($("#updateModal #moName").val()))
  359 + {
  360 + alert("必须填写监控对象名称!");
  361 + return;
  362 + }
  363 + if (!validIp($("#updateModal #moHostIp").val())) {
  364 + alert("Ip 填写错误!");
  365 + return;
  366 + }
  367 +
357 $.ajax({ 368 $.ajax({
358 - url:contextPath + "/mobject/update",  
359 - type:"post",  
360 - dataType:"json",  
361 - data:{ 369 + url: contextPath + "/mobject/update",
  370 + type: "post",
  371 + dataType: "json",
  372 + data: {
362 moId: $("#updateModal #moId").val(), 373 moId: $("#updateModal #moId").val(),
363 moName: $("#updateModal #moName").val(), 374 moName: $("#updateModal #moName").val(),
364 moHostIp: $("#updateModal #moHostIp").val(), 375 moHostIp: $("#updateModal #moHostIp").val(),
365 moTypeId: $("#updateModal #moTypeId").val(), 376 moTypeId: $("#updateModal #moTypeId").val(),
366 - moTypeName:$("#updateModal #moTypeName").val(),  
367 - moTags:$("#updateModal #moTags").val(),  
368 - moUrl:$("#updateModal #moUrl").val()  
369 - } 377 + moTypeName: $("#updateModal #moTypeName").val(),
  378 + moTags: $("#updateModal #moTags").val(),
  379 + moUrl: $("#updateModal #moUrl").val()
  380 + },
  381 + success: function () {
  382 + var div = document.getElementById("updateModal");
  383 + div.style.display = "none";
  384 +
  385 + },
  386 + error: function () {
  387 +
  388 + }
370 }); 389 });
371 }); 390 });
372 391
  392 + function validIp(ip) {
  393 + var iPattern = /^([0-9]|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.([0-9]|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.([0-9]|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.([0-9]|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])$/;
  394 + if ("" != ip && iPattern.test(ip)) {
  395 + return true;
  396 + }
  397 + else {
  398 + return false;
  399 + }
  400 + }
  401 +
  402 + function validEmpty(str) {
  403 + if ("" != str) {
  404 + return true;
  405 + }
  406 + else {
  407 + return false;
  408 + }
  409 +
  410 + }
  411 +
373 $("#deleteModal #deleteSubmit").click(function () { 412 $("#deleteModal #deleteSubmit").click(function () {
374 $.ajax({ 413 $.ajax({
375 - url:contextPath+"/mobject/delete",  
376 - type:"post",  
377 - dataType:"json",  
378 - data:{ 414 + url: contextPath + "/mobject/delete",
  415 + type: "post",
  416 + dataType: "json",
  417 + data: {
379 moId: $("#deleteModal #moId").val() 418 moId: $("#deleteModal #moId").val()
380 } 419 }
381 }); 420 });