summaryrefslogtreecommitdiffstats
path: root/warehouse/src/main/webapp/WEB-INF/pages/app/saveAppInfo.jsp
blob: 51ca3522463349c9ae0f02a84d2d5ea269d159fe (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
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
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%
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">
 	#e_appTypeId {height:auto;}
    .box{height:50px;border-style:solid; border-width:1px; border-color:#F0F0F0;text-align:center;line-height:50px;color:white;}
	.file-btn{z-index:0;filter:alpha(opacity=1);opacity:0.8;}
	#e_position{z-index:100;}
	 .create-schedule{border:2px solid #E0E0E0;}
	 .create-scheduling{border:2px solid #29e62d;}
</style>
<!-- navigationDialog dialog -->
<jsp:include page="../navigationDialog.jsp" flush="true"></jsp:include>
<c:choose>
	<c:when test="${not empty modelErrors}">
		<div class="alert alert-danger" id="modalErrorArea" role="alert">
			&nbsp;${modelErrors}
		</div>
	</c:when>
	<c:otherwise>
		<div class="card mb-3" style="height:auto;">
		    <!-- <div style="margin-left:10px;width:98%"> -->
		    <div class="col-md-12 box">
		        <div class="form-group row">
		            <img src="image/insertAppDetails.PNG" style="height:100%;width:100%"/>
		        </div>
		        <div class="form-group row" style="margin-top:-15px;">
		            <div class="col-md-4 create-scheduling" ></div> 
		            <div class="col-md-4 create-schedule" ></div> 
		            <div class="col-md-4 create-schedule" ></div>
		        </div>
		    </div>
			<div class="card-body card-change-password pt0">
			<div class="alert alert-danger" id="modalErrorArea" role="alert"<c:choose>
				<c:when test="${not empty modelErrors}">style="display: block"</c:when>
				<c:otherwise>style="display: none"</c:otherwise>
				</c:choose>>
				<c:if test="${not empty modelErrors}">
					&nbsp;${modelErrors}
				</c:if>
			</div>
			<p style="font-size:25px;margin-top:10px;">Fill in information</p>
		      <div class="card-body">
		      	<div class="alert alert-danger;"style="display:none" id="modalErrorArea" role="alert"></div>
		        <form id="registerForm" class="was-validated"> 
		       		<input type="hidden" id="e_deviceTypeId" value="${appInfo.appDeviceTypeId}">
		       		<input type="hidden" id="e_hashcode" value="${appInfo.hashcode}">
		       		<input type="hidden" id="e_verFilePath" value="${appInfo.verFilePath}">
		       		<input type="hidden" id="e_appSize" value="${appInfo.appSize}">
		       		<input type="hidden" id="e_appVersionId" value="${appInfo.appVersionId}">
		       		<input type="hidden" id="e_imagePath" value="${appInfo.imagePath}">
		            <div class="form-group row">
			            <div class="col-md-3"><label for="e_uuId" class="notNull">UUID</label></div>
			            <div class="col-md-9">
			              <input class="form-control style-height" id="e_uuId" name="e_uuId" title="This field is required" maxlength="32" type="text" placeholder="" value="${appInfo.appId}"  required disabled>
			            </div>
		          	</div> 
		          	<c:if test="${empty appInfo.appIdCustom}">
		          	<div class="form-group row">
			            <div class="col-md-3 "><label for="e_position" class="notNull">App File</label></div>
			             <div class="col-md-2 file-box" id="upload" style="display:block">
			                <input type="button" class="btn btn-success" value="UPLOAD"  style="height:50px;width:150px;padding:0px;position:absolute;top:-10px;">
			             	<input title="This field is required" id="path" name="position" type="file"  style="height:50px;width:150px;padding:0px;position:absolute;top:-10px;opacity:0;" class="form-control file-btn" value="${appInfo.verFilePath}" accept=".wgt" onchange="change(event)" required>
			            </div>	
			                 
			            <div class="col-md-2 file-box" id="uploading" style="display:none">
			                <input type="button" class="btn btn-success" value="UPLOADING......"  style="height:50px;width:150px;padding:0px;position:absolute;top:-10px;background:#ADADAD">
			             	<input title="This field is required" id="path" name="position" type="file"  style="height:50px;width:150px;padding:0px;position:absolute;top:-10px;opacity:0;" class="form-control file-btn" value="${appInfo.verFilePath}" accept=".wgt" onchange="change(event)" required>
			            </div>	      
		          	</div>
		          	</c:if>
		          	 <div class="form-group row">
			            <div class="col-md-3"><label for="e_appId" class="notNull">App Id</label></div>
			            <div class="col-md-9">
			              <input class="form-control style-height" id="e_appId" name="e_appId" title="This field is required"  type="text"  value="${appInfo.appIdCustom}"  required disabled>
			            </div>
		          	</div> 
		          	<div class="form-group row">
			            <div class="col-md-3"><label for="e_versionName" class="notNull">Version</label></div>
			            <div class="col-md-9">
			              <input class="form-control style-height" id="e_versionName" title="This field is required" name="e_versionName"  type="text"  value="${appInfo.versionName}"  required disabled>
			            </div>
		          	</div> 
		          	<div class="form-group row">
			            <div class="col-md-3"><label for="e_appName" class="notNull">App Name</label></div>
			            <div class="col-md-9">
			              <input class="form-control style-height" id="e_appName" name="e_appName" title="This field is required" type="text" placeholder="" value="${appInfo.appName}"  required disabled>
			            </div>
		          	</div> 
		          	<div class="form-group row">
			            <div class="col-md-3"><label for="e_isPublicName" class="notNull">App Is Public</label></div>
			            <div class="col-md-9">
			                <select id="e_isPublicName" class="form-control" required>
			                    <c:forEach var="list" items="${appIsPublicList}">
	                                <option value="${list.value}" <c:if test="${list.value eq appInfo.appIsPublic}">selected="selected"</c:if>>${list.label}</option>
	                            </c:forEach>
	                        </select>
			            </div>
		          	</div> 
		           	<div class="form-group row" >
			            <div class="col-md-3 "><label for="e_appTypeId" class="notNull">App Type</label></div>
			            <div class="col-md-9">
			              <select id="e_appTypeId" class="form-control" required>
	                        <c:forEach var="list" items="${appTypeList}">
	                           <option value="${list.value}" <c:if test="${list.value eq appInfo.typeId}">selected="selected"</c:if>>${list.label}</option>
	                        </c:forEach>
	                      </select>
			            </div>
		          	</div>
		          	<div class="form-group row">
	                    <div class="col-md-3" style="margin-top:65px;"><label for="e_appAbstract" class="notNull">App Description</label></div>
		                    <div class="col-md-9">
		                	<textarea class="form-control" title="This field is required" maxlength="800" placeholder="Maximum length is 800 characters." id="e_appAbstract" name="e_appAbstract" style="height:150px;" rows="8" cols="40" required>${appInfo.appAbstract}</textarea>
	                	</div>
                	</div>
                	 <div class="form-group row">
			            <div class="col-md-3"><label style="margin-top:35px;" for="e_thumbnail" class="notNull">App Icon</label></div>
			            <div class="col-md-9">
			                <img id="e_iconPath" src="${appInfo.imagePath}" style="width: 150px; height:150px;border:#ADADAD 1px solid"/><br>
			                <input onchange="changeImg(event,'e_iconPath')"  type="file" style="width:150px;height:150px;margin-top:-150px;position: absolute; opacity:0;">
			            </div>
		          	</div>		          			          			          			          	
		        </form>
		       	<div style="float:right;" class="col-md-0">
			        <button type="button" class="btn btn-primary form-btn-w-70" id="btn-save-edit" onclick="saveAppForm()">Save</button>
		      	</div>
		      </div>
		    </div>
		</div>
	</c:otherwise>
</c:choose>

<script src="<%=basePath%>/js/constant.js"></script>
<script>
$(function(){
	Commons.bindDateControl();
	Commons.appendRedAsterisk();
	blobData=null;
	filename=null;	
	if($('#e_imagePath').val() == ''){
		$('#e_iconPath').attr("src",'<%=basePath%>/image/addPic.png');
	}
});  
var load = function(event){
	var load = document.getElementById("path");
	var index=load.value.lastIndexOf("\_");
	load.value=load.value.substring(index+1,load.value.length);
	return load.value;
}

var blobData, filename;
var change = function (event) {
	file = event.target.files[0];
	var fileReader = new FileReader();
	fileReader.readAsArrayBuffer(file);
	var toBlob = function(a){
        return new Blob([a],{type:file.type})
    }
	
	fileReader.onload = function(){
		var result = this.result;
        var blob = new Blob([result],{type:file.type});
        blobData = blob;
        filename = file.name;
        saveUpload();
    }
}

var $errorArea = $('#modalErrorArea');
var appForm = function() {
	this.developer = '';
	this.typeId = '';
	this.appName = '';
	this.verFilePath = '';
	this.versionName = '';
	this.appAbstract = '';
	this.appId = '';
	this.appVersionId = '';
	this.appIsPublic = '';
};
var saveUpload = function() {
	$("#btn-save-edit").attr('disabled',true);
	$("#upload")[0].style.display = "none";
	$("#uploading")[0].style.display = "block";
	var tf = new appForm();
	tf.appId = $('#e_uuId').val();
	tf.appDeviceTypeId = $('#e_deviceTypeId').val();
	if( filename == null){
		tf.verFilePath = load();
	}else{
		tf.verFilePath = filename;
	}
	var formData = new FormData();
	formData.append("file", blobData);
	formData.append("form", JSON.stringify(tf));

	try {
		$.ajax({
			url: '<%=basePath%>/app/uploadFile',
			cache: false,
			type: 'POST',
			async:true,
            processData:false,
            contentType:false,
			data: formData,
			success: function (data) {
				$("#btn-save-edit").attr('disabled',false);
				var json = JSON.parse(data);
				if(200 == json.result) {
					Commons.showContent('<%=basePath%>' + json.forward);
					$('#e_hashcode').attr("value",json.message.fileHashCode);
					$('#e_appId').attr("value",json.message.configAppId);
					$('#e_versionName').attr("value",json.message.configVersionName);
					$('#e_verFilePath').attr("value",json.message.filePath);
					$('#e_appName').attr("value",json.message.configAppName);
					$('#e_iconPath').attr("src",'<%=ippath%>'+json.message.iconPath);
					$('#e_imagePath').attr("value",json.message.iconPath);
					$('#e_appSize').attr("value",json.message.fileSize);
					if($('#e_imagePath').val() == ''){
						$('#e_iconPath').attr("src",'<%=basePath%>/image/addPic.png');
					}
					blobData="";
					filename="";
					$errorArea.css("display", "none");
				} else if(401 == json.result) {
					var errorContent = '';
					for (var i in json.message) {
						errorContent += '<div>' + json.message[i] + '</div>';
					}
					$errorArea.empty().append(errorContent);
					$errorArea.css("display", "block");
					$("#btn-save-edit").attr('disabled',true);
				} else if(500 == json.result) {
					var errorContent = '';
					for (var i in json.message) {
						errorContent += '<div>' + json.message[i] + '</div>';
					}
					$errorArea.empty().append(errorContent);
					$errorArea.css("display", "block");
					$("#btn-save-edit").attr('disabled',true);
				}
				$("#upload")[0].style.display = "block";
				$("#uploading")[0].style.display = "none";
			},
			 error: function (jqXHR, textStatus, errorThrown) {
		            /*错误信息处理*/
		    }
		});
	} catch(e) {
		console.log(e);
	}
};
//image
function changeImg(e,name) {
	$errorArea.empty();
	$errorArea.css("display", "none");
    for (var i = 0; i < e.target.files.length; i++) {
        var file = e.target.files.item(i);
        if (!(/^image\/.*$/i.test(file.type))) {
        	//isImage
        	$errorArea.empty().append('<div>' + 'You can upload pictures only.' + '</div>');
			$errorArea.css("display", "block");
        } else if(file.size > (500*1024)){
        	//image size
        	$errorArea.empty().append('<div>' + 'The picture sizes should not exceed 500KB.' + '</div>');
			$errorArea.css("display", "block");
        } else{ 
        	//FileReader API
            var freader = new FileReader();
            blobData = file;
            freader.readAsDataURL(file);
            freader.onload = function (e) {
            	var result = this.result;
                var blob = new Blob([result],{type:file.type});
                $("#e_iconPath").attr("src",e.target.result); 
            }         
        }
    }
}
var saveAppForm = function() {
	$("#btn-save-edit").attr('disabled',true);
	var tf = new appForm();
	tf.appId = $('#e_uuId').val();
	tf.appDeviceTypeId = $('#e_deviceTypeId').val();
	tf.versionName = $('#e_versionName').val();
	tf.typeId = $('#e_appTypeId').val();
	tf.appName = $('#e_appName').val();
	tf.appAbstract = $('#e_appAbstract').val();
	tf.appIsPublic = $('#e_isPublicName').val();
	tf.hashcode = $('#e_hashcode').val();
    tf.verFilePath = $('#e_verFilePath').val();
    tf.imagePath = $('#e_imagePath').val();
    tf.appIdCustom = $('#e_appId').val();
    tf.appSize = $('#e_appSize').val();
    tf.appVersionId = $('#e_appVersionId').val();
	var formData = new FormData();
	formData.append("file", blobData);
	formData.append("form", JSON.stringify(tf));

	try {
		$.ajax({
			url: '<%=basePath%>/app/saveInfo',
			cache: false,
			type: 'POST',
			async:true,
            processData:false,
            contentType:false,
			data: formData,
			success: function (data) {
				var json = JSON.parse(data);
				if(200 == json.result) {
					Commons.showContent('<%=basePath%>/' + json.forward+'?appId='+json.message.appId);
					blobData=null;
				} else if(401 == json.result) {
					$("#btn-save-edit").attr('disabled',false);
					var errorContent = '';
					for (var i in json.message) {
						errorContent += '<div>' + json.message[i] + '</div>';
					}
					$errorArea.empty().append(errorContent);
					$errorArea.css("display", "block");
				} else {
					$("#btn-save-edit").attr('disabled',false);
					var errorContent = '';
					for (var i in json.message) {
						errorContent += '<div>' + json.message[i] + '</div>';
					}
					$errorArea.empty().append(errorContent);
					$errorArea.css("display", "block");
				}
			},
			 error: function (jqXHR, textStatus, errorThrown) {
		            /*错误信息处理*/
		    }
		});
	} catch(e) {
		console.log(e);
	}
};
var upload = function() {
	$('#path').click();
};
</script>