mobjectInfo.jsp
21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
<%@page language="java" contentType="text/html;charset=utf-8" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<div id="breadcrumb">
<a href="#" title="Go to Home" class="tip-bottom"><i
class="icon-home"></i> Home</a> <a href="#" class="current">Tables</a>
</div>
<div class="container-fluid">
<div class="widget-box">
<div class="widget-title">
<h5>Dynamic table</h5>
</div>
<!-- 树 -->
<div style="margin-top: 45px; float: left;margin-top: 54px;border: dashed;width: 300px;color: #D3D3D3;height: 580px;">
<div class="widget-title">
<h5>Tree Title</h5>
</div>
<div id="jstree" class="jstree jstree-default" role="tree" aria-multiselectable="true"
tabindex="0" style="height: 400px;color: black"></div>
</div>
<!-- 列表 -->
<div class="widget-content nopadding" style="margin-left: 300px;">
<div class="widget-title" style="height: 53px;">
<div>
<div class="form-inline" role="form" id="inBoxQueryDiv"
style=" margin-top: 12px;margin-left: 25px;float: left;">
<div class="input-group" style="float: left;">
<span class="input-group-addon">IP:</span>
<input type="text" id="" class="form-control" placeholder=""/>
</div>
<div class="input-group" style="float: left;">
<span class="input-group-addon">IP:</span>
<input type="text" id="" class="form-control" placeholder=""/>
</div>
<button id="submit" class="btn btn-default">搜索</button>
</div>
</div>
</div>
<div id="table"></div>
</div>
</div>
</div>
<div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true">×</button>
<h4 class="modal-title" id="addModalLabel">新增</h4>
</div>
<div class="modal-body">
<div class="row-fluid">
<div class="span12">
<div class="widget-content nopadding">
<form action="#" method="post" class="form-horizontal" id="addForm">
<div class="control-group" typeof="hidden" id="moId">
</div>
<div class="control-group" typeof="hidden" id="moTypeId">
</div>
<div class="control-group">
<label class="control-label" style="float: left;">名称</label>
<div class="controls">
<input type="text" id="moName"/>
</div>
</div>
<div class="control-group">
<label class="control-label" style="float: left;">所属主机</label>
<div class="controls">
<input type="text" placeholder="请填写主机IP" id="moHostIp"/>
</div>
</div>
<div class="control-group">
<label class="control-label" style="float: left;">类型</label>
<div class="controls">
<input type="text" readonly="readonly" id="moTypeName"/>
</div>
</div>
<div class="control-group">
<label class="control-label" style="float: left;">标签</label>
<div class="controls">
<input type="text" id="moTags"/>
</div>
</div>
<div class="control-group">
<label class="control-label" style="float: left;">域名</label>
<div class="controls">
<input type="text" id="moUrl"/>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">关闭
</button>
<button type="submit" class="btn btn-primary" id="addSubmit">提交</button>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal -->
</div>
</div>
<div class="modal fade" id="updateModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">修改</h4>
</div>
<div class="modal-body">
<div class="row-fluid">
<div class="span12">
<div class="widget-content nopadding">
<form action="#" method="post" class="form-horizontal" id="updateForm">
<div class="control-group" typeof="hidden" id="moId">
</div>
<div class="control-group" typeof="hidden" id="moTypeId">
</div>
<div class="control-group">
<label class="control-label" style="float: left;">名称</label>
<div class="controls">
<input type="text" id="moName"/>
</div>
</div>
<div class="control-group">
<label class="control-label" style="float: left;">所属主机</label>
<div class="controls">
<input type="text" placeholder="请填写主机IP" id="moHostIp"/>
</div>
</div>
<div class="control-group">
<label class="control-label" style="float: left;">类型</label>
<div class="controls">
<input type="text" readonly="readonly" id="moTypeName"/>
</div>
</div>
<div class="control-group">
<label class="control-label" style="float: left;">标签</label>
<div class="controls">
<input type="text" id="moTags"/>
</div>
</div>
<div class="control-group">
<label class="control-label" style="float: left;">域名</label>
<div class="controls">
<input type="text" id="moUrl"/>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">关闭
</button>
<button type="submit" class="btn btn-primary" value="Validate" id="updateSubmit">提交</button>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal -->
</div>
</div>
<div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">确定删除?</h4>
</div>
<div class="modal-body">
<div class="row-fluid">
<div class="span12">
<div class="widget-content nopadding">
<form action="#" method="post" class="form-horizontal" id="deleteForm">
<div class="control-group" typeof="hidden" id="moId">
</div>
</form>
</div>
</div>
</div>
<button type="button" class="btn btn-default" style="margin-right: auto" data-dismiss="modal">取消
</button>
<button type="submit" class="btn btn-primary" style="margin-left: auto" id="deleteSubmit">确认</button>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal -->
</div>
</div>
<script>
$(function () {
$("#table").table({
url: contextPath + "/mobject/query",
striped: true,
panelClass: "panel-success",
pagination: true,
pageSize: 10,
loadFilter: function (data) {
return defaultLoadFilter(data);
},
columns: [{
title: "名称",
field: "moName"
}, {
title: "所属主机",
field: "moHostIp"
}, {
title: "类型",
field: "moTypeName"
}, {
title: "状态",
field: "moStatus"
}, {
title: "标签",
field: "moTags"
}, {
title: "操作",
formatter: function (value, rowData, rowIndex) {
var div = $("<div>");
//修改
var editBtn = $("<button data-target='#updateModal' data-toggle='modal'>").addClass("btn btn-primary btn-mini").html("修改").appendTo(div);
editBtn.click(function () {
updateMObject(rowData);
});
div.append(" ");
div.append(" ");
div.append(" ");
//删除
var delBtn = $("<button data-target='#deleteModal' data-toggle='modal'>").addClass("btn btn-danger btn-mini").html("删除").appendTo(div);
delBtn.click(function () {
deleteMObject(rowData);
}
);
return div;
}
}],
/* data: data*/
});
});
//模拟数据
var jsonData = [
{"id": "1", "name": "父节点1", "url": "www.baidu.com", "pid": "0"},
{"id": "4", "name": "父节点11", "url": "", "pid": "1"},
{"id": "14", "name": "父节点112", "url": "", "pid": "4"},
{"id": "5", "name": "父节点12", "url": "", "pid": "1"},
{"id": "6", "name": "父节点13", "url": "", "pid": "1"},
{"id": "2", "name": "父节点4", "url": "", "pid": "0"},
{"id": "7", "name": "父节点41", "url": "", "pid": "2"},
{"id": "8", "name": "父节点42", "url": "", "pid": "2"},
{"id": "9", "name": "父节点43", "url": "", "pid": "2"},
{"id": "3", "name": "父节点5", "url": "", "pid": "0"},
{"id": "10", "name": "父节点51", "url": "", "pid": "3"},
{"id": "13", "name": "父节点111", "url": "", "pid": "4"},
{"id": "11", "name": "父节点52", "url": "", "pid": "3"},
{"id": "12", "name": "父节点53", "url": "", "pid": "3"}
];
//主方法,运用递归实现
function createTree(jsons, pid) {
if (jsons != null) {
var ul = '<ul class="" style="width: 120px;" >';
for (var i = 0; i < jsons.length; i++) {
if (jsons[i].pid == pid) {
ul += '<input type="checkbox" name="checkBox" value=' + jsons[i].id + ' style="float: left;margin-top: 6px;width:10px;height:10px;"><li class="tree" value=' + jsons[i].id + '><a href="#">' + jsons[i].name + "</a></li>";
ul += createTree(jsons, jsons[i].id);
}
}
ul += "</ul>";
}
return ul;
}
$(function () {
var ul = createTree(jsonData, 0);
$("#continer").append(ul);
//控制菜单的隐藏显示
$("ul[class] li").each(function () {
$(this).click(function () {
$(this).next().toggle();
});
});
});
function deleteMObject(rowData) {
$("#deleteModal #moId").val(rowData.moId);
}
function updateMObject(rowData) {
$("#updateModal #moName").val(rowData.moName);
$("#updateModal #moHostIp").val(rowData.moHostIp);
$("#updateModal #moTypeName").val(rowData.moTypeName);
$("#updateModal #moTags").val(rowData.moTags);
$("#updateModal #moUrl").val(rowData.moUrl);
$("#updateModal #moId").val(rowData.moId);
$("#updateModal #moTypeId").val(rowData.moTypeId);
}
$("#updateModal #updateSubmit").click(function () {
if (!validEmpty($("#updateModal #moName").val())) {
alert("必须填写监控对象名称!");
return;
}
if (!validIp($("#updateModal #moHostIp").val())) {
alert("Ip 填写错误!");
return;
}
$.ajax({
url: contextPath + "/mobject/update",
type: "post",
dataType: "json",
data: {
moId: $("#updateModal #moId").val(),
moName: $("#updateModal #moName").val(),
moHostIp: $("#updateModal #moHostIp").val(),
moTypeId: $("#updateModal #moTypeId").val(),
moTypeName: $("#updateModal #moTypeName").val(),
moTags: $("#updateModal #moTags").val(),
moUrl: $("#updateModal #moUrl").val()
},
success: function (response) {
if (200 != response.status) {
alert(response.message);
}
else {
var div = document.getElementById("updateModal");
div.style.display = "none";
}
}
});
});
$("#deleteModal #deleteSubmit").click(function () {
$.ajax({
url: contextPath + "/mobject/delete",
type: "post",
dataType: "json",
data: {
moId: $("#deleteModal #moId").val()
},
success: function () {
var div = document.getElementById("deleteModal");
div.style.display = "none";
},
error: function () {
}
});
});
$("#addModal #addSubmit").click(function () {
if (!validEmpty($("#addModal #moName").val())) {
alert("必须填写监控对象名称!");
return;
}
if (!validIp($("#addModal #moHostIp").val())) {
alert("Ip 填写错误!");
return;
}
$.ajax(
{
url: contextPath + "/mobject/add",
type: "post",
dataType: "json",
data: {
moName: $("#addModal #moName").val(),
moHostIp: $("#addModal #moHostIp").val(),
moTypeId: $("#addModal #moTypeId").val(),
moTypeName: $("#addModal #moTypeName").val(),
moTags: $("#addModal #moTags").val(),
moUrl: $("#addModal #moUrl").val()
},
success: function (response) {
if (200 != response.status) {
alert(response.message);
}
else {
var div = document.getElementById("addModal");
div.style.display = "none";
}
}
}
);
}
);
function validIp(ip) {
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])$/;
if ("" != ip && iPattern.test(ip)) {
return true;
}
else {
return false;
}
}
function validEmpty(str) {
if ("" != str) {
return true;
}
else {
return false;
}
}
</script>
<script type="text/javascript" src="<%=basePath %>/script/yoho.type.tree.js"></script>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog"
aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog" style="width: 300px">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="myModalLabel">
添加类型
</h4>
</div>
<div class="modal-body">
<div id="modal_type_add">
<div class="input-group" style="padding-bottom: 5px">
<span class="input-group-addon" style="width: 100px">父节点:</span>
<input type="text" id="tx_new_type_parent" width="50" readonly="true" class="form-control"
placeholder=""/>
</div>
<div class="input-group" style="padding-bottom: 5px">
<span class="input-group-addon" style="width: 100px">Name:</span>
<input type="text" id="tx_new_type_name" width="50" class="form-control" placeholder=""/>
</div>
<div class="input-group" style="padding-bottom: 5px">
<span class="input-group-addon" style="width: 100px">子节点:</span>
<input type="checkbox" id="cb_new_type_isleaf" style="margin-left: 30px" name="appName"
value="JAVA">
</div>
</div>
<div id="modal_type_update">
<div class="input-group" style="padding-bottom: 5px">
<span class="input-group-addon" style="width: 100px">原名称:</span>
<input type="text" id="tx_update_type_name_old" readonly="true" class="form-control"
placeholder=""/>
</div>
<div class="input-group" style="padding-bottom: 5px">
<span class="input-group-addon" style="width: 100px">新名称:</span>
<input type="text" id="tx_update_type_name_new" class="form-control" placeholder=""/>
</div>
</div>
<div id="modal_type_del">
确认删除该类型节点?
</div>
</div>
<div class="modal-footer">
<input type="hidden" id="tx_type_action"/>
<input type="hidden" id="tx_type_id"/>
<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
<button type="button" id="btn4type" class="btn btn-primary">确认</button>
</div>
</div>
</div>
</div>