summaryrefslogtreecommitdiffstats
path: root/warehouse/src/main/webapp/WEB-INF/pages/app/type.jsp
blob: b06ea2ebd81e15fa3a308bf7b2a5e465017287c0 (plain)
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
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path;
	String ippath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort();
%>
<style type="text/css">
.vBtn {
	font-size: 30px;
	margin-top: -40px;
	float: right;
	text-align: center;
	background: none;
	border: none;
	color: gray;
}

.div3D {
	box-shadow: 0px 0px 4px #000;
	background: #FFFFFF;
	border-radius: 5px;
}

.hr {
	height: 1px;
	border: none;
	border-top: 1px solid #E0E0E0;
}

.cr-link-row {
	cr-link-row-icon-width: 40px;
	border-top: var(- -settings-separator-line);
}
</style>

<div class="alert alert-secondary container" role="alert">
	<div style="display: inline-block">Setting</div>
</div>
<c:choose>
	<c:when test="${not empty modelErrors}">
		<div class="alert alert-danger" id="modalErrorArea" role="alert">${modelErrors}</div>
	</c:when>
	<c:otherwise>
		<input type="hidden" id="appTypeList" value="${appTypeList}">
		<div id="page-content" class="index-page container">
			<div style="margin-left: 100px;">
				<div class="col-md-4" style="margin-left: -50px; font-size: 25px;">
					<p>Application Type</p>
					<button id="downShwoBtn"  class="vBtn fa fa-chevron-circle-up" type="button" onclick="typeBtn()"></button>
					<button id="downCloseBtn"  style="display: none" class="vBtn fa fa-chevron-circle-down" type="button" onclick="typeBtn()"></button>
				</div>
				<br>
				<ul>
					<div id="type" class="col-md-9 div3D">
						<hr style="height: 1px; border: none; border-top: 1px solid #FFFFFF;" />
						<c:forEach var="list" items="${appTypeList}">
							<option value="${list.value}">${list.label}</option>
							<div style="float: right; margin-top: -27px;">
								<button type="button" style="color: #1a73e8; background: #FFFFFF; border: solid 1px #D0D0D0; border-radius: 5px;"
									data-toggle="modal" data-target="#popTypeModal" onclick="setValues('0100', '${list.value}', '${list.label}')">Modify</button>
							</div>
							<hr class="hr" />
						</c:forEach>
						<button type="button" class="btn btn-info" data-toggle="modal"
							data-target="#popTypeModal" onclick="setValues('0100', '', '')">Add Type</button>
						<br>
						<br>
					</div>
				</ul>
			</div>
			<br>
			<br>
			<div style="margin-left: 100px;">
				<div class="col-md-5" style="margin-left: -50px; font-size: 25px;">
					<p>Application Device Type</p>
					<button id="downDeviceCloseBtn" style="display: none" class="vBtn fa fa-chevron-circle-down" type="button" onclick="deviceTypeBtn()"></button>
					<button id="downDeviceShwoBtn" class="vBtn fa fa-chevron-circle-up" type="button" onclick="deviceTypeBtn()"></button>
				</div>
				<br>
				<ul>
					<div id="deviceType" class="col-md-9 div3D">
						<hr style="height: 1px; border: none; border-top: 1px solid #FFFFFF;" />
						<c:forEach var="list" items="${appDeviceTypeList}">
							<option value="${list.value}">${list.label}</option>
							<div style="float: right; margin-top: -27px;">
								<button type="button"
									style="color: #1a73e8; background: #FFFFFF; border: solid 1px #D0D0D0; border-radius: 5px;"
									data-toggle="modal" data-target="#popTypeModal"
									onclick="setValues('0101', '${list.value}', '${list.label}')">Modify</button>
							</div>
						<hr class="hr">
						</c:forEach>
						<button type="button" class="btn btn-info" data-toggle="modal" data-target="#popTypeModal" onclick="setValues('0101', '', '')">
						Add Device Type</button>
						<br>
						<br>
					</div>
				</ul>
			</div>
			<%-- <br><a href="" onclick="Commons.showContent('<%=basePath%>/app/')" style="margin-left: 780px;">
				<button type="button" class="btn btn-primary">Back</button>
			</a><br> --%>
			<br>
		</div>
		<!-- show window -->
		<!-- modal -->
		<div class="modal fade" id="popTypeModal" 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="typeModalTitle">AddType</h4>
					</div>
					<div class="modal-body">
						<div class="alert alert-danger" style="display:none" id="typeModalErrorArea" role="alert"></div>
						<label id="typeModalDescribe">Please input the type name you want to add.</label> 
						<input type="hidden" id="m_type" name="m_type" value=""></input>
					    <input type="hidden" id="m_value" name="m_value" value=""></input> 
					    <input type="hidden" id="m_label" name="m_label" value=""></input>
						<div class="form-group fond-size">
							<!-- <label id="typeLabel">Type</label> -->
							<input class="form-control login-input style-input" id="typeName" name="s_typeLabel" type="text">
						</div>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-default" style="width: 100px;" data-dismiss="modal">Close</button>
						<button type="button" id="submitBtn" class="btn btn-primary" style="width: 100px;" onclick="submitType()">Submit</button>
					</div>
				</div>
			</div>
		</div>
	</c:otherwise>
