From 0f5ccc9aa3d028fee093c733744064c24fb302b9 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 17 Mar 2009 05:20:37 +0000 Subject: Switch from using SimpleUploader to using swfUpload as our flash based uploader. This is modeled on http://codex.gallery2.org/Gallery3:Upload_UX but is not yet complete. Notes: * Changed #gProgressBar to .gProgressBar to support multiple progress bars on the same page * Added a bunch of CSS to the "needs a home" section in themes/default/css/screen.css --- lib/swfupload/swfupload.queue.js | 77 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 lib/swfupload/swfupload.queue.js (limited to 'lib/swfupload/swfupload.queue.js') diff --git a/lib/swfupload/swfupload.queue.js b/lib/swfupload/swfupload.queue.js new file mode 100644 index 00000000..b04d87ac --- /dev/null +++ b/lib/swfupload/swfupload.queue.js @@ -0,0 +1,77 @@ +/* + Queue Plug-in + + Features: + *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. + + */ + +var SWFUpload; +if (typeof(SWFUpload) === "function") { + SWFUpload.queue = {}; + + SWFUpload.prototype.initSettings = (function (oldInitSettings) { + return function () { + if (typeof(oldInitSettings) === "function") { + oldInitSettings.call(this); + } + + this.customSettings.queue_cancelled_flag = false; + this.customSettings.queue_upload_count = 0; + + this.settings.user_upload_complete_handler = this.settings.upload_complete_handler; + this.settings.upload_complete_handler = SWFUpload.queue.uploadCompleteHandler; + + this.settings.queue_complete_handler = this.settings.queue_complete_handler || null; + }; + })(SWFUpload.prototype.initSettings); + + SWFUpload.prototype.startUpload = function (fileID) { + this.customSettings.queue_cancelled_flag = false; + this.callFlash("StartUpload", false, [fileID]); + }; + + SWFUpload.prototype.cancelQueue = function () { + this.customSettings.queue_cancelled_flag = true; + this.stopUpload(); + + var stats = this.getStats(); + while (stats.files_queued > 0) { + this.cancelUpload(); + stats = this.getStats(); + } + }; + + SWFUpload.queue.uploadCompleteHandler = function (file) { + var user_upload_complete_handler = this.settings.user_upload_complete_handler; + var continueUpload; + + if (file.filestatus === SWFUpload.FILE_STATUS.COMPLETE) { + this.customSettings.queue_upload_count++; + } + + if (typeof(user_upload_complete_handler) === "function") { + continueUpload = (user_upload_complete_handler.call(this, file) === false) ? false : true; + } else { + continueUpload = true; + } + + if (continueUpload) { + var stats = this.getStats(); + if (stats.files_queued > 0 && this.customSettings.queue_cancelled_flag === false) { + this.startUpload(); + } else if (this.customSettings.queue_cancelled_flag === false) { + this.queueEvent("queue_complete_handler", [this.customSettings.queue_upload_count]); + this.customSettings.queue_upload_count = 0; + } else { + this.customSettings.queue_cancelled_flag = false; + this.customSettings.queue_upload_count = 0; + } + } + }; +} \ No newline at end of file -- cgit v1.2.3