2008-01-25 14:21:11 -05:00
|
|
|
/*
|
|
|
|
Queue Plug-in
|
|
|
|
|
|
|
|
Features:
|
2008-10-30 19:13:53 -04:00
|
|
|
*Adds a cancelQueue() method for cancelling the entire queue.
|
|
|
|
*All queued files are uploaded when startUpload() is called.
|
|
|
|
*If false is returned from uploadComplete then the queue upload is stopped.
|
|
|
|
If false is not returned (strict comparison) then the queue upload is continued.
|
|
|
|
*Adds a QueueComplete event that is fired when all the queued files have finished uploading.
|
|
|
|
Set the event handler with the queue_complete_handler setting.
|
2008-01-25 14:21:11 -05:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
var SWFUpload;
|
|
|
|
if (typeof(SWFUpload) === "function") {
|
|
|
|
SWFUpload.queue = {};
|
|
|
|
|
2008-10-30 19:13:53 -04:00
|
|
|
SWFUpload.prototype.initSettings = (function (oldInitSettings) {
|
|
|
|
return function () {
|
|
|
|
if (typeof(oldInitSettings) === "function") {
|
|
|
|
oldInitSettings.call(this);
|
2008-01-25 14:21:11 -05:00
|
|
|
}
|
|
|
|
|
2009-05-17 08:29:58 -04:00
|
|
|
this.queueSettings = {};
|
2008-01-25 14:21:11 -05:00
|
|
|
|
2009-05-17 08:29:58 -04:00
|
|
|
this.queueSettings.queue_cancelled_flag = false;
|
|
|
|
this.queueSettings.queue_upload_count = 0;
|
|
|
|
|
|
|
|
this.queueSettings.user_upload_complete_handler = this.settings.upload_complete_handler;
|
|
|
|
this.queueSettings.user_upload_start_handler = this.settings.upload_start_handler;
|
2008-10-30 19:13:53 -04:00
|
|
|
this.settings.upload_complete_handler = SWFUpload.queue.uploadCompleteHandler;
|
2009-05-17 08:29:58 -04:00
|
|
|
this.settings.upload_start_handler = SWFUpload.queue.uploadStartHandler;
|
2008-10-30 19:13:53 -04:00
|
|
|
|
|
|
|
this.settings.queue_complete_handler = this.settings.queue_complete_handler || null;
|
2008-01-25 14:21:11 -05:00
|
|
|
};
|
2008-10-30 19:13:53 -04:00
|
|
|
})(SWFUpload.prototype.initSettings);
|
2008-01-25 14:21:11 -05:00
|
|
|
|
2008-10-30 19:13:53 -04:00
|
|
|
SWFUpload.prototype.startUpload = function (fileID) {
|
2009-05-17 08:29:58 -04:00
|
|
|
this.queueSettings.queue_cancelled_flag = false;
|
|
|
|
this.callFlash("StartUpload", [fileID]);
|
2008-10-30 19:13:53 -04:00
|
|
|
};
|
2008-01-25 14:21:11 -05:00
|
|
|
|
2008-10-30 19:13:53 -04:00
|
|
|
SWFUpload.prototype.cancelQueue = function () {
|
2009-05-17 08:29:58 -04:00
|
|
|
this.queueSettings.queue_cancelled_flag = true;
|
2008-10-30 19:13:53 -04:00
|
|
|
this.stopUpload();
|
2008-01-25 14:21:11 -05:00
|
|
|
|
2008-10-30 19:13:53 -04:00
|
|
|
var stats = this.getStats();
|
|
|
|
while (stats.files_queued > 0) {
|
2008-01-25 14:21:11 -05:00
|
|
|
this.cancelUpload();
|
|
|
|
stats = this.getStats();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-05-17 08:29:58 -04:00
|
|
|
SWFUpload.queue.uploadStartHandler = function (file) {
|
|
|
|
var returnValue;
|
|
|
|
if (typeof(this.queueSettings.user_upload_start_handler) === "function") {
|
|
|
|
returnValue = this.queueSettings.user_upload_start_handler.call(this, file);
|
|
|
|
}
|
|
|
|
|
|
|
|
// To prevent upload a real "FALSE" value must be returned, otherwise default to a real "TRUE" value.
|
|
|
|
returnValue = (returnValue === false) ? false : true;
|
|
|
|
|
|
|
|
this.queueSettings.queue_cancelled_flag = !returnValue;
|
|
|
|
|
|
|
|
return returnValue;
|
|
|
|
};
|
|
|
|
|
2008-10-30 19:13:53 -04:00
|
|
|
SWFUpload.queue.uploadCompleteHandler = function (file) {
|
2009-05-17 08:29:58 -04:00
|
|
|
var user_upload_complete_handler = this.queueSettings.user_upload_complete_handler;
|
2008-10-30 19:13:53 -04:00
|
|
|
var continueUpload;
|
|
|
|
|
|
|
|
if (file.filestatus === SWFUpload.FILE_STATUS.COMPLETE) {
|
2009-05-17 08:29:58 -04:00
|
|
|
this.queueSettings.queue_upload_count++;
|
2008-10-30 19:13:53 -04:00
|
|
|
}
|
|
|
|
|
2008-01-25 14:21:11 -05:00
|
|
|
if (typeof(user_upload_complete_handler) === "function") {
|
2008-10-30 19:13:53 -04:00
|
|
|
continueUpload = (user_upload_complete_handler.call(this, file) === false) ? false : true;
|
2009-05-17 08:29:58 -04:00
|
|
|
} else if (file.filestatus === SWFUpload.FILE_STATUS.QUEUED) {
|
|
|
|
// If the file was stopped and re-queued don't restart the upload
|
|
|
|
continueUpload = false;
|
2008-10-30 19:13:53 -04:00
|
|
|
} else {
|
|
|
|
continueUpload = true;
|
2008-01-25 14:21:11 -05:00
|
|
|
}
|
|
|
|
|
2008-10-30 19:13:53 -04:00
|
|
|
if (continueUpload) {
|
2008-01-25 14:21:11 -05:00
|
|
|
var stats = this.getStats();
|
2009-05-17 08:29:58 -04:00
|
|
|
if (stats.files_queued > 0 && this.queueSettings.queue_cancelled_flag === false) {
|
2008-01-25 14:21:11 -05:00
|
|
|
this.startUpload();
|
2009-05-17 08:29:58 -04:00
|
|
|
} else if (this.queueSettings.queue_cancelled_flag === false) {
|
|
|
|
this.queueEvent("queue_complete_handler", [this.queueSettings.queue_upload_count]);
|
|
|
|
this.queueSettings.queue_upload_count = 0;
|
2008-01-25 14:21:11 -05:00
|
|
|
} else {
|
2009-05-17 08:29:58 -04:00
|
|
|
this.queueSettings.queue_cancelled_flag = false;
|
|
|
|
this.queueSettings.queue_upload_count = 0;
|
2008-01-25 14:21:11 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2009-05-17 08:29:58 -04:00
|
|
|
}
|