comparison 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
comparison
equal deleted inserted replaced
3109:6aa8d90aeee5 3110:7047222cfa96
1 var pendingUploads = []; 1 var pendingUploads = [];
2 var currentUpload = 0; 2 var currentUpload = 0;
3 var totalUpload = 0; 3 var totalUpload = 0;
4 4
5 $(document).ready(function() { 5 $(document).ready(function() {
6 var progress;
7
6 // Initialize the jQuery File Upload widget: 8 // Initialize the jQuery File Upload widget:
7 $('#fileupload').fileupload({ 9 $('#fileupload').fileupload({
8 //dataType: 'json', 10 //dataType: 'json',
9 //maxChunkSize: 500, 11 //maxChunkSize: 500,
10 //sequentialUploads: true, 12 //sequentialUploads: true,
31 appendFilesToUploadList(data.files); 33 appendFilesToUploadList(data.files);
32 }) 34 })
33 .bind('fileuploadsend', function (e, data) { 35 .bind('fileuploadsend', function (e, data) {
34 // Update the progress bar. Note: for some weird reason, the 36 // Update the progress bar. Note: for some weird reason, the
35 // "fileuploadprogressall" does not work under Firefox. 37 // "fileuploadprogressall" does not work under Firefox.
36 var progress = parseInt(currentUpload / totalUploads * 100, 10); 38 progress = parseInt(currentUpload / totalUploads * 100, 10);
37 currentUpload += 1; 39 currentUpload += 1;
38 $('#progress .label').text('Uploading: ' + progress + '%'); 40 $('#progress .label').text('Uploading: ' + progress + '%');
39 $('#progress .bar') 41 $('#progress .bar')
40 .css('width', progress + '%') 42 .css('width', progress + '%')
41 .css('background-color', 'green'); 43 .css('background-color', 'green');
52 54
53 $('#fileupload').live('change', function (e) { 55 $('#fileupload').live('change', function (e) {
54 appendFilesToUploadList(e.target.files); 56 appendFilesToUploadList(e.target.files);
55 }) 57 })
56 58
57 $('#upload').live('pageshow', function() { 59
60 function ClearUploadProgress()
61 {
62 $('#progress .label').text('');
63 $('#progress .bar').css('width', '0%').css('background-color', '#333');
64 }
65
66 $('#upload').live('pagebeforeshow', function() {
58 if (navigator.userAgent.toLowerCase().indexOf('firefox') == -1) { 67 if (navigator.userAgent.toLowerCase().indexOf('firefox') == -1) {
59 $("#issue-21-warning").css('display', 'none'); 68 $("#issue-21-warning").css('display', 'none');
60 } 69 }
61 70
71 ClearUploadProgress();
72 });
73
74 $('#upload').live('pageshow', function() {
62 $('#fileupload').fileupload('enable'); 75 $('#fileupload').fileupload('enable');
63 }); 76 });
64 77
65 $('#upload').live('pagehide', function() { 78 $('#upload').live('pagehide', function() {
66 $('#fileupload').fileupload('disable'); 79 $('#fileupload').fileupload('disable');
71 var pu = pendingUploads; 84 var pu = pendingUploads;
72 pendingUploads = []; 85 pendingUploads = [];
73 86
74 $('.pending-file').remove(); 87 $('.pending-file').remove();
75 $('#upload-list').listview('refresh'); 88 $('#upload-list').listview('refresh');
76 $('#progress .bar').css('width', '0%'); 89 ClearUploadProgress();
77 $('#progress .label').text('');
78 90
79 currentUpload = 1; 91 currentUpload = 1;
80 totalUploads = pu.length + 1; 92 totalUploads = pu.length + 1;
81 if (pu.length > 0) { 93 if (pu.length > 0) {
82 $('#upload-button').addClass('ui-disabled'); 94 $('#upload-button').addClass('ui-disabled');