editHostInfo.jsp
7.47 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
<%@page language="java" contentType="text/html;charset=utf-8" %>
<form method="post" class="form-horizontal" id="hostInfoForm" name="hostInfoForm">
<div class="form-group" >
<label class="col-sm-2 control-label"> <span style="color:red">*</span>主机IP:</label>
<div class="col-sm-8">
<input type="text" class="form-control" id="hostIp" name="hostIp" placeholder="输入IP地址" maxlength="30" size="40" onblur="autoHostName();"/>
</div>
</div>
<div class="form-group" >
<label class="col-sm-2 control-label"> <span style="color:red">*</span>云类型:</label>
<div class="col-sm-8">
<select id="cloudType" name="cloudType" class="form-control" onchange="autoHostName();">
<option value="1">AWS</option>
<option value="2">Qcloud</option>
<option value="3">其他</option>
</select>
</div>
</div>
<div class="form-group" >
<label class="col-sm-2 control-label">标签:</label>
<div class="col-sm-8" id="appNameContent">
</div>
</div>
<div class="form-group" >
<label class="col-sm-2 control-label"> <span style="color:red">*</span>主机别名:</label>
<div class="col-sm-8">
<input type="text" class="form-control" id="alias" name="alias" placeholder="输入主机别名" maxlength="30" size="40" />
</div>
</div>
<div class="form-group" >
<label class="col-sm-2 control-label"></label>
<div class="col-sm-8" id="messageAlert"></div>
</div>
</form>
<script>
var tagTypes = eval(${tagTypeMapJson});
function autoHostName(){
var hostIp=$("#hostInfoForm #hostIp").val();
var cloudType=$('#hostInfoForm #cloudType option:selected').text();
var tags="";
$("input[name='appName']:checked").each(function(){
if(tags.indexOf($(this).attr('value')+'-')<0){
tags += $(this).attr('value')+'-';
}
});
$("#hostInfoForm #alias").val(cloudType+"-"+tags+hostIp);
}
function endWithChars(str,endStr){
var d=str.length-endStr.length;
return (d>=0&&str.lastIndexOf(endStr)==d)
}
$(function () {
/*$.ajax({
url : contextPath +"/hostGroup/getAllTagsGroupByType",
type : 'post',
async : false,
dataType : "json",
success : function(data) {
var contentHtml='';
contentHtml += "<table border=1>";
for (var key in tagTypes) {
contentHtml += "<tr>";
contentHtml += "<td width='60'>";
contentHtml += tagTypes[key] ;
contentHtml += "</td>";
contentHtml += "<td>";
$.each(data.data[key],function(n,value) {
if(n>0&&n%6==0){
contentHtml+='</br>';
}
contentHtml+='<input type="checkbox" name="appName" onchange="autoHostName();" value="'+value.groupName+'">' +value.groupName+' ';
});
contentHtml += "</td>";
contentHtml += "</tr>";
}
contentHtml += "</table>";
$("#hostInfoForm #appNameContent").html(contentHtml);
}
});*/
$.ajax({
url : contextPath +"/hostGroup/getAllTagsGroupTreegridByType",
type : 'post',
async : false,
dataType : "json",
success : function(data) {
var contentHtml='';
contentHtml += "<table border=1>";
for (var key in tagTypes) {
contentHtml += "<tr>";
contentHtml += "<td width='60'>";
contentHtml += tagTypes[key] ;
contentHtml += "</td>";
contentHtml += "<td>";
if(key=="app"||key=="mid"){
contentHtml += constructTr(data.data[key],1);
}else{
contentHtml += constructTr(data.data[key]);
}
contentHtml += "</td>";
contentHtml += "</tr>";
}
contentHtml += "</table>";
$("#hostInfoForm #appNameContent").html(contentHtml);
}
});
function constructTrLevel2(treeData,levelnum){
var contentHtml="";
$.each(treeData,function(n,value) {
if(!endWithChars(contentHtml,"</br>")){
if((n>0&&n%6==0)){
contentHtml+='</br>';
}
}
contentHtml+='<input type="checkbox" name="appName" onchange="autoHostName();" value="'+value.groupName+'">' +value.groupName+' ';
if(value.children!=null&&value.children.length>0){
levelnum++;
if(!endWithChars(contentHtml,"</br>")){
contentHtml+='</br>';
}
if(levelnum<=3){
if(levelnum==2){
contentHtml+=' ';
}else {
contentHtml+=' ';
contentHtml+=' ';
}
}
// }
contentHtml += constructTrLevel2(value.children,levelnum);
levelnum--;
if(!endWithChars(contentHtml,"</br>")){
contentHtml+='</br>';
}
}
});
return contentHtml;
}
function constructTr(treeData){
var contentHtml="";
$.each(treeData,function(n,value) {
if(n>0&&n%6==0){
contentHtml+='</br>';
}
contentHtml+='<input type="checkbox" name="appName" onchange="autoHostName();" value="'+value.groupName+'">' +value.groupName+' ';
if(value.children!=null&&value.children.length>0){
contentHtml += constructTr(value.children);
}
});
return contentHtml;
}
//加载form
$("#hostInfoForm").form({
loadUrl : "getHostInfoById.do",
loadParams : {
id : paramObj.hoseInfoId
},
loadFilter : function(data) {
return defaultLoadFilter(data);
},
onBeforeLoad : function(loadParams) {
if (loadParams.hoseInfoId == 0) {
return false;
}
},
onLoadSuccess : function(data) {
$("#hostInfoForm #hostIp").prop("readonly",true);
//$(":checkbox[value='"+java+"']").prop("checked",true);
if(data.tags != null && data.tags != ""){
var tags=data.tags.substr(0,data.tags.length-1);
var tagArr=tags.split(",");
for(i=0;i<tagArr.length;i++){
$(":checkbox[value='"+tagArr[i]+"']").prop("checked",true);
}
}
}
});
});
</script>