4836: side menu inline edit now properly saved after exiting edit mode.
[acontent.git] / docs / include / jscripts / infusion / components / uploader / js / DemoUploadManager.js
1 fluid_1_1=fluid_1_1||{};(function($,fluid){var updateProgress=function(file,events,demoState,isUploading){if(!isUploading){return }var chunk=Math.min(demoState.chunkSize,file.size);demoState.bytesUploaded=Math.min(demoState.bytesUploaded+chunk,file.size);events.onFileProgress.fire(file,demoState.bytesUploaded,file.size)};var fireAfterFileComplete=function(that,file){if(that.swfUploadSettings){that.swfUploadSettings.upload_complete_handler(file)}else{that.events.afterFileComplete.fire(file)}};var finishAndContinueOrCleanup=function(that,file){that.queueManager.finishFile(file);if(that.queueManager.shouldUploadNextFile()){startUploading(that)}else{that.queueManager.complete()}};var finishUploading=function(that){if(!that.queue.isUploading){return }var file=that.demoState.currentFile;file.filestatus=fluid.uploader.fileStatusConstants.COMPLETE;that.events.onFileSuccess.fire(file);that.demoState.fileIdx++;finishAndContinueOrCleanup(that,file)};var simulateUpload=function(that){if(!that.queue.isUploading){return }var file=that.demoState.currentFile;if(that.demoState.bytesUploaded<file.size){that.invokeAfterRandomDelay(function(){updateProgress(file,that.events,that.demoState,that.queue.isUploading);simulateUpload(that)})}else{finishUploading(that)}};var startUploading=function(that){that.demoState.currentFile=that.queue.files[that.demoState.fileIdx];that.demoState.chunksForCurrentFile=Math.ceil(that.demoState.currentFile/that.demoState.chunkSize);that.demoState.bytesUploaded=0;that.queue.isUploading=true;that.events.onFileStart.fire(that.demoState.currentFile);that.demoState.currentFile.filestatus=fluid.uploader.fileStatusConstants.IN_PROGRESS;simulateUpload(that)};var stopDemo=function(that){var file=that.demoState.currentFile;file.filestatus=fluid.uploader.fileStatusConstants.CANCELLED;that.queue.shouldStop=true;that.events.onFileError.fire(file,fluid.uploader.errorConstants.UPLOAD_STOPPED,"The demo upload was paused by the user.");finishAndContinueOrCleanup(that,file);that.events.onUploadStop.fire()};var setupDemoUploadManager=function(that){if(that.options.simulateDelay===undefined||that.options.simulateDelay===null){that.options.simulateDelay=true}that.demoState={fileIdx:0,chunkSize:200000};return that};fluid.demoUploadManager=function(uploadManager){var that=uploadManager;that.start=function(){that.queueManager.start();startUploading(that)};that.stop=function(){stopDemo(that)};that.invokeAfterRandomDelay=function(fn){var delay;if(that.options.simulateDelay){delay=Math.floor(Math.random()*1000+100);setTimeout(fn,delay)}else{fn()}};setupDemoUploadManager(that);return that}})(jQuery,fluid_1_1);