1

Alright I've been creating some test code to try and clear the upload queue, but I just don't know how to access the refresh() function from where I am. I'm using the jQuery UI widget as base to work from. The part where I use INIT is giving me hell, I just can't seem to figure out how to refresh() from within my json call. I hope you can enlighten me as apparently I suck at jQuery.

    var do_continue = false;

    $("#uploader").plupload({
    // General settings
    runtimes : 'html5,browserplus,silverlight,gears,html4',
    url : CI.base_url + 'private/ad/upload_ad_images',
    max_file_size : '2mb',
    max_file_count: 5, // user can add no more then 20 files at a time
    //chunk_size : '1mb',
    unique_names : true,
    multiple_queues : true,

    // Resize images on clientside if we can
    //resize : {width : 800, height : 600, quality : 90},

    // Rename files by clicking on their titles
    rename: true,

    // Sort files
    sortable: true,

    // Specify what files to browse for
    filters : [
        {title : "Image files", extensions : "jpg,gif,png"}
    ],

    // Flash settings
    flash_swf_url : CI.base_url + 'scripts/plupload/js/plupload.flash.swf',

    // Silverlight settings
    silverlight_xap_url : CI.base_url + 'scripts/plupload/js/plupload.silverlight.xap',
    // Post init events, bound after the internal events
    init : {
        QueueChanged: function(up) {
            // check for max photos here
            $.getJSON(CI.base_url + 'private/ad_ajax/count_uploaded_images/', function(data) {
            if (!data.message) {
                alert("no data found? - please contact us with this message.");
                do_continue = false;
            }else if(data.message != "go") {
                alert("Maximum photo uploads reached.");
                do_continue = false;
            }
            if (!do_continue) {
                $(this).refresh(); // -->> need something that works here
            }
            });
        }
    }
});

2 Answers 2

3

What exactly are you trying to refresh within the UI? As far as I know refresh() only redraws the plupload transparent shim for the runtimes in the correct position. It does not reload the entire UI or refresh/clear the upload queue.

If you could elaborate a bit more as to what/why you are trying a refresh I may be able to help you further. Either way, refresh based on your code is called as follows:

up.refresh();

If you are trying to empty the upload queue entirely that is done as follows:

up.splice();

or from anywhere else within your code using:

var uploader = $('#uploader').plupload('getUploader');
uploader.splice();

You may also want to check into the other available events as I suspect you should be doing your check on FilesAdded rather than on QueueChanged but depends what you are trying to achieve.

1
  • Well, $(this).refresh() seems to refresh the upload queue when I put it directly in QueueChanged: function(up) {$(this).refresh()}. I want it to refresh only when the maximum amount of photos is reached which I'm pulling via $.getJSON. But (this) is not accessible within the getJSON function. I just need to know how to access the refresh/splice from within the getJSON function.
    – qwertzman
    Commented Jan 13, 2012 at 13:39
1
$.getJSON(CI.base_url + 'private/ad_ajax/count_uploaded_images/', function(data) {
if(data.message != "go") {
    alert("Maximum photo uploads reached.");
    do_continue = false;
    plupload.each(files, function(file) {
        up.removeFile(file);
    });
}
});

Was the answer - up.refresh() etc did not work for some reason.

1
  • uploader.splice(); is enough to clear the queue.. maybe using jquery.ui, or flash plugin you will need the refresh afterwards
    – Piotr Kula
    Commented May 3, 2012 at 14:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.