Skip to content

Commit 361b779

Browse files
committed
The totaluploadprogress ignores files that aren't accepted now.
Also added a default totaluploadprogress event handler. Closes dropzone#143, closes dropzone#144
1 parent edf7f0b commit 361b779

File tree

8 files changed

+35
-10
lines changed

8 files changed

+35
-10
lines changed

downloads/dropzone-amd-module.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ Emitter.prototype.hasListeners = function(event){
209209
*/
210210

211211

212-
Dropzone.prototype.events = ["drop", "dragstart", "dragend", "dragenter", "dragover", "dragleave", "selectedfiles", "addedfile", "removedfile", "thumbnail", "error", "processingfile", "uploadprogress", "sending", "success", "complete", "reset"];
212+
Dropzone.prototype.events = ["drop", "dragstart", "dragend", "dragenter", "dragover", "dragleave", "selectedfiles", "addedfile", "removedfile", "thumbnail", "error", "processingfile", "uploadprogress", "totaluploadprogress", "sending", "success", "complete", "reset"];
213213

214214
Dropzone.prototype.defaultOptions = {
215215
url: null,
@@ -352,6 +352,7 @@ Emitter.prototype.hasListeners = function(event){
352352
uploadprogress: function(file, progress, bytesSent) {
353353
return file.previewElement.querySelector("[data-dz-uploadprogress]").style.width = "" + progress + "%";
354354
},
355+
totaluploadprogress: noop,
355356
sending: noop,
356357
success: function(file) {
357358
return file.previewElement.classList.add("dz-success");
@@ -480,6 +481,7 @@ Emitter.prototype.hasListeners = function(event){
480481
setupHiddenFileInput();
481482
}
482483
this.files = [];
484+
this.acceptedFiles = [];
483485
this.filesQueue = [];
484486
this.filesProcessing = [];
485487
this.URL = (_ref = window.URL) != null ? _ref : window.webkitURL;
@@ -493,7 +495,7 @@ Emitter.prototype.hasListeners = function(event){
493495

494496
totalBytesSent = 0;
495497
totalBytes = 0;
496-
_ref2 = _this.files;
498+
_ref2 = _this.acceptedFiles;
497499
for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {
498500
file = _ref2[_j];
499501
totalBytesSent += file.upload.bytesSent;
@@ -730,8 +732,11 @@ Emitter.prototype.hasListeners = function(event){
730732
}
731733
return this.accept(file, function(error) {
732734
if (error) {
735+
file.accepted = false;
733736
return _this.errorProcessing(file, error);
734737
} else {
738+
file.accepted = true;
739+
_this.acceptedFiles.push(file);
735740
if (_this.options.enqueueForUpload) {
736741
_this.filesQueue.push(file);
737742
return _this.processQueue();

downloads/dropzone-amd-module.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

downloads/dropzone.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
418418
*/
419419

420420

421-
Dropzone.prototype.events = ["drop", "dragstart", "dragend", "dragenter", "dragover", "dragleave", "selectedfiles", "addedfile", "removedfile", "thumbnail", "error", "processingfile", "uploadprogress", "sending", "success", "complete", "reset"];
421+
Dropzone.prototype.events = ["drop", "dragstart", "dragend", "dragenter", "dragover", "dragleave", "selectedfiles", "addedfile", "removedfile", "thumbnail", "error", "processingfile", "uploadprogress", "totaluploadprogress", "sending", "success", "complete", "reset"];
422422

423423
Dropzone.prototype.defaultOptions = {
424424
url: null,
@@ -561,6 +561,7 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
561561
uploadprogress: function(file, progress, bytesSent) {
562562
return file.previewElement.querySelector("[data-dz-uploadprogress]").style.width = "" + progress + "%";
563563
},
564+
totaluploadprogress: noop,
564565
sending: noop,
565566
success: function(file) {
566567
return file.previewElement.classList.add("dz-success");
@@ -689,6 +690,7 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
689690
setupHiddenFileInput();
690691
}
691692
this.files = [];
693+
this.acceptedFiles = [];
692694
this.filesQueue = [];
693695
this.filesProcessing = [];
694696
this.URL = (_ref = window.URL) != null ? _ref : window.webkitURL;
@@ -702,7 +704,7 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
702704

703705
totalBytesSent = 0;
704706
totalBytes = 0;
705-
_ref2 = _this.files;
707+
_ref2 = _this.acceptedFiles;
706708
for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {
707709
file = _ref2[_j];
708710
totalBytesSent += file.upload.bytesSent;
@@ -939,8 +941,11 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
939941
}
940942
return this.accept(file, function(error) {
941943
if (error) {
944+
file.accepted = false;
942945
return _this.errorProcessing(file, error);
943946
} else {
947+
file.accepted = true;
948+
_this.acceptedFiles.push(file);
944949
if (_this.options.enqueueForUpload) {
945950
_this.filesQueue.push(file);
946951
return _this.processQueue();

downloads/dropzone.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/dropzone.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
*/
4949

5050

51-
Dropzone.prototype.events = ["drop", "dragstart", "dragend", "dragenter", "dragover", "dragleave", "selectedfiles", "addedfile", "removedfile", "thumbnail", "error", "processingfile", "uploadprogress", "sending", "success", "complete", "reset"];
51+
Dropzone.prototype.events = ["drop", "dragstart", "dragend", "dragenter", "dragover", "dragleave", "selectedfiles", "addedfile", "removedfile", "thumbnail", "error", "processingfile", "uploadprogress", "totaluploadprogress", "sending", "success", "complete", "reset"];
5252

5353
Dropzone.prototype.defaultOptions = {
5454
url: null,
@@ -191,6 +191,7 @@
191191
uploadprogress: function(file, progress, bytesSent) {
192192
return file.previewElement.querySelector("[data-dz-uploadprogress]").style.width = "" + progress + "%";
193193
},
194+
totaluploadprogress: noop,
194195
sending: noop,
195196
success: function(file) {
196197
return file.previewElement.classList.add("dz-success");
@@ -319,6 +320,7 @@
319320
setupHiddenFileInput();
320321
}
321322
this.files = [];
323+
this.acceptedFiles = [];
322324
this.filesQueue = [];
323325
this.filesProcessing = [];
324326
this.URL = (_ref = window.URL) != null ? _ref : window.webkitURL;
@@ -332,7 +334,7 @@
332334

333335
totalBytesSent = 0;
334336
totalBytes = 0;
335-
_ref2 = _this.files;
337+
_ref2 = _this.acceptedFiles;
336338
for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {
337339
file = _ref2[_j];
338340
totalBytesSent += file.upload.bytesSent;
@@ -569,8 +571,11 @@
569571
}
570572
return this.accept(file, function(error) {
571573
if (error) {
574+
file.accepted = false;
572575
return _this.errorProcessing(file, error);
573576
} else {
577+
file.accepted = true;
578+
_this.acceptedFiles.push(file);
574579
if (_this.options.enqueueForUpload) {
575580
_this.filesQueue.push(file);
576581
return _this.processQueue();

src/dropzone.coffee

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class Dropzone extends Em
5454
"error"
5555
"processingfile"
5656
"uploadprogress"
57+
"totaluploadprogress"
5758
"sending"
5859
"success"
5960
"complete"
@@ -270,12 +271,15 @@ class Dropzone extends Em
270271
file.previewElement.classList.add "dz-processing"
271272

272273
# Called whenever the upload progress gets updated.
273-
# You can be sure that this will be called with the percentage 100% when the file is finished uploading.
274274
# Receives `file`, `progress` (percentage 0-100) and `bytesSent`.
275275
# To get the total number of bytes of the file, use `file.size`
276276
uploadprogress: (file, progress, bytesSent) ->
277277
file.previewElement.querySelector("[data-dz-uploadprogress]").style.width = "#{progress}%"
278278

279+
# Called whenever the total upload progress gets updated.
280+
# Called with totalUploadProgress (0-100), totalBytes and totalBytesSent
281+
totaluploadprogress: noop
282+
279283
# Called just before the file is sent. Gets the `xhr` object as second
280284
# parameter, so you can modify it (for example to add a CSRF token) and a
281285
# `formData` object to add additional information.
@@ -412,6 +416,7 @@ class Dropzone extends Em
412416
setupHiddenFileInput()
413417

414418
@files = [] # All files
419+
@acceptedFiles = [] # All files that are actually accepted
415420
@filesQueue = [] # The files that still have to be processed
416421
@filesProcessing = [] # The files currently processed
417422
@URL = window.URL ? window.webkitURL
@@ -425,7 +430,7 @@ class Dropzone extends Em
425430
@on "uploadprogress", (file) =>
426431
totalBytesSent = 0;
427432
totalBytes = 0;
428-
for file in @files
433+
for file in @acceptedFiles
429434
totalBytesSent += file.upload.bytesSent
430435
totalBytes += file.upload.total
431436
totalUploadProgress = 100 * totalBytesSent / totalBytes
@@ -589,8 +594,11 @@ class Dropzone extends Em
589594

590595
@accept file, (error) =>
591596
if error
597+
file.accepted = false
592598
@errorProcessing file, error
593599
else
600+
file.accepted = true
601+
@acceptedFiles.push file
594602
if @options.enqueueForUpload
595603
@filesQueue.push file
596604
@processQueue()

test/test.coffee

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ describe "Dropzone", ->
370370
bytesSent: 200
371371
}
372372
]
373+
dropzone.acceptedFiles = dropzone.files
373374

374375
totalProgressExpectation = 15
375376
dropzone.on "totaluploadprogress", (progress) -> progress.should.eql totalProgressExpectation

test/test.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)