</c:choose>

<script src="<%=basePath%>/js/constant.js"></script>
<script>
$(function() {
	$("#submitBtn").attr('disabled',true);
	$("#popTypeModal").on("hide.bs.modal", function() {
	    $(this).removeData("bs.modal");
	    var div = document.getElementById("typeModalErrorArea");
	    div.innerHTML = "";
        div.style.display="none";
	});
	/* $("#type").parent().parent().find("ul").toggle();
	$("#deviceType").parent().parent().find("ul").toggle(); */
	
	$('#typeName').bind('input propertychange', function() {
		$("#submitBtn").attr('disabled',false);
    });
	$('#typeName').bind('input propertychange', function() {
		$("#submitBtn").attr('disabled',false);
    });
}); 

/* A function to show a modal window and set the detail style of this modal window. 
   type:0100(type),0101(deviceType)
   typeValue: label name, null(add), value exists(modify) 
   typeLabel: label name */
function setValues(type, typeValue, typeLabel){
	document.getElementById("m_type").value = type;
	document.getElementById("m_value").value = typeValue;
	document.getElementById("m_label").value = typeLabel;
	
	var m_type = document.getElementById("m_type").value;
	var m_typeValue = document.getElementById("m_value").value;
	var m_typeLabel = document.getElementById("m_label").value;
	
	var typeModalTitle = document.getElementById("typeModalTitle");
	var typeModalDescribe = document.getElementById("typeModalDescribe");
	var typeLabel = document.getElementById("typeLabel");
	var typeName = document.getElementById("typeName");
	
	//type
	if('0100' == m_type){
		//type-modify
		//typeLabel.innerHTML = "Type";
		if("" != m_typeValue){
			typeModalTitle.innerHTML = "Modify Type";
			typeModalDescribe.innerHTML = "Please input the type you want to modify.";
			typeName.value = m_typeLabel;
		}
		//type-add
		else if("" == m_typeValue) { 
			typeModalTitle.innerHTML = "Add Type";
			typeModalDescribe.innerHTML = "Please input the type you want to add.";
			typeName.value = "";
		}
	}
	//device type
	else if('0101' == m_type){ 
		//device type-modify
		//typeLabel.innerHTML = "DeviceType";
		if("" != m_typeValue){ 
			typeModalTitle.innerHTML = "Modify Device Type";
			typeModalDescribe.innerHTML = "Please input the device type you want to modify.";
			typeName.value = m_typeLabel;
		}
		//device type-add
		else if("" == m_typeValue) { 
			typeModalTitle.innerHTML = "Add Device Type";
			typeModalDescribe.innerHTML = "Please input the device type you want to add.";
			typeName.value = "";
		}
	}
}

function submitType(){
	var type = document.getElementById("m_type").value;
	var typeValue = document.getElementById("m_value").value;
	var typeLabel = document.getElementById("typeName").value;
	var div = document.getElementById("typeModalErrorArea");
	
	if("" == typeLabel || null == typeLabel)
	{
		var errorContent = '';
		errorContent = "Type name is required.";
		div.innerHTML = errorContent;
        div.style.display="block";
        return;
	}
	try {
		$.ajax({
			url: '<%=basePath%>/app/saveType',
			type: 'POST',
			data: { "type":type, "typeValue":typeValue, "typeLabel":typeLabel},
			success: function (data) {
				var json = JSON.parse(data);
				if(200 == json.result) {
 					$('#popTypeModal').modal('hide');
					$('.modal-backdrop').remove();
					$('body').removeClass('modal-open'); 
					Commons.showContent('<%=basePath%>/app/type');
				} else if(401 == json.result) {
					$("#submitBtn").attr('disabled',true);	
					var errorContent = '';
					for (var i in json.message) {
						errorContent += json.message[i];
					}
					div.innerHTML = errorContent;
			        div.style.display="block";
				} else {
					$("#submitBtn").attr('disabled',true);	
					var errorContent = '';
					for (var i in json.message) {
						errorContent += '<div>' + json.message[i] + '</div>';
					}
					div.innerHTML = errorContent;
			        div.style.display="block";
				}
			},
			 error: function (jqXHR, textStatus, errorThrown) {
		            /*错误信息处理*/
		    }
		});
	} catch(e) {
		console.log(e);
	}
}

var typeNum = 0;
function typeBtn(){
	$("#type").parent().parent().find("ul").slideToggle();
	typeNum++;
	if(typeNum%2 == 1){
		$("#downShwoBtn").css("display","none");
		$("#downCloseBtn").css("display","block");
	}else{
		$("#downShwoBtn").css("display","block");
		$("#downCloseBtn").css("display","none");
	}
}

var deviceTypeNum = 0;
function deviceTypeBtn(){
	$("#deviceType").parent().parent().find("ul").slideToggle();
	deviceTypeNum++;
	if(deviceTypeNum%2 == 1){
		$("#downDeviceShwoBtn").css("display","none");
		$("#downDeviceCloseBtn").css("display","block");
	}else{
		$("#downDeviceShwoBtn").css("display","block");
		$("#downDeviceCloseBtn").css("display","none");
	}
}
</script>