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
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;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 // Initialize the jQuery File Upload widget:
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 $('#fileupload').fileupload({
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 //dataType: 'json',
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 //maxChunkSize: 500,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 //sequentialUploads: true,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 limitConcurrentUploads: 3,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 add: function (e, data) {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 pendingUploads.push(data);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 })
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 .bind('fileuploadstop', function(e, data) {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 $('#upload-button').removeClass('ui-disabled');
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 //$('#upload-abort').addClass('ui-disabled');
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 $('#progress .bar').css('width', '100%');
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 if ($('#progress .label').text() != 'Failure')
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 $('#progress .label').text('Done');
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 })
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 .bind('fileuploadfail', function(e, data) {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 $('#progress .bar')
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 .css('width', '100%')
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 .css('background-color', 'red');
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 $('#progress .label').text('Failure');
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 })
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 })
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 .bind('fileuploadsend', function (e, data) {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 // Update the progress bar. Note: for some weird reason, the
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 currentUpload += 1;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 $('#progress .label').text('Uploading: ' + progress + '%');
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 $('#progress .bar')
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 .css('width', progress + '%')
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 .css('background-color', 'green');
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 });
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 });
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 $('#fileupload').fileupload('enable');
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 });
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 $('#upload').live('pagehide', function() {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 $('#fileupload').fileupload('disable');
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 });
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-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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 pendingUploads = [];
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 $('.pending-file').remove();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 currentUpload = 1;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 totalUploads = pu.length + 1;
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 if (pu.length > 0) {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 $('#upload-button').addClass('ui-disabled');
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 //$('#upload-abort').removeClass('ui-disabled');
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 pu[i].submit();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 }
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 $('#upload-clear').live('click', function() {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 pendingUploads = [];
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 $('.pending-file').remove();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 $('#upload-list').listview('refresh');
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
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 /*$('#upload-abort').live('click', function() {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 $('#fileupload').fileupload().abort();
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 });*/