Mercurial > hg > orthanc
annotate OrthancExplorer/file-upload.js @ 3110:7047222cfa96
minor improvements to upload progress bar
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 11 Jan 2019 10:55:18 +0100 |
parents | 6aa8d90aeee5 |
children | 495ec3d3893d |
rev | line source |
---|---|
0 | 1 var pendingUploads = []; |
2 var currentUpload = 0; | |
3 var totalUpload = 0; | |
4 | |
5 $(document).ready(function() { | |
3110
7047222cfa96
minor improvements to upload progress bar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3109
diff
changeset
|
6 var progress; |
7047222cfa96
minor improvements to upload progress bar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3109
diff
changeset
|
7 |
0 | 8 // Initialize the jQuery File Upload widget: |
9 $('#fileupload').fileupload({ | |
10 //dataType: 'json', | |
11 //maxChunkSize: 500, | |
12 //sequentialUploads: true, | |
13 limitConcurrentUploads: 3, | |
14 add: function (e, data) { | |
15 pendingUploads.push(data); | |
16 } | |
17 }) | |
18 .bind('fileuploadstop', function(e, data) { | |
19 $('#upload-button').removeClass('ui-disabled'); | |
20 //$('#upload-abort').addClass('ui-disabled'); | |
21 $('#progress .bar').css('width', '100%'); | |
22 if ($('#progress .label').text() != 'Failure') | |
23 $('#progress .label').text('Done'); | |
24 }) | |
25 .bind('fileuploadfail', function(e, data) { | |
26 $('#progress .bar') | |
27 .css('width', '100%') | |
28 .css('background-color', 'red'); | |
29 $('#progress .label').text('Failure'); | |
30 }) | |
31 .bind('fileuploaddrop', function (e, data) { | |
3104
b311cff247ca
added a log in console to debug issue #1. Can't reproduce the issue since then so let's keep the log!
Alain Mazy <alain@mazy.be>
parents:
3103
diff
changeset
|
32 console.log("dropped " + data.files.length + " files"); |
3102
9b18c8d4d459
'fix' for Orthanc issue 21: added a select file button + a warning specific for Firefox users
Alain Mazy <alain@mazy.be>
parents:
3023
diff
changeset
|
33 appendFilesToUploadList(data.files); |
0 | 34 }) |
35 .bind('fileuploadsend', function (e, data) { | |
36 // Update the progress bar. Note: for some weird reason, the | |
37 // "fileuploadprogressall" does not work under Firefox. | |
3110
7047222cfa96
minor improvements to upload progress bar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3109
diff
changeset
|
38 progress = parseInt(currentUpload / totalUploads * 100, 10); |
0 | 39 currentUpload += 1; |
40 $('#progress .label').text('Uploading: ' + progress + '%'); | |
41 $('#progress .bar') | |
42 .css('width', progress + '%') | |
43 .css('background-color', 'green'); | |
44 }); | |
45 }); | |
46 | |
3102
9b18c8d4d459
'fix' for Orthanc issue 21: added a select file button + a warning specific for Firefox users
Alain Mazy <alain@mazy.be>
parents:
3023
diff
changeset
|
47 function appendFilesToUploadList(files) { |
3103
81b58b549845
back to using 'var' instead of 'let' since let is not supported by many old browsers. All variables declaration have been moved to the top of the function to better show that their scope is the function
Alain Mazy <alain@mazy.be>
parents:
3102
diff
changeset
|
48 var target = $('#upload-list'); |
3102
9b18c8d4d459
'fix' for Orthanc issue 21: added a select file button + a warning specific for Firefox users
Alain Mazy <alain@mazy.be>
parents:
3023
diff
changeset
|
49 $.each(files, function (index, file) { |
9b18c8d4d459
'fix' for Orthanc issue 21: added a select file button + a warning specific for Firefox users
Alain Mazy <alain@mazy.be>
parents:
3023
diff
changeset
|
50 target.append('<li class="pending-file">' + file.name + '</li>'); |
9b18c8d4d459
'fix' for Orthanc issue 21: added a select file button + a warning specific for Firefox users
Alain Mazy <alain@mazy.be>
parents:
3023
diff
changeset
|
51 }); |
9b18c8d4d459
'fix' for Orthanc issue 21: added a select file button + a warning specific for Firefox users
Alain Mazy <alain@mazy.be>
parents:
3023
diff
changeset
|
52 target.listview('refresh'); |
9b18c8d4d459
'fix' for Orthanc issue 21: added a select file button + a warning specific for Firefox users
Alain Mazy <alain@mazy.be>
parents:
3023
diff
changeset
|
53 } |
0 | 54 |
3102
9b18c8d4d459
'fix' for Orthanc issue 21: added a select file button + a warning specific for Firefox users
Alain Mazy <alain@mazy.be>
parents:
3023
diff
changeset
|
55 $('#fileupload').live('change', function (e) { |
9b18c8d4d459
'fix' for Orthanc issue 21: added a select file button + a warning specific for Firefox users
Alain Mazy <alain@mazy.be>
parents:
3023
diff
changeset
|
56 appendFilesToUploadList(e.target.files); |
9b18c8d4d459
'fix' for Orthanc issue 21: added a select file button + a warning specific for Firefox users
Alain Mazy <alain@mazy.be>
parents:
3023
diff
changeset
|
57 }) |
0 | 58 |
3110
7047222cfa96
minor improvements to upload progress bar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3109
diff
changeset
|
59 |
7047222cfa96
minor improvements to upload progress bar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3109
diff
changeset
|
60 function ClearUploadProgress() |
7047222cfa96
minor improvements to upload progress bar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3109
diff
changeset
|
61 { |
7047222cfa96
minor improvements to upload progress bar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3109
diff
changeset
|
62 $('#progress .label').text(''); |
7047222cfa96
minor improvements to upload progress bar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3109
diff
changeset
|
63 $('#progress .bar').css('width', '0%').css('background-color', '#333'); |
7047222cfa96
minor improvements to upload progress bar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3109
diff
changeset
|
64 } |
7047222cfa96
minor improvements to upload progress bar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3109
diff
changeset
|
65 |
7047222cfa96
minor improvements to upload progress bar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3109
diff
changeset
|
66 $('#upload').live('pagebeforeshow', function() { |
3102
9b18c8d4d459
'fix' for Orthanc issue 21: added a select file button + a warning specific for Firefox users
Alain Mazy <alain@mazy.be>
parents:
3023
diff
changeset
|
67 if (navigator.userAgent.toLowerCase().indexOf('firefox') == -1) { |
9b18c8d4d459
'fix' for Orthanc issue 21: added a select file button + a warning specific for Firefox users
Alain Mazy <alain@mazy.be>
parents:
3023
diff
changeset
|
68 $("#issue-21-warning").css('display', 'none'); |
9b18c8d4d459
'fix' for Orthanc issue 21: added a select file button + a warning specific for Firefox users
Alain Mazy <alain@mazy.be>
parents:
3023
diff
changeset
|
69 } |
9b18c8d4d459
'fix' for Orthanc issue 21: added a select file button + a warning specific for Firefox users
Alain Mazy <alain@mazy.be>
parents:
3023
diff
changeset
|
70 |
3110
7047222cfa96
minor improvements to upload progress bar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3109
diff
changeset
|
71 ClearUploadProgress(); |
7047222cfa96
minor improvements to upload progress bar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3109
diff
changeset
|
72 }); |
7047222cfa96
minor improvements to upload progress bar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3109
diff
changeset
|
73 |
7047222cfa96
minor improvements to upload progress bar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3109
diff
changeset
|
74 $('#upload').live('pageshow', function() { |
0 | 75 $('#fileupload').fileupload('enable'); |
76 }); | |
77 | |
78 $('#upload').live('pagehide', function() { | |
79 $('#fileupload').fileupload('disable'); | |
80 }); | |
81 | |
82 | |
83 $('#upload-button').live('click', function() { | |
3103
81b58b549845
back to using 'var' instead of 'let' since let is not supported by many old browsers. All variables declaration have been moved to the top of the function to better show that their scope is the function
Alain Mazy <alain@mazy.be>
parents:
3102
diff
changeset
|
84 var pu = pendingUploads; |
0 | 85 pendingUploads = []; |
86 | |
87 $('.pending-file').remove(); | |
88 $('#upload-list').listview('refresh'); | |
3110
7047222cfa96
minor improvements to upload progress bar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3109
diff
changeset
|
89 ClearUploadProgress(); |
0 | 90 |
91 currentUpload = 1; | |
92 totalUploads = pu.length + 1; | |
93 if (pu.length > 0) { | |
94 $('#upload-button').addClass('ui-disabled'); | |
95 //$('#upload-abort').removeClass('ui-disabled'); | |
96 } | |
97 | |
3103
81b58b549845
back to using 'var' instead of 'let' since let is not supported by many old browsers. All variables declaration have been moved to the top of the function to better show that their scope is the function
Alain Mazy <alain@mazy.be>
parents:
3102
diff
changeset
|
98 for (var i = 0; i < pu.length; i++) { |
0 | 99 pu[i].submit(); |
100 } | |
101 }); | |
102 | |
103 $('#upload-clear').live('click', function() { | |
104 pendingUploads = []; | |
105 $('.pending-file').remove(); | |
106 $('#upload-list').listview('refresh'); | |
107 }); | |
108 | |
109 /*$('#upload-abort').live('click', function() { | |
110 $('#fileupload').fileupload().abort(); | |
111 });*/ |