sroze / backbone-upload-manager

An upload manager written using Backbone.js
105 stars 35 forks source link

Clicking cancel uploads only removes half of files from queue #7

Open paradigmbase opened 10 years ago

paradigmbase commented 10 years ago

In my app as well as the demo page, clicking on Cancel Uploads only removes half of the files in the queue.

paradigmbase commented 10 years ago

For the cancel all handler, a while loop works better then using each.

backbone.upload-manager.js ln 198:

// Add cancel all handler
$('button#cancel-uploads-button', this.el).click(function(){
    while (self.files.length) {
        self.files.at(0).cancel();
    }
});
Darksoulsong commented 10 years ago

@paradigmbase Nice solution. Thx a lot!

paradigmbase commented 10 years ago

Np

dogeared commented 10 years ago

Doesn't look like this solution ever got merged in. The bug persists on the demo page. I will setup a PR for this.

sroze commented 10 years ago

@paradigmbase Your code snippet seams to always loop on the first item, as the cancel method on file don't remove it from files collection... Right ?

paradigmbase commented 10 years ago

It essentially does the same thing as your original code, except that instead of using each it uses a while loop. The each loop didn't allow the cancel method to be called on each model in the collection, but a while loop does.

It does call cancel on the first item of the collection. However, each time the loop iterates this is a new item since the previous first item has been removed.