uploader icon indicating copy to clipboard operation
uploader copied to clipboard

Reset queue

Open pavanray opened this issue 8 years ago • 7 comments

Hi, I have a scenario like, I will choose the files and maxFile limit is 4. I am giving the delete icon to delete uploaded file. Now consider I have uploaded 2 images so now remaining count is 2. And if I delete 1 then remaining count should be 3.

But I couldn't reset the queue back. Can you please help me with this.

Thanks in advance.

pavanray avatar Feb 03 '17 11:02 pavanray

Same issue I am also facing. Any help guys ?

Viren0007 avatar Feb 14 '17 07:02 Viren0007

Hey, can you make some example in plunker or jsfiddle? It would be easy to get the issue correctly.

debasispanda avatar Feb 19 '17 07:02 debasispanda

Hi there, I needed a way to reset a queue and I did it like this:

This line shows the current queue. $('#drop-area').data('dmUploader').queue;

You can create a new Array, fill it with the wanted items and just override the queue with the following line:

$('#drop-area').data('dmUploader').queue = newArray;

I hope this helps you. :)

danielatwhitegrid avatar Mar 05 '18 10:03 danielatwhitegrid

The array become empty but the progress line and image is not changing

7aadhi avatar Sep 05 '18 09:09 7aadhi

The array become empty but the progress line and image is not changing

Could you explain your problem a bit more?

danielatwhitegrid avatar Sep 19 '18 12:09 danielatwhitegrid

I call this function to reset the queue to its original state when a button is clicked:

<button id='qClearButton' class='qClearButton' onclick=clearQ() disabled>Clear Queue</button>

function clearQ() { // clear any files currently in queue $('.media').remove(); // add 'No files uploaded' $('#fileQ ul').append('<li class="text-muted text-center empty">No files uploaded.'); // Disable "Clear Queue" button until files have been uploaded $("#qClearButton").prop("disabled", true); }

The button is initially disabled. I enable it when the upload of a queue of files completes:

DmUploader.prototype.processQueue = function() { this.queuePos++;

if (this.queuePos >= this.queue.length) {
  if (this.activeFiles === 0) {
    this.settings.onComplete.call(this.element);
    // When finished, enable "Clear Queue" button
    $("#qClearButton").prop("disabled",false);
  } ... <remainder of function omitted; it's the original code from github>

The function called on the button click disables the button again, and it stays that way until more files are uploaded.

This approach has the benefit of preventing the user from clicking the button and clearing the queue while upload(s) are in progress.

It does NOT, however, reset the queue.length setting. Any thoughts about how this can be done?

SapientHetero avatar Oct 22 '18 23:10 SapientHetero

Found a solution.

function clearQ() {
    // clear any files currently in queue
    $('.media').remove();
    // restore 'No files uploaded' message in user-visible file queue
    $('#files').find('li.empty').fadeIn(); 
    // disable "Clear Queue" button until more files have been uploaded
    $("#qClearButton").prop("disabled", true);
    // get reference to dmUploader plugin in order to access queue-related variables
    var myUploader = $('#drag-and-drop-zone').dmUploader().data();
    myUploader.queue = [];
    myUploader.queuePos = -1;
    myUploader.activeFiles = 0;
}

SapientHetero avatar Oct 25 '18 04:10 SapientHetero