annotate OrthancExplorer/file-upload.js @ 3530:b26b6ea27648

endianness to string
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 02 Oct 2019 11:13:32 +0200
parents fc9a4a2dad63
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 var pendingUploads = [];
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 var currentUpload = 0;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 // Initialize the jQuery File Upload widget:
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 $('#fileupload').fileupload({
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 //dataType: 'json',
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 //maxChunkSize: 500,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 //sequentialUploads: true,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 limitConcurrentUploads: 3,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 add: function (e, data) {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 pendingUploads.push(data);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 })
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 .bind('fileuploadstop', function(e, data) {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 $('#upload-button').removeClass('ui-disabled');
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 //$('#upload-abort').addClass('ui-disabled');
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 $('#progress .bar').css('width', '100%');
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 if ($('#progress .label').text() != 'Failure')
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 $('#progress .label').text('Done');
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 })
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 .bind('fileuploadfail', function(e, data) {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 $('#progress .bar')
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 .css('width', '100%')
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 .css('background-color', 'red');
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 $('#progress .label').text('Failure');
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 })
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 })
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 .bind('fileuploadsend', function (e, data) {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 // Update the progress bar. Note: for some weird reason, the
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 // "fileuploadprogressall" does not work under Firefox.
3111
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3110
diff changeset
43 var progress = parseInt(currentUpload / totalUploads * 100, 10);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 currentUpload += 1;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 $('#progress .label').text('Uploading: ' + progress + '%');
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 $('#progress .bar')
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 .css('width', progress + '%')
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 .css('background-color', 'green');
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 });
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 });
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 $('#fileupload').fileupload('enable');
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 });
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 $('#upload').live('pagehide', function() {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 $('#fileupload').fileupload('disable');
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 });
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 pendingUploads = [];
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 $('.pending-file').remove();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 currentUpload = 1;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 totalUploads = pu.length + 1;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 if (pu.length > 0) {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 $('#upload-button').addClass('ui-disabled');
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 //$('#upload-abort').removeClass('ui-disabled');
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 pu[i].submit();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 });
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 $('#upload-clear').live('click', function() {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 pendingUploads = [];
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 $('.pending-file').remove();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 $('#upload-list').listview('refresh');
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 });
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 /*$('#upload-abort').live('click', function() {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 $('#fileupload').fileupload().abort();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 });*/