7604 |
25 Feb 19 |
nicklas |
/* $Id $ |
7604 |
25 Feb 19 |
nicklas |
2 |
------------------------------------------------------------------ |
7604 |
25 Feb 19 |
nicklas |
Copyright (C) 2013 Nicklas Nordborg |
7604 |
25 Feb 19 |
nicklas |
4 |
|
7604 |
25 Feb 19 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
7604 |
25 Feb 19 |
nicklas |
Available at http://base.thep.lu.se/ |
7604 |
25 Feb 19 |
nicklas |
7 |
|
7604 |
25 Feb 19 |
nicklas |
BASE is free software; you can redistribute it and/or |
7604 |
25 Feb 19 |
nicklas |
modify it under the terms of the GNU General Public License |
7604 |
25 Feb 19 |
nicklas |
as published by the Free Software Foundation; either version 3 |
7604 |
25 Feb 19 |
nicklas |
of the License, or (at your option) any later version. |
7604 |
25 Feb 19 |
nicklas |
12 |
|
7604 |
25 Feb 19 |
nicklas |
BASE is distributed in the hope that it will be useful, |
7604 |
25 Feb 19 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
7604 |
25 Feb 19 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
7604 |
25 Feb 19 |
nicklas |
GNU General Public License for more details. |
7604 |
25 Feb 19 |
nicklas |
17 |
|
7604 |
25 Feb 19 |
nicklas |
You should have received a copy of the GNU General Public License |
7604 |
25 Feb 19 |
nicklas |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
7604 |
25 Feb 19 |
nicklas |
20 |
------------------------------------------------------------------ |
7604 |
25 Feb 19 |
nicklas |
21 |
|
7604 |
25 Feb 19 |
nicklas |
@author Nicklas |
7604 |
25 Feb 19 |
nicklas |
23 |
*/ |
7604 |
25 Feb 19 |
nicklas |
'use strict'; |
7604 |
25 Feb 19 |
nicklas |
25 |
|
7604 |
25 Feb 19 |
nicklas |
var Upload = function() |
7604 |
25 Feb 19 |
nicklas |
27 |
{ |
7604 |
25 Feb 19 |
nicklas |
var upload = {}; |
7604 |
25 Feb 19 |
nicklas |
29 |
|
7985 |
22 Jun 21 |
nicklas |
var uploadRequest; |
7985 |
22 Jun 21 |
nicklas |
31 |
|
7604 |
25 Feb 19 |
nicklas |
32 |
/** |
7604 |
25 Feb 19 |
nicklas |
Initialize the page. |
7604 |
25 Feb 19 |
nicklas |
34 |
*/ |
7604 |
25 Feb 19 |
nicklas |
upload.initPage = function() |
7604 |
25 Feb 19 |
nicklas |
36 |
{ |
7604 |
25 Feb 19 |
nicklas |
var pageId = Doc.getPageId(); |
7604 |
25 Feb 19 |
nicklas |
if (pageId == 'select-file') |
7604 |
25 Feb 19 |
nicklas |
39 |
{ |
7604 |
25 Feb 19 |
nicklas |
// Zip formats |
7604 |
25 Feb 19 |
nicklas |
upload.initZipFormats(); |
7985 |
22 Jun 21 |
nicklas |
Events.addEventHandler('zipUnpack', 'click', upload.unpackZipOnClick); |
7604 |
25 Feb 19 |
nicklas |
43 |
|
7604 |
25 Feb 19 |
nicklas |
// Upload+Close buttons |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnUpload', upload.doUpload); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('close', App.closeWindow); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnAbort', upload.abortUpload); |
7604 |
25 Feb 19 |
nicklas |
48 |
|
7604 |
25 Feb 19 |
nicklas |
// File |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('the_file', 'change', upload.fileOnChange); |
7604 |
25 Feb 19 |
nicklas |
51 |
|
7604 |
25 Feb 19 |
nicklas |
// Error handling |
7985 |
22 Jun 21 |
nicklas |
Buttons.addClickHandler('failClose', App.closeWindow); |
7604 |
25 Feb 19 |
nicklas |
54 |
} |
7604 |
25 Feb 19 |
nicklas |
55 |
} |
7604 |
25 Feb 19 |
nicklas |
56 |
|
7604 |
25 Feb 19 |
nicklas |
upload.validateFile = function() |
7604 |
25 Feb 19 |
nicklas |
58 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['file']; |
7604 |
25 Feb 19 |
nicklas |
if (Strings.trim(frm.the_file.value) == '') |
7604 |
25 Feb 19 |
nicklas |
61 |
{ |
7604 |
25 Feb 19 |
nicklas |
Forms.showNotification(frm.the_file, 'You must select a file to upload'); |
7604 |
25 Feb 19 |
nicklas |
return false; |
7604 |
25 Feb 19 |
nicklas |
64 |
} |
7604 |
25 Feb 19 |
nicklas |
return true; |
7604 |
25 Feb 19 |
nicklas |
66 |
} |
7604 |
25 Feb 19 |
nicklas |
67 |
|
7604 |
25 Feb 19 |
nicklas |
// Submit the form |
7604 |
25 Feb 19 |
nicklas |
upload.doUpload = function() |
7604 |
25 Feb 19 |
nicklas |
70 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['file']; |
7604 |
25 Feb 19 |
nicklas |
if (upload.validateFile()) |
7604 |
25 Feb 19 |
nicklas |
73 |
{ |
7985 |
22 Jun 21 |
nicklas |
var upl = new FormData(); |
7985 |
22 Jun 21 |
nicklas |
75 |
|
7604 |
25 Feb 19 |
nicklas |
// Copy form values so they are sent BEFORE the file |
7985 |
22 Jun 21 |
nicklas |
upl.set('check_md5', frm.check_md5 && frm.check_md5.checked ? "1" : "0"); |
7985 |
22 Jun 21 |
nicklas |
upl.set('write_protected', frm.write_protected.checked ? "1" : "0"); |
7985 |
22 Jun 21 |
nicklas |
upl.set('replace_existing', frm.replace_existing && frm.replace_existing.checked ? "1" : "0"); |
7985 |
22 Jun 21 |
nicklas |
upl.set('compressed', frm.compressed && frm.compressed.value); |
7985 |
22 Jun 21 |
nicklas |
if (frm.zip_format) |
7604 |
25 Feb 19 |
nicklas |
82 |
{ |
7985 |
22 Jun 21 |
nicklas |
upl.set('zip_format', frm.zip_format.value); |
7985 |
22 Jun 21 |
nicklas |
upl.set('zip_unpack', frm.zip_unpack.checked ? "1" : "0"); |
7985 |
22 Jun 21 |
nicklas |
upl.set('zip_overwrite', frm.zip_overwrite.checked ? "1" : "0"); |
7985 |
22 Jun 21 |
nicklas |
upl.set('zip_keep', frm.zip_keep.checked ? "1" : "0"); |
7604 |
25 Feb 19 |
nicklas |
87 |
} |
7985 |
22 Jun 21 |
nicklas |
upl.set('characterSet', frm.charset.value); |
7985 |
22 Jun 21 |
nicklas |
upl.set('subtype_id', frm.subtype_id.value); |
7985 |
22 Jun 21 |
nicklas |
upl.set('description', frm.description.value); |
7985 |
22 Jun 21 |
nicklas |
upl.set('the_file', frm.the_file.files[0]); |
7985 |
22 Jun 21 |
nicklas |
92 |
|
7985 |
22 Jun 21 |
nicklas |
var url = 'Upload?ID='+App.getSessionId(); |
7985 |
22 Jun 21 |
nicklas |
url += '&directory_id='+Data.get('page-data', 'directory-id'); |
7985 |
22 Jun 21 |
nicklas |
95 |
|
7985 |
22 Jun 21 |
nicklas |
uploadRequest = Ajax.getXmlHttpRequest(); |
7985 |
22 Jun 21 |
nicklas |
Ajax.setReadyStateHandler(uploadRequest, upload.uploadComplete, upload.uploadComplete); |
7985 |
22 Jun 21 |
nicklas |
uploadRequest.open('POST', url, true); |
7985 |
22 Jun 21 |
nicklas |
uploadRequest.send(upl); |
7985 |
22 Jun 21 |
nicklas |
100 |
|
7604 |
25 Feb 19 |
nicklas |
Doc.hide('selectForm'); |
7604 |
25 Feb 19 |
nicklas |
Doc.show('progressForm'); |
7604 |
25 Feb 19 |
nicklas |
upload.sendProgressUpdateRequest(); |
7604 |
25 Feb 19 |
nicklas |
104 |
} |
7604 |
25 Feb 19 |
nicklas |
105 |
} |
7604 |
25 Feb 19 |
nicklas |
106 |
|
7985 |
22 Jun 21 |
nicklas |
upload.uploadComplete = function(request) |
7985 |
22 Jun 21 |
nicklas |
108 |
{ |
7986 |
29 Jun 21 |
nicklas |
// If we have called uploadRequest.abort() |
7986 |
29 Jun 21 |
nicklas |
// we do not need error handling here |
7986 |
29 Jun 21 |
nicklas |
if (request.status == 0) return; |
7985 |
22 Jun 21 |
nicklas |
var result = {}; |
7985 |
22 Jun 21 |
nicklas |
try |
7985 |
22 Jun 21 |
nicklas |
114 |
{ |
7985 |
22 Jun 21 |
nicklas |
var contentType = request.getResponseHeader('Content-Type'); |
7985 |
22 Jun 21 |
nicklas |
if (request.status != 200 || contentType.indexOf('json') == -1) |
7985 |
22 Jun 21 |
nicklas |
117 |
{ |
7985 |
22 Jun 21 |
nicklas |
throw new Error(request.responseText); |
7985 |
22 Jun 21 |
nicklas |
119 |
} |
7985 |
22 Jun 21 |
nicklas |
result = JSON.parse(request.responseText); |
7985 |
22 Jun 21 |
nicklas |
121 |
} |
7985 |
22 Jun 21 |
nicklas |
catch (err) |
7985 |
22 Jun 21 |
nicklas |
123 |
{ |
7985 |
22 Jun 21 |
nicklas |
result.status = 'error'; |
7985 |
22 Jun 21 |
nicklas |
result.message = err; |
7985 |
22 Jun 21 |
nicklas |
126 |
} |
7985 |
22 Jun 21 |
nicklas |
if (result.status == 'ok') |
7985 |
22 Jun 21 |
nicklas |
128 |
{ |
7985 |
22 Jun 21 |
nicklas |
var url = '../../common/close_popup.jsp?refresh_opener=1&message='+encodeURIComponent(result.message); |
7985 |
22 Jun 21 |
nicklas |
window.top.location = url; |
7985 |
22 Jun 21 |
nicklas |
131 |
} |
7985 |
22 Jun 21 |
nicklas |
else |
7985 |
22 Jun 21 |
nicklas |
133 |
{ |
7986 |
29 Jun 21 |
nicklas |
upload.displayError(result); |
7985 |
22 Jun 21 |
nicklas |
135 |
} |
7985 |
22 Jun 21 |
nicklas |
136 |
} |
7985 |
22 Jun 21 |
nicklas |
137 |
|
7604 |
25 Feb 19 |
nicklas |
upload.fileOnChange = function() |
7604 |
25 Feb 19 |
nicklas |
139 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['file']; |
7604 |
25 Feb 19 |
nicklas |
var filename = frm.the_file.value; |
7604 |
25 Feb 19 |
nicklas |
var isZip = false; |
7604 |
25 Feb 19 |
nicklas |
var zipIndex = 0; |
7604 |
25 Feb 19 |
nicklas |
var longestMatch = 0; |
7604 |
25 Feb 19 |
nicklas |
145 |
|
7985 |
22 Jun 21 |
nicklas |
for (var i = 0; i < frm.zip_format.length; i++) |
7604 |
25 Feb 19 |
nicklas |
147 |
{ |
7985 |
22 Jun 21 |
nicklas |
var zf = frm.zip_format[i].zipFormat; |
7604 |
25 Feb 19 |
nicklas |
var matchLength = upload.matchesZipExtension(zf, filename); |
7604 |
25 Feb 19 |
nicklas |
if (matchLength > longestMatch) |
7604 |
25 Feb 19 |
nicklas |
151 |
{ |
7604 |
25 Feb 19 |
nicklas |
isZip = true; |
7604 |
25 Feb 19 |
nicklas |
zipIndex = i; |
7604 |
25 Feb 19 |
nicklas |
longestMatch = matchLength; |
7604 |
25 Feb 19 |
nicklas |
155 |
} |
7604 |
25 Feb 19 |
nicklas |
156 |
} |
7604 |
25 Feb 19 |
nicklas |
157 |
|
7985 |
22 Jun 21 |
nicklas |
if (frm.zip_format) |
7604 |
25 Feb 19 |
nicklas |
159 |
{ |
7985 |
22 Jun 21 |
nicklas |
frm['zip_format'].disabled = !isZip; |
7985 |
22 Jun 21 |
nicklas |
frm['zip_format'].selectedIndex = zipIndex; |
7985 |
22 Jun 21 |
nicklas |
frm['zip_unpack'].disabled = !isZip; |
7985 |
22 Jun 21 |
nicklas |
frm['zip_overwrite'].disabled = !isZip || !frm['zip_unpack'].checked; |
7985 |
22 Jun 21 |
nicklas |
frm['zip_keep'].disabled = !isZip || !frm['zip_unpack'].checked; |
7985 |
22 Jun 21 |
nicklas |
frm['compressed'].disabled = isZip; |
7604 |
25 Feb 19 |
nicklas |
if (isZip) |
7604 |
25 Feb 19 |
nicklas |
167 |
{ |
7604 |
25 Feb 19 |
nicklas |
// Select '-auto-' if present, otherwise 'no' |
7985 |
22 Jun 21 |
nicklas |
Forms.selectListOption(frm['compressed'], '0'); |
7985 |
22 Jun 21 |
nicklas |
Forms.selectListOption(frm['compressed'], ''); |
7604 |
25 Feb 19 |
nicklas |
171 |
} |
7604 |
25 Feb 19 |
nicklas |
172 |
} |
7604 |
25 Feb 19 |
nicklas |
173 |
} |
7604 |
25 Feb 19 |
nicklas |
174 |
|
7604 |
25 Feb 19 |
nicklas |
upload.initZipFormats = function() |
7604 |
25 Feb 19 |
nicklas |
176 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['file']; |
7604 |
25 Feb 19 |
nicklas |
var zipFormats = Data.json('page-data', 'zip-formats'); |
7604 |
25 Feb 19 |
nicklas |
179 |
|
7604 |
25 Feb 19 |
nicklas |
for (var i = 0; i < zipFormats.length; i++) |
7604 |
25 Feb 19 |
nicklas |
181 |
{ |
7604 |
25 Feb 19 |
nicklas |
var zf = zipFormats[i]; |
7604 |
25 Feb 19 |
nicklas |
var option = new Option(upload.getFullZipFormatName(zf), zf.id); |
7985 |
22 Jun 21 |
nicklas |
frm.zip_format[frm.zip_format.length] = option; |
7604 |
25 Feb 19 |
nicklas |
option.zipFormat = zf; |
7604 |
25 Feb 19 |
nicklas |
186 |
} |
7604 |
25 Feb 19 |
nicklas |
187 |
} |
7604 |
25 Feb 19 |
nicklas |
188 |
|
7604 |
25 Feb 19 |
nicklas |
upload.getFullZipFormatName = function(zipFormat) |
7604 |
25 Feb 19 |
nicklas |
190 |
{ |
7604 |
25 Feb 19 |
nicklas |
var s = zipFormat.name + " ["; |
7604 |
25 Feb 19 |
nicklas |
for (var i = 0; i < zipFormat.extensions.length; i++) |
7604 |
25 Feb 19 |
nicklas |
193 |
{ |
7604 |
25 Feb 19 |
nicklas |
if (i > 0) s += ', '; |
7604 |
25 Feb 19 |
nicklas |
s += '*.' + zipFormat.extensions[i]; |
7604 |
25 Feb 19 |
nicklas |
196 |
} |
7604 |
25 Feb 19 |
nicklas |
s += ']'; |
7604 |
25 Feb 19 |
nicklas |
return s; |
7604 |
25 Feb 19 |
nicklas |
199 |
} |
7604 |
25 Feb 19 |
nicklas |
200 |
|
7604 |
25 Feb 19 |
nicklas |
upload.matchesZipExtension = function(zipFormat, filename) |
7604 |
25 Feb 19 |
nicklas |
202 |
{ |
7604 |
25 Feb 19 |
nicklas |
var longestMatch = 0; |
7604 |
25 Feb 19 |
nicklas |
for (var i = 0; i < zipFormat.extensions.length; i++) |
7604 |
25 Feb 19 |
nicklas |
205 |
{ |
7604 |
25 Feb 19 |
nicklas |
var ext = '.' + zipFormat.extensions[i]; |
7604 |
25 Feb 19 |
nicklas |
var index = filename.lastIndexOf(ext); |
7604 |
25 Feb 19 |
nicklas |
if (index > 0 && (index + ext.length == filename.length)) |
7604 |
25 Feb 19 |
nicklas |
209 |
{ |
7604 |
25 Feb 19 |
nicklas |
if (ext.length > longestMatch) |
7604 |
25 Feb 19 |
nicklas |
211 |
{ |
7604 |
25 Feb 19 |
nicklas |
longestMatch = ext.length; |
7604 |
25 Feb 19 |
nicklas |
213 |
} |
7604 |
25 Feb 19 |
nicklas |
214 |
} |
7604 |
25 Feb 19 |
nicklas |
215 |
} |
7604 |
25 Feb 19 |
nicklas |
return longestMatch; |
7604 |
25 Feb 19 |
nicklas |
217 |
} |
7604 |
25 Feb 19 |
nicklas |
218 |
|
7604 |
25 Feb 19 |
nicklas |
upload.unpackZipOnClick = function() |
7604 |
25 Feb 19 |
nicklas |
220 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['file']; |
7985 |
22 Jun 21 |
nicklas |
var checked = frm['zip_unpack'].checked; |
7985 |
22 Jun 21 |
nicklas |
if (!checked) frm['zip_keep'].checked = true; |
7985 |
22 Jun 21 |
nicklas |
frm['zip_overwrite'].disabled = !checked; |
7985 |
22 Jun 21 |
nicklas |
frm['zip_keep'].disabled = !checked; |
7604 |
25 Feb 19 |
nicklas |
226 |
} |
7604 |
25 Feb 19 |
nicklas |
227 |
|
7604 |
25 Feb 19 |
nicklas |
upload.sendProgressUpdateRequest = function() |
7604 |
25 Feb 19 |
nicklas |
229 |
{ |
7604 |
25 Feb 19 |
nicklas |
var request = Ajax.getXmlHttpRequest(); |
7604 |
25 Feb 19 |
nicklas |
var url = 'ajax.jsp?ID='+App.getSessionId(); |
7604 |
25 Feb 19 |
nicklas |
url += '&cmd=GetProgress&'+Math.random(); |
7604 |
25 Feb 19 |
nicklas |
request.open("GET", url, true); |
7604 |
25 Feb 19 |
nicklas |
Ajax.setReadyStateHandler(request, upload.progressUpdateCallback); |
7604 |
25 Feb 19 |
nicklas |
request.send(null); |
7604 |
25 Feb 19 |
nicklas |
236 |
} |
7604 |
25 Feb 19 |
nicklas |
237 |
|
7604 |
25 Feb 19 |
nicklas |
upload.progressUpdateCallback = function(request) |
7604 |
25 Feb 19 |
nicklas |
239 |
{ |
7604 |
25 Feb 19 |
nicklas |
var progress = JSON.parse(request.responseText); |
7986 |
29 Jun 21 |
nicklas |
if (progress) |
7604 |
25 Feb 19 |
nicklas |
242 |
{ |
7986 |
29 Jun 21 |
nicklas |
if (progress.status == 'ok') |
7986 |
29 Jun 21 |
nicklas |
244 |
{ |
7986 |
29 Jun 21 |
nicklas |
if (progress.file) |
7986 |
29 Jun 21 |
nicklas |
246 |
{ |
7986 |
29 Jun 21 |
nicklas |
var filename = progress.file; |
7986 |
29 Jun 21 |
nicklas |
var transferredBytes = progress.transferredBytes; |
7986 |
29 Jun 21 |
nicklas |
var totalBytes = progress.totalBytes; |
7986 |
29 Jun 21 |
nicklas |
var timeInSeconds = progress.timeInSeconds; |
7986 |
29 Jun 21 |
nicklas |
var message = progress.message; |
7986 |
29 Jun 21 |
nicklas |
upload.displayProgress(filename, transferredBytes, totalBytes, timeInSeconds, message); |
7986 |
29 Jun 21 |
nicklas |
253 |
} |
7986 |
29 Jun 21 |
nicklas |
254 |
} |
7986 |
29 Jun 21 |
nicklas |
else |
7986 |
29 Jun 21 |
nicklas |
256 |
{ |
7986 |
29 Jun 21 |
nicklas |
upload.displayError(progress); |
7986 |
29 Jun 21 |
nicklas |
uploadRequest.abort(); // Important!! Otherwise the browser may try to re-send the request |
7986 |
29 Jun 21 |
nicklas |
return; |
7986 |
29 Jun 21 |
nicklas |
260 |
} |
7604 |
25 Feb 19 |
nicklas |
261 |
} |
7604 |
25 Feb 19 |
nicklas |
setTimeout(upload.sendProgressUpdateRequest, 1500); |
7604 |
25 Feb 19 |
nicklas |
263 |
} |
7604 |
25 Feb 19 |
nicklas |
264 |
|
7604 |
25 Feb 19 |
nicklas |
265 |
|
7604 |
25 Feb 19 |
nicklas |
upload.displayProgress = function(fileName, transferredBytes, totalBytes, transferTime, message) |
7604 |
25 Feb 19 |
nicklas |
267 |
{ |
7604 |
25 Feb 19 |
nicklas |
// File name |
7604 |
25 Feb 19 |
nicklas |
Doc.element('fileName').innerHTML = 'Uploading ' + fileName + '...'; |
7604 |
25 Feb 19 |
nicklas |
270 |
|
7604 |
25 Feb 19 |
nicklas |
// Percent done |
7604 |
25 Feb 19 |
nicklas |
var percentDone = totalBytes == 0 ? 0 : Math.round(100 * transferredBytes / totalBytes); |
7604 |
25 Feb 19 |
nicklas |
Doc.element('percentText').innerHTML = percentDone+'%'; |
7604 |
25 Feb 19 |
nicklas |
var doneElement = Doc.element('percentDone'); |
7604 |
25 Feb 19 |
nicklas |
doneElement.style.width = percentDone+'%'; |
7604 |
25 Feb 19 |
nicklas |
var remainElement = Doc.element('percentRemain'); |
7604 |
25 Feb 19 |
nicklas |
remainElement.style.width = (100-percentDone)+'%'; |
7604 |
25 Feb 19 |
nicklas |
if (percentDone == 100) Doc.hide('percentRemain'); |
7604 |
25 Feb 19 |
nicklas |
279 |
|
7604 |
25 Feb 19 |
nicklas |
// Bytes |
7604 |
25 Feb 19 |
nicklas |
Doc.element('transferredBytes').innerHTML = Numbers.formatBytes(transferredBytes); |
7604 |
25 Feb 19 |
nicklas |
Doc.element('totalBytes').innerHTML = Numbers.formatBytes(totalBytes); |
7604 |
25 Feb 19 |
nicklas |
283 |
|
7604 |
25 Feb 19 |
nicklas |
// Times and rate |
7604 |
25 Feb 19 |
nicklas |
Doc.element('transferTime').innerHTML = Numbers.formatSeconds(transferTime); |
7604 |
25 Feb 19 |
nicklas |
var transferRate = transferTime == 0 ? 0 : transferredBytes / transferTime; |
7604 |
25 Feb 19 |
nicklas |
Doc.element('transferRate').innerHTML = '(' + Numbers.formatBytes(transferRate) + '/s)'; |
7604 |
25 Feb 19 |
nicklas |
if (transferRate > 0) |
7604 |
25 Feb 19 |
nicklas |
289 |
{ |
7604 |
25 Feb 19 |
nicklas |
var remainTime = parseInt((totalBytes-transferredBytes) / transferRate); |
7604 |
25 Feb 19 |
nicklas |
Doc.element('remainTime').innerHTML = Numbers.formatSeconds(remainTime) + ' (estimated)'; |
7604 |
25 Feb 19 |
nicklas |
292 |
} |
7604 |
25 Feb 19 |
nicklas |
293 |
|
7604 |
25 Feb 19 |
nicklas |
// Message |
7604 |
25 Feb 19 |
nicklas |
if (message) |
7604 |
25 Feb 19 |
nicklas |
296 |
{ |
7985 |
22 Jun 21 |
nicklas |
Doc.element('message').innerHTML = message.replace(/(.*):(.*)/, '<th>$1</th><td>$2</td>'); |
7604 |
25 Feb 19 |
nicklas |
298 |
} |
7985 |
22 Jun 21 |
nicklas |
else |
7985 |
22 Jun 21 |
nicklas |
300 |
{ |
7985 |
22 Jun 21 |
nicklas |
Doc.element('message').innerHTML = ''; |
7985 |
22 Jun 21 |
nicklas |
302 |
} |
7604 |
25 Feb 19 |
nicklas |
303 |
} |
7604 |
25 Feb 19 |
nicklas |
304 |
|
7986 |
29 Jun 21 |
nicklas |
upload.displayError = function(result) |
7986 |
29 Jun 21 |
nicklas |
306 |
{ |
7986 |
29 Jun 21 |
nicklas |
Doc.show('uploadFailed'); |
7986 |
29 Jun 21 |
nicklas |
Doc.hide('progressForm'); |
7986 |
29 Jun 21 |
nicklas |
Doc.element('failTitle').innerHTML = result.title || 'File upload failed'; |
7986 |
29 Jun 21 |
nicklas |
Doc.element('failMessage').innerHTML = result.message || result.stacktrace; |
7986 |
29 Jun 21 |
nicklas |
if (result.status == 'abort') setTimeout(App.closeWindow, 1500); |
7986 |
29 Jun 21 |
nicklas |
312 |
} |
7604 |
25 Feb 19 |
nicklas |
313 |
|
7604 |
25 Feb 19 |
nicklas |
upload.abortUpload = function() |
7604 |
25 Feb 19 |
nicklas |
315 |
{ |
7604 |
25 Feb 19 |
nicklas |
if (confirm('Are you sure you want to abort the upload? It cannot be resumed.')) |
7604 |
25 Feb 19 |
nicklas |
317 |
{ |
7604 |
25 Feb 19 |
nicklas |
318 |
/* |
7986 |
29 Jun 21 |
nicklas |
Aborting is tricky. See tickets: |
7986 |
29 Jun 21 |
nicklas |
http://base.thep.lu.se/ticket/2018 |
7986 |
29 Jun 21 |
nicklas |
http://base.thep.lu.se/ticket/2019 |
7986 |
29 Jun 21 |
nicklas |
322 |
|
7986 |
29 Jun 21 |
nicklas |
Sending "Abort" command to the server AND |
7986 |
29 Jun 21 |
nicklas |
uploadRequest.abort() should tell both ends. |
7986 |
29 Jun 21 |
nicklas |
The "abort" is catched by the progress updater that |
7986 |
29 Jun 21 |
nicklas |
also display the error message. |
7604 |
25 Feb 19 |
nicklas |
327 |
*/ |
7604 |
25 Feb 19 |
nicklas |
var request = Ajax.getXmlHttpRequest(); |
7604 |
25 Feb 19 |
nicklas |
var url = 'ajax.jsp?ID='+App.getSessionId(); |
7604 |
25 Feb 19 |
nicklas |
url += '&cmd=Abort&'+Math.random(); |
7604 |
25 Feb 19 |
nicklas |
request.open("GET", url, true); |
7604 |
25 Feb 19 |
nicklas |
request.send(null); |
7985 |
22 Jun 21 |
nicklas |
333 |
|
7985 |
22 Jun 21 |
nicklas |
uploadRequest.abort(); |
7604 |
25 Feb 19 |
nicklas |
335 |
} |
7604 |
25 Feb 19 |
nicklas |
336 |
} |
7604 |
25 Feb 19 |
nicklas |
337 |
|
7604 |
25 Feb 19 |
nicklas |
return upload; |
7604 |
25 Feb 19 |
nicklas |
339 |
}(); |
7604 |
25 Feb 19 |
nicklas |
340 |
|
7604 |
25 Feb 19 |
nicklas |
Doc.onLoad(Upload.initPage); |