comparison OrthancServer/OrthancExplorer/file-upload.js @ 4044:d25f4c0fa160 framework

splitting code into OrthancFramework and OrthancServer
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 10 Jun 2020 20:30:34 +0200
parents OrthancExplorer/file-upload.js@fc9a4a2dad63
children 4bb7522a63e0
comparison
equal deleted inserted replaced
4043:6c6239aec462 4044:d25f4c0fa160
1 var pendingUploads = [];
2 var currentUpload = 0;
3 var totalUpload = 0;
4 var alreadyInitialized = false; // trying to debug Orthanc issue #1
5
6 $(document).ready(function() {
7 if (alreadyInitialized) {
8 console.log("Orthanc issue #1: the fileupload has been initialized twice !");
9 } else {
10 alreadyInitialized = true;
11 }
12
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) {
37 console.log("dropped " + data.files.length + " files: ", data);
38 appendFilesToUploadList(data.files);
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.
43 var progress = parseInt(currentUpload / totalUploads * 100, 10);
44 currentUpload += 1;
45 $('#progress .label').text('Uploading: ' + progress + '%');
46 $('#progress .bar')
47 .css('width', progress + '%')
48 .css('background-color', 'green');
49 });
50 });
51
52 function appendFilesToUploadList(files) {
53 var target = $('#upload-list');
54 $.each(files, function (index, file) {
55 target.append('<li class="pending-file">' + file.name + '</li>');
56 });
57 target.listview('refresh');
58 }
59
60 $('#fileupload').live('change', function (e) {
61 appendFilesToUploadList(e.target.files);
62 })
63
64
65 function ClearUploadProgress()
66 {
67 $('#progress .label').text('');
68 $('#progress .bar').css('width', '0%').css('background-color', '#333');
69 }
70
71 $('#upload').live('pagebeforeshow', function() {
72 if (navigator.userAgent.toLowerCase().indexOf('firefox') == -1) {
73 $("#issue-21-warning").css('display', 'none');
74 }
75
76 ClearUploadProgress();
77 });
78
79 $('#upload').live('pageshow', function() {
80 $('#fileupload').fileupload('enable');
81 });
82
83 $('#upload').live('pagehide', function() {
84 $('#fileupload').fileupload('disable');
85 });
86
87
88 $('#upload-button').live('click', function() {
89 var pu = pendingUploads;
90 pendingUploads = [];
91
92 $('.pending-file').remove();
93 $('#upload-list').listview('refresh');
94 ClearUploadProgress();
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
103 for (var i = 0; i < pu.length; i++) {
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 });*/