-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUploadFile.html
More file actions
421 lines (371 loc) · 15.7 KB
/
Copy pathUploadFile.html
File metadata and controls
421 lines (371 loc) · 15.7 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
<html>
<head>
<title>BBDP</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/FCMPushHandler.js"></script> <!-- 提醒推播 -->
<!-- <script type="text/javascript" src="js/RemindPushHandler.js"></script> 傳送提醒推播 -->
<script type="text/javascript" charset="utf-8" src="js/pushToBBDPDoctor.js"></script> <!-- 傳送提醒推播至醫生端 -->
<link rel="stylesheet" type="text/css" href="css/frame.css">
<!------------------------------cordova相關js---------------------------------------->
<script type="text/javascript" charset="utf-8" src="js/MediaCapture.js"></script>
<script type="text/javascript" src="cordova.js"></script> <!-- Cordova套件 -->
<!------------------------------上傳js---------------------------------------->
<script type="text/javascript" charset="utf-8">
document.addEventListener("backbutton", onBackKeyDown, false); //偵測事件
function onBackKeyDown() { //返回按鈕
window.history.go(-1);
}
$(document).ready(function() {
document.addEventListener("deviceready", onDeviceReady, false); //偵測事件
function onDeviceReady() {
pictureSource=navigator.camera.PictureSourceType;
destinationType=navigator.camera.DestinationType;
}
$.ajax({
type: "GET",
url: serverURL + "GetInfoServlet",
data: {patientID: window.localStorage.getItem('login'), option: "getPatientName"},
dataType: "text",
success : function(response){
patientName = response;
console.log(patientName);
},
error : function(){
}
});
initialHospital();
});
//遠端網址
//var serverURL = "http://140.121.197.130:8004/BBDPPatient/";
var serverURL = "http://140.121.196.23:3390/BBDPPatient/";
//var fileServerURL = "http://140.121.197.130:8600/BBDPFolderServer/";
var fileServerURL = "http://140.121.196.23:3390/BBDPFolderServer/";
var pictureSource;
var destinationType;
var patientID = window.localStorage.getItem('login');
var doctorID = "";
var time;
var selectPictrue = ""; //圖片路徑
var selectVideo = ""; //影片路徑
var descriptionString; //描述
var patientName = "";
var videoFormat = "";
var doctorInfoJsonString = "";
//取得相簿中的相片
function getPhoto(source) {
selectPictrue = "";
var previewImage = document.getElementById('previewImage');
previewImage.style.display = 'block';
previewImage.src = "img/imageUpload.png";
navigator.camera.getPicture(onPhotoURISuccess,
function(error){console.log("取得相片失敗!")},
{ quality: 50,
destinationType: Camera.DestinationType.FILE_URI,
sourceType : Camera.PictureSourceType.PHOTOLIBRARY ,
encodingType: Camera.EncodingType.JPEG,
mediaType:Camera.MediaType.PICTURE,
popoverOptions : CameraPopoverOptions,
});
}
//取得照片成功後
function onPhotoURISuccess(imageURI) {
window.resolveLocalFileSystemURI(imageURI,
function(fileEntry) {
fileEntry.file(function(fileObj) {
console.log("Size = " + fileObj.size);
if(fileObj.size>5242880){ //5MB
navigator.notification.alert('檔案大小請勿超過5MB',function(){imageURI = "";},'提醒','確定');
}
else{ //顯示照片
var previewImage = document.getElementById('previewImage');
previewImage.style.display = 'block';
previewImage.src = imageURI;
}
},
function (error) {});
}, function (error) {}
);
console.log("照片路徑:" + imageURI); //照片路徑
selectPictrue = imageURI; //設定照片路徑
selectVideo = "";
}
//取得相簿中的影片
function getVideo(source) {
selectVideo = "";
var previewImage = document.getElementById('previewImage');
previewImage.style.display = 'block';
previewImage.src = "img/imageUpload.png";
navigator.camera.getPicture(onVideoURISuccess,
function(error){console.log("取得影片失敗!")},
{ quality: 50,
destinationType: Camera.DestinationType.FILE_URI,
sourceType : Camera.PictureSourceType.PHOTOLIBRARY ,
mediaType:Camera.MediaType.VIDEO,
popoverOptions : CameraPopoverOptions,
});
}
//取得影片成功後
function onVideoURISuccess(videoURI) {
console.log("影片格式:" + videoURI.substr(videoURI.lastIndexOf('.') + 1));
console.log("影片路徑:" + videoURI);
videoFormat = videoURI.substr(videoURI.lastIndexOf('.') + 1);
//檢查格式 (html5video支援格式:mp4 mov ogv webm)
if(videoFormat == 'mp4' || videoFormat == 'mov' || videoFormat == 'MOV'){
previewImage.style.display = 'block';
previewImage.src = "img/uploadOK.png";
selectVideo = videoURI; //設定影片路徑
selectPictrue = "";
}
else{
navigator.notification.alert('不支援'+videoFormat+'格式之影片',function(){},'提醒','確定');
}
}
//上傳檔案
function upload(fileURL, SERVER) {
//上傳按鈕不可按
$('#uploadBtn').empty();
$('#uploadBtn').append("上傳中...");
$('#uploadBtn').attr('disabled', true);
//上傳成功
var success = function (r) {
//推播給醫生
var message = patientName + "傳送了一個檔案";
remindPush(doctorID, patientID, patientName, message, "EditPatientFolder.html?time="+time, "folder");
//推播給家屬
$.ajax({
type: "GET",
url: serverURL+"FamilyServlet",
data: {patientID: patientID, option: "sendFilePush", time: time},
success : function(){
console.log("已傳送推播給家屬");
},
error : function(){
console.log("傳送推播給家屬時發生錯誤");
}
});
//SpinnerDialog
if(device.platform=="Android"){
SpinnerDialog.hide();
}
else if(device.platform=="iOS"){
window.plugins.spinnerDialog.hide();
}
navigator.notification.alert('上傳成功',function(){},'提醒','確定');
window.location.href = 'Folder.html';
}
//上傳失敗
var fail = function (error) {
var previewImage = document.getElementById('previewImage');
previewImage.style.display = 'block';
previewImage.src = "img/imageUpload.png";
//SpinnerDialog
if(device.platform=="Android"){
SpinnerDialog.hide();
}
else if(device.platform=="iOS"){
window.plugins.spinnerDialog.hide();
}
navigator.notification.alert('上傳失敗',function(){},'提醒','確定');
window.location.href = 'UploadFile.html';
}
var options = new FileUploadOptions();
options.fileName = fileURL.substr(fileURL.lastIndexOf('/') + 1);
//options.mimeType = "image/jpeg";
//options.chunkedMode = true; //設置 chunkedMode 選項 false ,防止將上載到 Nginx 伺服器的問題。
//上傳參數
var params = new Object();
params.time = time;
params.patientID = patientID;
params.doctorID = doctorID;
params.description = descriptionString;
params.videoFormat = videoFormat;
params.doctorInfoJsonString = doctorInfoJsonString;
console.log(doctorInfoJsonString);
if(selectPictrue.length > 0){
params.type = "picture"; //String fieldName = item.getFieldName();
}
else if(selectVideo.length > 0){
params.type = "video";
}
options.params = params;
var ft = new FileTransfer();
ft.onprogress = function (e) {
console.info(e);
if (e.lengthComputable) {
console.log('上傳進度:' + e.loaded / e.total);
}
//SpinnerDialog
if(device.platform=="Android"){
SpinnerDialog.show("上傳中", "請稍後...", function(){});
}
else if(device.platform=="iOS"){
window.plugins.spinnerDialog.show("上傳中", "請稍後...", function(){});
}
}
ft.upload(fileURL, encodeURI(SERVER), success, fail, options);
};
//上傳按鈕
$(document).ready(function(){
$("#uploadBtn").click(function(){
var today=new Date();
time = today.getFullYear() + '-'+ (today.getMonth()+1) + '-' + today.getDate() + ' '
+ today.getHours() + ':' + today.getMinutes() + ':' + today.getSeconds();
descriptionString = $('#description').val();
doctorID = $('#doctor').val();
var doctorName = $("#doctor option[value='"+$('#doctor').val()+"']").text()
doctorInfoJsonString = '{"hospital":"'+$('#hospital').val()+'", "department":"'+$('#department').val()+'", "name":"'+doctorName+'"}';
//alert(doctorInfoJsonString);
if($('#hospital').val().length == 0){
navigator.notification.alert('請選擇醫院',function(){},'提醒','確定');
}
else if($('#department').val().length == 0){
navigator.notification.alert('請選擇科別',function(){},'提醒','確定');
}
else if($('#doctor').val().length == 0){
navigator.notification.alert('請選擇醫師',function(){},'提醒','確定');
}
else if($('#description').val().trim() == ""){
navigator.notification.alert('請輸入檔案內容描述',function(){},'提醒','確定');
}
else if($('#description').val().length > 200){
navigator.notification.alert('檔案內容描述請勿超過200個字',function(){},'提醒','確定');
}
else if(selectPictrue.length == 0 && selectVideo.length == 0){
navigator.notification.alert('請選擇照片或影片',function(){},'提醒','確定');
}
else if(selectPictrue.length > 0){
upload(selectPictrue, fileServerURL + "UploadFileServlet"); //上傳照片
}
else if(selectVideo.length > 0){
upload(selectVideo, fileServerURL + "UploadVideoServlet"); //上傳影片
}
});
});
//初始化醫院選單
function initialHospital(){
$.ajax({
url : serverURL+"GetInfoServlet",
data : {option : "searchHospital"},
dataType : "json",
success : function(response) {
$("#hospital").empty();
var option="<option value=''>請選擇</option>";
for(var i=0;i<response.length;i++){
option+="<option value='"+response[i]["hospital"]+"'>"+response[i]["hospital"]+"</option>";
}
$("#hospital").append(option);
$('#hospital').attr('disabled', false); //醫院可選
},
error : function() {
console.log("錯誤訊息");
}
});
}
//醫院選單
function changeHospital(){
if($('#hospital option:selected').val()){
$.ajax({
url : serverURL+"GetInfoServlet",
data : {option : "searchDepartment",hospital:$('#hospital option:selected').val()},
dataType : "json",
success : function(response) {
$("#department").empty();
var temp="<option value=''>請選擇</option>";
for(var i=0;i<response.length;i++){
temp+="<option value='"+response[i]["department"]+"'>"+response[i]["department"]+"</option>";
}
$("#department").append(temp);
$('#department').attr('disabled', false); //診別可選
$("#doctor").empty();
$("#doctor").append("<option value=''>請選擇</option>");
$('#doctor').attr('disabled', true); //醫師不可選
},
error : function() {
console.log("錯誤訊息");
}
});
}
else{ //沒有選擇醫院
$("#department").empty();
$("#department").append("<option value=''>請選擇</option>");
$('#department').attr('disabled', true); //診別不可選
$("#doctor").empty();
$("#doctor").append("<option value=''>請選擇</option>");
$('#doctor').attr('disabled', true); //醫師不可選
}
}
//診別選單
function changeDepartment(){
if($('#department option:selected').val()){
$.ajax({
url : serverURL+"GetInfoServlet",
data : {option : "searchDoctor", hospital : $('#hospital option:selected').val(), department : $('#department option:selected').val()},
dataType : "json",
success : function(response) {
$("#doctor").empty();
var temp="<option value=''>請選擇</option>";
for(var i=0;i<response.length;i++){
temp+="<option value='"+response[i]["doctorID"]+"'>"+response[i]["name"]+"</option>";
}
$("#doctor").append(temp);
$('#doctor').attr('disabled', false); //醫師可選
},
error : function() {
console.log("錯誤訊息");
}
});
}
else{ //沒有選擇診別
$("#doctor").empty();
$("#doctor").append("<option value=''>請選擇</option>");
$('#doctor').attr('disabled', true); //醫師不可選
}
}
</script>
<style type="text/css">
</style>
</head>
<body>
<div class=" text-center title">
<a id="backBtn" onclick="window.history.go(-1);"><img src="img/backButton.png" style="float:left;width:10vw;height:10vw;"></a>
<img src="img/folder.png" style="vertical-align:middle;width:10vw;height:10vw;">
<h1 style="display:inline;">我的檔案</h1>
<img src="img/background.png" style="float:right;width:10vw;height:10vw;">
</div>
<div style="height:15vw;"></div>
<div class="col-xs-12 col-sm-12">
<div style="height:6vw;"></div>
<center>
<img id="previewImage" src="img/imageUpload.png" style="height:25vw;"/> <!--影片上傳成功換圖片為 uploadOK.png-->
<div style="height:6vw;"></div>
<p class="basicText" style="display:inline;vertical-align:middle;">醫院:</p>
<select class="form-control inputLg" id="hospital" onChange="changeHospital()" disabled="disabled" style="display:inline;vertical-align:middle;width:65vw;">
<option value="">請選擇</option>
<option value="中國醫藥大學附設醫院">中國醫藥大學附設醫院</option>
</select>
<div style="height:6vw;"></div>
<p class="basicText" style="display:inline;vertical-align:middle;">科別:</p>
<select class="form-control inputLg" id="department" onChange="changeDepartment()" disabled="disabled" style="display:inline;vertical-align:middle;width:65vw;">
<option value="">請選擇</option>
</select>
<div style="height:6vw;"></div>
<p class="basicText" style="display:inline;vertical-align:middle;">醫師:</p>
<select class="form-control inputLg" id="doctor" disabled="disabled" style="display:inline;vertical-align:middle;width:65vw;">
<option value="">請選擇</option>
</select>
<div style="height:6vw;"></div>
<textarea class="form-control" rows="4" placeholder="檔案內容描述" style="width:80vw" id="description"></textarea>
<div style="height:6vw;"></div>
<button type="button" class="btn btn-save btn-lg" style="display:inline;outline: none;" onclick="getPhoto(pictureSource.PHOTOLIBRARY);" >選擇相片</button>
<button type="button" class="btn btn-save btn-lg" style="display:inline;margin-left:3vw;outline: none;" onclick="getVideo(pictureSource.PHOTOLIBRARY);">選擇影片</button>
<div style="height:6vw;"></div>
<button id="uploadBtn" type="submit" class="btn btn-pink btn-lg" style="outline: none;">上傳</button>
<div style="height:6vw;"></div>
</center>
</div>
</body>
</html>