Mercurial > hg > orthanc
annotate OrthancExplorer/file-upload.js @ 3394:2f82ef41bf5a
fix
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 06 Jun 2019 16:42:41 +0200 |
parents | fc9a4a2dad63 |
children |
rev | line source |
---|---|
0 | 1 var pendingUploads = []; |
2 var currentUpload = 0; | |
3 var totalUpload = 0; | |
3159
4cfed5c2eacd
added debug info for Orthanc issue #1
Alain Mazy <alain@mazy.be>
parents:
3104
diff
changeset
|
4 var alreadyInitialized = false; // trying to debug Orthanc issue #1 |
0 | 5 |
6 $(document).ready(function() { | |
3159
4cfed5c2eacd
added debug info for Orthanc issue #1
Alain Mazy <alain@mazy.be>
parents:
3104
diff
changeset
|
7 if (alreadyInitialized) { |
4cfed5c2eacd
added debug info for Orthanc issue #1
Alain Mazy <alain@mazy.be>
parents:
3104
diff
changeset
|
8 console.log("Orthanc issue #1: the fileupload has been initialized twice !"); |
4cfed5c2eacd
added debug info for Orthanc issue #1
Alain Mazy <alain@mazy.be>
parents:
3104
diff
changeset
|
9 } else { |
4cfed5c2eacd
added debug info for Orthanc issue #1
Alain Mazy <alain@mazy.be>
parents:
3104
diff
changeset
|
10 alreadyInitialized = true; |
4cfed5c2eacd
added debug info for Orthanc issue #1
Alain Mazy <alain@mazy.be>
parents:
3104
diff
changeset
|
11 } |
4cfed5c2eacd
added debug info for Orthanc issue #1
Alain Mazy <alain@mazy.be>
parents:
3104
diff
changeset
|
12 |
0 | 13 // Initialize the jQuery File Upload widget: |
14 $('#fileupload').fileupload({ | |
15 //dataType: 'json', | |
16 //maxChunkSize: 500, | |
17 //sequentialUploads: true, | |
18 limitConcurrentUploads: 3, | |
19 add: function (e, data) { | |
20 pendingUploads.push(data); | |
21 } | |
22 }) | |
23 .bind('fileuploadstop', function(e, data) { | |
24 $('#upload-button').removeClass('ui-disabled'); | |
25 //$('#upload-abort').addClass('ui-disabled'); | |
26 $('#progress .bar').css('width', '100%'); | |
27 if ($('#progress .label').text() != 'Failure') | |
28 $('#progress .label').text('Done'); | |
29 }) | |
30 .bind('fileuploadfail', function(e, data) { | |
31 $('#progress .bar') | |
32 .css('width', '100%') | |
33 .css('background-color', 'red'); | |
34 $('#progress .label').text('Failure'); | |
35 }) | |
36 .bind('fileuploaddrop', function (e, data) { | |
3159
4cfed5c2eacd
added debug info for Orthanc issue #1
Alain Mazy <alain@mazy.be>
parents:
3104
diff
changeset
|
37 console.log("dropped " + data.files.length + " files: ", data); |
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
|
38 appendFilesToUploadList(data.files); |
0 | 39 }) |
40 .bind('fileuploadsend', function (e, data) { | |
41 // Update the progress bar. Note: for some weird reason, the | |
42 // "fileuploadprogressall" does not work under Firefox. | |
3111 | 43 var progress = parseInt(currentUpload / totalUploads * 100, 10); |
0 | 44 currentUpload += 1; |
45 $('#progress .label').text('Uploading: ' + progress + '%'); | |
46 $('#progress .bar') | |
47 .css('width', progress + '%') | |
48 .css('background-color', 'green'); | |
49 }); | |
50 }); | |
51 | |
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
|
52 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
|
53 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
|
54 $.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
|
55 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
|
56 }); |
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 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
|
58 } |
0 | 59 |
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
|
60 $('#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
|
61 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
|
62 }) |
0 | 63 |
3110
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 function ClearUploadProgress() |
7047222cfa96
minor improvements to upload progress bar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3109
diff
changeset
|
66 { |
7047222cfa96
minor improvements to upload progress bar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3109
diff
changeset
|
67 $('#progress .label').text(''); |
7047222cfa96
minor improvements to upload progress bar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3109
diff
changeset
|
68 $('#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
|
69 } |
7047222cfa96
minor improvements to upload progress bar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3109
diff
changeset
|
70 |
7047222cfa96
minor improvements to upload progress bar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3109
diff
changeset
|
71 $('#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
|
72 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
|
73 $("#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
|
74 } |
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
|
75 |
3110
7047222cfa96
minor improvements to upload progress bar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3109
diff
changeset
|
76 ClearUploadProgress(); |
7047222cfa96
minor improvements to upload progress bar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3109
diff
changeset
|
77 }); |
7047222cfa96
minor improvements to upload progress bar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3109
diff
changeset
|
78 |
7047222cfa96
minor improvements to upload progress bar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3109
diff
changeset
|
79 $('#upload').live('pageshow', function() { |
0 | 80 $('#fileupload').fileupload('enable'); |
81 }); | |
82 | |
83 $('#upload').live('pagehide', function() { | |
84 $('#fileupload').fileupload('disable'); | |
85 }); | |
86 | |
87 | |
88 $('#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
|
89 var pu = pendingUploads; |
0 | 90 pendingUploads = []; |
91 | |
92 $('.pending-file').remove(); | |
93 $('#upload-list').listview('refresh'); | |
3110
7047222cfa96
minor improvements to upload progress bar
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3109
diff
changeset
|
94 ClearUploadProgress(); |
0 | 95 |
96 currentUpload = 1; | |
97 totalUploads = pu.length + 1; | |
98 if (pu.length > 0) { | |
99 $('#upload-button').addClass('ui-disabled'); | |
100 //$('#upload-abort').removeClass('ui-disabled'); | |
101 } | |
102 | |
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
|
103 for (var i = 0; i < pu.length; i++) { |
0 | 104 pu[i].submit(); |
105 } | |
106 }); | |
107 | |
108 $('#upload-clear').live('click', function() { | |
109 pendingUploads = []; | |
110 $('.pending-file').remove(); | |
111 $('#upload-list').listview('refresh'); | |
112 }); | |
113 | |
114 /*$('#upload-abort').live('click', function() { | |
115 $('#fileupload').fileupload().abort(); | |
116 });*/ |