uploader-queue-min.js revision 95cfe14d285d02e9af6e9c97537db3458a335d5b
YUI.add("uploader-queue",function(a){var g=a.Lang,k=a.bind,h=a.config.win,f,d,j,b,i,e;var c=function(l){this.queuedFiles=[],this.numberOfUploads=0,this.currentUploadedByteValues={},this.currentFiles={},this.totalBytesUploaded=0,this.totalBytes=0;c.superclass.constructor.apply(this,arguments);};a.extend(c,a.Base,{_currentState:c.STOPPED,initializer:function(l){},_uploadStartHandler:function(m){var l=m;l.file=m.target;l.originEvent=m;this.fire("uploadstart",l);},_uploadErrorHandler:function(m){var n=this.get("errorAction");var l=m;l.file=m.target;l.originEvent=m;this.numberOfUploads-=1;delete this.currentFiles[m.target.get("id")];m.target.cancelUpload();if(n===c.STOP){this.pauseUpload();}else{if(n===c.RESTART_ASAP){this.queuedFiles.unshift(m.target);this._startNextFile();}else{if(n===c.RESTART_AFTER){this.queuedFiles.push(m.target);this._startNextFile();}}}this.fire("uploaderror",l);},_startNextFile:function(){if(this.queuedFiles.length>0){var m=this.queuedFiles.shift(),l=m.get("id"),n=this.get("perFileParameters"),o=n.hasOwnProperty(l)?n[l]:n;this.currentUploadedByteValues[l]=0;m.on("uploadstart",this._uploadStartHandler,this);m.on("uploadprogress",this._uploadProgressHandler,this);m.on("uploadcomplete",this._uploadCompleteHandler,this);m.on("uploaderror",this._uploadErrorHandler,this);m.startUpload(this.get("uploadURL"),o,this.get("fileFieldName"));this._registerUpload(m);}},_registerUpload:function(l){this.numberOfUploads+=1;this.currentFiles[l.get("id")]=l;},_unregisterUpload:function(l){if(this.numberOfUploads>0){this.numberOfUploads-=1;}delete this.currentFiles[l.get("id")];},_uploadCompleteHandler:function(m){this._unregisterUpload(m.target);this.totalBytesUploaded+=m.target.get("size");delete this.currentUploadedByteValues[m.target.get("id")];if(this.queuedFiles.length>0&&this._currentState===c.UPLOADING){this._startNextFile();}var l=m;l.file=m.target;l.originEvent=m;this.fire("uploadcomplete",l);if(this.queuedFiles.length==0&&this.currentFiles.length==0){this.fire("alluploadscomplete");}},_uploadProgressHandler:function(o){this.currentUploadedByteValues[o.target.get("id")]=o.bytesLoaded;var n=o;n.originEvent=o;n.file=o.target;this.fire("uploadprogress",n);var m=this.totalBytesUploaded;a.each(this.currentUploadedByteValues,function(p){m+=p;});var l=Math.min(100,Math.round(10000*m/this.totalBytes)/100);this.fire("totaluploadprogress",{bytesLoaded:m,bytesTotal:this.totalBytes,percentLoaded:l});},startUpload:function(){this.queuedFiles=this.get("fileList").slice(0);this.numberOfUploads=0;this.currentUploadedByteValues={};this.currentFiles={};this.totalBytesUploaded=0;this._currentState=c.UPLOADING;while(this.numberOfUploads<this.get("simUploads")){this._startNextFile();}},pauseUpload:function(){this._currentState=c.STOPPED;},restartUpload:function(){this._currentState=c.UPLOADING;while(this.numberOfUploads<this.get("simUploads")){this._startNextFile();}},forceReupload:function(l){var m=l.get("id");if(this.currentFiles.hasOwnProperty(m)){l.cancelUpload();this._unregisterUpload(l);this.queuedFiles.unshift(l);this._startNextFile();}},cancelUpload:function(){for(fid in this.currentFiles){this.currentFiles[fid].cancel();this._unregisterUpload(this.currentFiles[fid]);}this.currentUploadedByteValues={};this.currentFiles={};this.totalBytesUploaded=0;}},{CONTINUE:"continue",STOP:"stop",RESTART_ASAP:"restartasap",RESTART_AFTER:"restartafter",STOPPED:"stopped",UPLOADING:"uploading",NAME:"uploaderqueue",ATTRS:{simUploads:{value:2,validator:function(m,l){return(m>=1&&m<=5);}},errorAction:{value:"continue",validator:function(m,l){return(m===c.CONTINUE||m===c.STOP||m===c.RESTART_ASAP||m===c.RESTART_AFTER);}},bytesUploaded:{readOnly:true,value:0},bytesTotal:{readOnly:true,value:0},fileList:{value:[],lazyAdd:false,setter:function(m){var l=m;a.Array.each(l,function(n){this.totalBytes+=n.get("size");},this);return m;}},fileFieldName:{value:"Filedata"},uploadURL:{value:""},perFileParameters:{value:{}}}});a.namespace("Uploader");a.Uploader.Queue=c;},"@VERSION@",{requires:["base"]});