Skip to content

Commit

Permalink
The totaluploadprogress ignores files that aren't accepted now.
Browse files Browse the repository at this point in the history
Also added a default totaluploadprogress event handler.

Closes dropzone#143, closes dropzone#144
  • Loading branch information
enyo committed May 29, 2013
1 parent edf7f0b commit 361b779
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 10 deletions.
9 changes: 7 additions & 2 deletions downloads/dropzone-amd-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ Emitter.prototype.hasListeners = function(event){
*/


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

Dropzone.prototype.defaultOptions = {
url: null,
Expand Down Expand Up @@ -352,6 +352,7 @@ Emitter.prototype.hasListeners = function(event){
uploadprogress: function(file, progress, bytesSent) {
return file.previewElement.querySelector("[data-dz-uploadprogress]").style.width = "" + progress + "%";
},
totaluploadprogress: noop,
sending: noop,
success: function(file) {
return file.previewElement.classList.add("dz-success");
Expand Down Expand Up @@ -480,6 +481,7 @@ Emitter.prototype.hasListeners = function(event){
setupHiddenFileInput();
}
this.files = [];
this.acceptedFiles = [];
this.filesQueue = [];
this.filesProcessing = [];
this.URL = (_ref = window.URL) != null ? _ref : window.webkitURL;
Expand All @@ -493,7 +495,7 @@ Emitter.prototype.hasListeners = function(event){

totalBytesSent = 0;
totalBytes = 0;
_ref2 = _this.files;
_ref2 = _this.acceptedFiles;
for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {
file = _ref2[_j];
totalBytesSent += file.upload.bytesSent;
Expand Down Expand Up @@ -730,8 +732,11 @@ Emitter.prototype.hasListeners = function(event){
}
return this.accept(file, function(error) {
if (error) {
file.accepted = false;
return _this.errorProcessing(file, error);
} else {
file.accepted = true;
_this.acceptedFiles.push(file);
if (_this.options.enqueueForUpload) {
_this.filesQueue.push(file);
return _this.processQueue();
Expand Down
2 changes: 1 addition & 1 deletion downloads/dropzone-amd-module.min.js

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions downloads/dropzone.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
*/


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

Dropzone.prototype.defaultOptions = {
url: null,
Expand Down Expand Up @@ -561,6 +561,7 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
uploadprogress: function(file, progress, bytesSent) {
return file.previewElement.querySelector("[data-dz-uploadprogress]").style.width = "" + progress + "%";
},
totaluploadprogress: noop,
sending: noop,
success: function(file) {
return file.previewElement.classList.add("dz-success");
Expand Down Expand Up @@ -689,6 +690,7 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
setupHiddenFileInput();
}
this.files = [];
this.acceptedFiles = [];
this.filesQueue = [];
this.filesProcessing = [];
this.URL = (_ref = window.URL) != null ? _ref : window.webkitURL;
Expand All @@ -702,7 +704,7 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){

totalBytesSent = 0;
totalBytes = 0;
_ref2 = _this.files;
_ref2 = _this.acceptedFiles;
for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {
file = _ref2[_j];
totalBytesSent += file.upload.bytesSent;
Expand Down Expand Up @@ -939,8 +941,11 @@ require.register("dropzone/lib/dropzone.js", function(exports, require, module){
}
return this.accept(file, function(error) {
if (error) {
file.accepted = false;
return _this.errorProcessing(file, error);
} else {
file.accepted = true;
_this.acceptedFiles.push(file);
if (_this.options.enqueueForUpload) {
_this.filesQueue.push(file);
return _this.processQueue();
Expand Down
2 changes: 1 addition & 1 deletion downloads/dropzone.min.js

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions lib/dropzone.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
*/


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

Dropzone.prototype.defaultOptions = {
url: null,
Expand Down Expand Up @@ -191,6 +191,7 @@
uploadprogress: function(file, progress, bytesSent) {
return file.previewElement.querySelector("[data-dz-uploadprogress]").style.width = "" + progress + "%";
},
totaluploadprogress: noop,
sending: noop,
success: function(file) {
return file.previewElement.classList.add("dz-success");
Expand Down Expand Up @@ -319,6 +320,7 @@
setupHiddenFileInput();
}
this.files = [];
this.acceptedFiles = [];
this.filesQueue = [];
this.filesProcessing = [];
this.URL = (_ref = window.URL) != null ? _ref : window.webkitURL;
Expand All @@ -332,7 +334,7 @@

totalBytesSent = 0;
totalBytes = 0;
_ref2 = _this.files;
_ref2 = _this.acceptedFiles;
for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {
file = _ref2[_j];
totalBytesSent += file.upload.bytesSent;
Expand Down Expand Up @@ -569,8 +571,11 @@
}
return this.accept(file, function(error) {
if (error) {
file.accepted = false;
return _this.errorProcessing(file, error);
} else {
file.accepted = true;
_this.acceptedFiles.push(file);
if (_this.options.enqueueForUpload) {
_this.filesQueue.push(file);
return _this.processQueue();
Expand Down
12 changes: 10 additions & 2 deletions src/dropzone.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class Dropzone extends Em
"error"
"processingfile"
"uploadprogress"
"totaluploadprogress"
"sending"
"success"
"complete"
Expand Down Expand Up @@ -270,12 +271,15 @@ class Dropzone extends Em
file.previewElement.classList.add "dz-processing"

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

# Called whenever the total upload progress gets updated.
# Called with totalUploadProgress (0-100), totalBytes and totalBytesSent
totaluploadprogress: noop

# Called just before the file is sent. Gets the `xhr` object as second
# parameter, so you can modify it (for example to add a CSRF token) and a
# `formData` object to add additional information.
Expand Down Expand Up @@ -412,6 +416,7 @@ class Dropzone extends Em
setupHiddenFileInput()

@files = [] # All files
@acceptedFiles = [] # All files that are actually accepted
@filesQueue = [] # The files that still have to be processed
@filesProcessing = [] # The files currently processed
@URL = window.URL ? window.webkitURL
Expand All @@ -425,7 +430,7 @@ class Dropzone extends Em
@on "uploadprogress", (file) =>
totalBytesSent = 0;
totalBytes = 0;
for file in @files
for file in @acceptedFiles
totalBytesSent += file.upload.bytesSent
totalBytes += file.upload.total
totalUploadProgress = 100 * totalBytesSent / totalBytes
Expand Down Expand Up @@ -589,8 +594,11 @@ class Dropzone extends Em

@accept file, (error) =>
if error
file.accepted = false
@errorProcessing file, error
else
file.accepted = true
@acceptedFiles.push file
if @options.enqueueForUpload
@filesQueue.push file
@processQueue()
Expand Down
1 change: 1 addition & 0 deletions test/test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ describe "Dropzone", ->
bytesSent: 200
}
]
dropzone.acceptedFiles = dropzone.files

totalProgressExpectation = 15
dropzone.on "totaluploadprogress", (progress) -> progress.should.eql totalProgressExpectation
Expand Down
1 change: 1 addition & 0 deletions test/test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 361b779

Please sign in to comment.