diff --git a/AjaxControlToolkit/AjaxFileUpload/AjaxFileUpload.cs b/AjaxControlToolkit/AjaxFileUpload/AjaxFileUpload.cs index 052582c15..9c24ca371 100644 --- a/AjaxControlToolkit/AjaxFileUpload/AjaxFileUpload.cs +++ b/AjaxControlToolkit/AjaxFileUpload/AjaxFileUpload.cs @@ -139,6 +139,18 @@ public AjaxFileUpload() set { ViewState["Mode"] = value.ToString(); } } + /// + /// Whether or not automatically start upload files after drag/drop or select in file dialog. The default is false + /// + [ExtenderControlProperty] + [DefaultValue(false)] + [ClientPropertyName("autoStartUpload")] + public bool AutoStartUpload + { + get { return bool.Parse((string)ViewState["AutoStartUpload"] ?? "false"); } + set { ViewState["AutoStartUpload"] = value.ToString(); } + } + /// /// An event raised when the file upload starts. /// diff --git a/AjaxControlToolkit/Scripts/AjaxFileUpload.js b/AjaxControlToolkit/Scripts/AjaxFileUpload.js index 865cbcbfe..818f767a5 100644 --- a/AjaxControlToolkit/Scripts/AjaxFileUpload.js +++ b/AjaxControlToolkit/Scripts/AjaxFileUpload.js @@ -584,6 +584,11 @@ Sys.Extended.UI.AjaxFileUpload.ProcessorHtml5 = function(control, elements) { e.stopPropagation(); e.preventDefault(); this.addFilesToQueue(e.dataTransfer.files); + + if (control.get_autoStartUpload()) { + control.startUpload(); + } + }; this.onFileDragOverHandler = function(e) { @@ -594,6 +599,10 @@ Sys.Extended.UI.AjaxFileUpload.ProcessorHtml5 = function(control, elements) { this.onFileSelectedHandler = function(e) { this.addFilesToQueue(e.target.files); this.createInputFileElement(); + + if (control.get_autoStartUpload()) { + control.startUpload(); + } }; this.createInputFileElement = function() { @@ -633,10 +642,10 @@ Sys.Extended.UI.AjaxFileUpload.ProcessorHtml5 = function(control, elements) { // #endregion - this.addFilesToQueue = function(files) { - // Validate and generate file item from HTML5 files. + this.addFilesToQueue = function (files) { - for(var i = 0; i < files.length; i++) { + // Validate and generate file item from HTML5 files. + for (var i = 0; i < files.length; i++) { var blob = files[i], slices = 0; @@ -953,6 +962,14 @@ Sys.Extended.UI.AjaxFileUpload.Control = function(element) { /// this._mode = 0; + /// + /// Whether or not automatically start upload files after drag/drop or select in file dialog. The default is false + /// + /// get_autoStartUpload + /// set_autoStartUpload + /// + this._autoStartUpload = false; + /// /// Whether or not AjaxFileUpload supports server polling. /// @@ -1182,6 +1199,18 @@ Sys.Extended.UI.AjaxFileUpload.Control.prototype = { } }, + /// + /// Manually starts upload process + /// + startUpload: function () { + if (this._isUploading || !this._filesInQueue.length) { + return; + } + + this._onUploadOrCancelButtonClickedHandler(); + }, + + /// /// If set to true, it will set the control state to enabled (ready to upload), /// otherwise the control will be disabled and the button state turns to the Cancel button. @@ -1530,6 +1559,13 @@ Sys.Extended.UI.AjaxFileUpload.Control.prototype = { this._mode = value; }, + get_autoStartUpload: function () { + return this._autoStartUpload; + }, + set_autoStartUpload: function (value) { + this._autoStartUpload = value; + }, + get_serverPollingSupport: function() { return this._serverPollingSupport; }, diff --git a/AjaxControlToolkit/Scripts/AjaxFileUpload.min.js b/AjaxControlToolkit/Scripts/AjaxFileUpload.min.js index 169a51e33..2dcf3824b 100644 --- a/AjaxControlToolkit/Scripts/AjaxFileUpload.min.js +++ b/AjaxControlToolkit/Scripts/AjaxFileUpload.min.js @@ -1 +1 @@ -Type.registerNamespace("Sys.Extended.UI.AjaxFileUpload");Sys.Extended.UI.AjaxFileUpload.Utils=function(){this.generateGuid=function(){for(var i,t="",n=0;n<32;n++)(n==8||n==12||n==16||n==20)&&(t=t+"-"),i=Math.floor(Math.random()*16).toString(16).toUpperCase(),t=t+i;return t};this.getFileName=function(n){var i="",r,t;if(!n)return"";if(!n.value&&n.name)i=n.name;else{if(!n.value&&typeof n!="string")throw"Invalid parameter. fullPath parameter must be a string of full path or file element.";n.value&&(n=n.value);n&&(r=n.indexOf("\\")>=0?n.lastIndexOf("\\"):n.lastIndexOf("/"),t=n.substring(r),(t.indexOf("\\")===0||t.indexOf("/")===0)&&(t=t.substring(1)),i=t)}return encodeURIComponent(i)};this.getFileType=function(n){if(!n)throw"file must defined or not null";if(!n.value&&n.name)return n.name.substring(n.name.lastIndexOf(".")+1);if(n.value&&(n=n.value),typeof n!="string")throw"can't resolve file type.";return n.substring(n.lastIndexOf(".")+1)};this.sizeToString=function(n){if(!n||n<=0)return"0 Kb";var t=Math.floor(Math.log(n)/Math.log(1024));return(n/Math.pow(1024,Math.floor(t))).toFixed(2)+" "+["bytes","kb","MB","GB","TB","PB"][t]};this.checkHtml5BrowserSupport=function(){return window.File&&window.FileReader&&window.FileList&&window.Blob&&(new XMLHttpRequest).upload}};Sys.Extended.UI.AjaxFileUpload.Item=function(n,t,i){this._deleteButton=null;this._parentId=n;this._inputElementValue=t.value;this._id=t.id;this._slices=t.slices;this._sliceIndex=0;this._fileInfoContainer=null;this._fileStatusText=null;this._isUploaded=!1;this._isUploading=!1;this._fileSize=0;this._fileName="";this._fileType="";this._bytesUploaded=0;this._ui=this.initUI(i)};Sys.Extended.UI.AjaxFileUpload.Item.prototype={initUI:function(n){var l=this,t=this._inputElementValue,e=new Sys.Extended.UI.AjaxFileUpload.Utils,a=e.checkHtml5BrowserSupport(),i=this._id,r=$common.createElementFromTemplate({nodeName:"div",properties:{id:this._parentId+"_FileItemContainer_"+i},cssClasses:["ajax__fileupload_fileItemInfo"]}),u=$common.createElementFromTemplate({nodeName:"div",properties:{id:this._parentId+"_FileInfoContainer_"+i,style:{display:"inline-block"}}}),o=$common.createElementFromTemplate({nodeName:"span",properties:{id:this._parentId+"_FileItemInfo_"+i},cssClasses:["ajax__fileupload_fileItemInfo"]}),h=$common.createElementFromTemplate({nodeName:"span",properties:{id:this._parentId+"_FileItemStatus_"+i},cssClasses:["uploadstatus"]}),f=$common.createElementFromTemplate({nodeName:"div",properties:{id:this._parentId+"_FileItemDeleteButton_"+i},cssClasses:["removeButton"]}),s,c;return this._fileName=e.getFileName(t),s=decodeURIComponent(this._fileName),a?(this._fileSize=t.size,c=t.type?'('+t.type+")<\/span>":"",o.innerHTML=''+s+"<\/span> "+c+' - '+e.sizeToString(t.size)+"<\/span> ",this._fileType=t.type):(o.innerHTML=''+s+"<\/span>",this._fileType=e.getFileType(t)),u.appendChild(o),u.appendChild(h),$common.setText(f,Sys.Extended.UI.Resources.AjaxFileUpload_Remove),$addHandlers(f,{click:Function.createDelegate(this,function(){n(l)})}),Sys.Browser.agent==Sys.Browser.InternetExplorer&&Sys.Browser.version<=8?(r.appendChild(f),r.appendChild(u)):(r.appendChild(u),r.appendChild(f)),this._fileInfoContainer=u,this._deleteButton=f,this._fileStatusText=h,r},setStatus:function(n,t){$common.setText(this._fileStatusText," ("+t+")");this._fileInfoContainer.setAttribute("class",n+"State")},disabled:function(n){this._deleteButton.disabled=n?"disabled":""},hide:function(){this._deleteButton.style.visibility="hidden"},destroy:function(){$common.removeElement(this._inputElementValue);$common.removeElement(this._deleteButton);$common.removeElement(this._ui)},get_inputElementValue:function(){return this._inputElementValue},appendNodeTo:function(n){n.appendChild(this._ui)},removeNodeFrom:function(n){n.removeChild(this._ui)}};Sys.Extended.UI.AjaxFileUpload.Processor=function(n,t){var r=new Sys.Extended.UI.AjaxFileUpload.Utils,i=new XMLHttpRequest;this._iframe=null;this._iframeName=n.get_id()+"_uploadIframe";this._form=null;this.initialize=function(){this.attachEvents();this.createIFrame();this.createForm()};this.attachEvents=function(){this.onFileSelected$delegate=Function.createDelegate(this,this.onFileSelectedHandler);this.attachFileInputEvents(t.inputFile,!0);var r=this;i.onreadystatechange=function(){if(i.readyState==4&&i.status==200){var t=i.responseText;t&&(t=parseFloat(t).toFixed(2),n.setPercent(t));t<100&&setTimeout(function(){r.pollingServerProgress(!0)},500)}}};this.attachFileInputEvents=function(n,t){t?$addHandlers(n,{change:this.onFileSelected$delegate}):$common.removeHandlers(n,{change:this.onFileSelected$delegate})};this.onFileSelectedHandler=function(){var i={id:r.generateGuid(),value:t.inputFile,type:r.getFileType(t.inputFile.value)};if(!n.fileTypeIsValid(i.type)){n.confirmFileIsInvalid(i);return}if(n.fileSizeExceeded(i.value.size)){n.confirmFileIsTooLarge(i);return}n.addFileToQueue(i);this.createInputFileElement()};this.createInputFileElement=function(){var i=t.inputFile,f,u;i.style.zIndex=-999;$common.setLocation(i,{x:-99999,y:-99999});this.attachFileInputEvents(i,!1);f=n.get_id()+"_file_"+r.generateGuid();u=$common.createElementFromTemplate({nodeName:"input",properties:{id:f,name:"act-file-data",type:"file",style:{zIndex:0,cursor:"pointer",position:"absolute"}}},i.parentNode);$common.setElementOpacity(u,0);this.attachFileInputEvents(u,!0);t.inputFile=u};this.startUpload=function(){var t=this._form,i=n.getNextFile(),r;if(!i){n._currentFileId=null;this.setThrobber(!1);n.done();return}for(n.setAsUploading(i),r=i.get_inputElementValue(),n._currentFileId=i._id,this.setThrobber(!0);t.firstChild;)t.removeChild(t.firstChild);r.name="act-file-data";t.appendChild(r);t.setAttribute("action",n._uploadUrl+"?contextKey="+n.get_contextKey()+"&controlID="+n.get_id()+"&fileId="+n._currentFileId+"&fileName="+i._fileName+"&usePoll="+(n.get_serverPollingSupport()?"true":"false"));t.submit()};this.cancelUpload=function(){var t=new XMLHttpRequest,r=this;i&&i.abort();t.open("POST","?contextKey="+n.get_contextKey()+"&controlID="+n.get_id()+"&cancel=1&guid="+n._currentFileId+r.getQueryString(),!0);t.onreadystatechange=function(){if(r.setThrobber(!1),t.readyState==4)if(t.status==200)n.cancelUpload();else{r.raiseUploadError(t);throw"Failed to cancel upload.";}};t.send(null)};this.getQueryString=function(){return"&"+window.location.search.replace("?","")};this.createIFrame=function(){var t=this._iframeName,n=document.createElement("IFRAME");n.width="0";n.height="0";n.style.display="none";n.src="about:blank";n.id=t;n.name=t;n.security="restricted";document.body.appendChild(n);n.contentWindow.name=t;$addHandlers(n,{load:Function.createDelegate(this,this.onIFrameLoadedHandler)});this._iframe=n};this.onIFrameLoadedHandler=function(t){if(n._currentFileId)try{var i=this._iframe,r=null;if(i.contentDocument?r=i.contentDocument:i.contentWindow?r=i.contentWindow.document:i.document&&(r=i.document),r==null)throw"Document not initialized";n.doneAndUploadNextFile(n.getCurrentFileItem())}catch(t){if(!n._canceled||!(t.message&&(t.message.indexOf("Access is denied")>-1||t.message.indexOf("Permission denied")>-1))){this.raiseUploadError(t);throw t;}}};this.setThrobber=function(i){if(n.get_serverPollingSupport()){n.setPercent(0);$common.setVisible(t.progressBar,i?!0:!1);$common.setVisible(t.progressBarContainer,i?!0:!1);this.pollingServerProgress(i);return}n.get_throbber()!=null&&(n.get_throbber().style.display=i?"":"none")};this.pollingServerProgress=function(t){t&&n._currentFileId&&(i.open("GET","?contextKey="+n.get_contextKey()+"&controlID="+n.get_id()+"&poll=1&guid="+n._currentFileId,!0),i.send(null))};this.createForm=function(){var t,i="___postForm"+n.get_id();try{t=document.createElement('
')}catch(r){t=document.createElement("form");t.setAttribute("id",i);t.setAttribute("method","post");t.setAttribute("target",this._iframe.id);t.setAttribute("enctype","multipart/form-data")}t.style.visibility="hidden";t.style.display="none";document.body.appendChild(t);this._form=t};this.raiseUploadError=function(t){n.raise_uploadError(t);i&&i.abort();n._currentFileId=null};this.resetUI=function(){n.setFileStatus(n._currentFileId,"error",Sys.Extended.UI.Resources.AjaxFileUpload_error)}};Sys.Extended.UI.AjaxFileUpload.ProcessorHtml5=function(n,t){var i=new Sys.Extended.UI.AjaxFileUpload.Utils,r=n.get_chunkSize()*1e3,u=0,f=null;this.initialize=function(){$common.setVisible(t.dropZone,!0);t.dropZone.innerHTML=Sys.Extended.UI.Resources.AjaxFileUpload_DropFiles;this.attachEvents()};this.attachEvents=function(){this.onFileDropped$delegate=Function.createDelegate(this,this.onFileDroppedHandler);this.onFileDragOver$delegate=Function.createDelegate(this,this.onFileDragOverHandler);this.onFileSelected$delegate=Function.createDelegate(this,this.onFileSelectedHandler);t.inputFile.addEventListener("change",this.onFileSelected$delegate,!1);t.dropZone.addEventListener("drop",this.onFileDropped$delegate,!1);t.dropZone.addEventListener("dragover",this.onFileDragOver$delegate,!1)};this.onFileDroppedHandler=function(n){n.stopPropagation();n.preventDefault();this.addFilesToQueue(n.dataTransfer.files)};this.onFileDragOverHandler=function(n){n.stopPropagation();n.preventDefault()};this.onFileSelectedHandler=function(n){this.addFilesToQueue(n.target.files);this.createInputFileElement()};this.createInputFileElement=function(){var u=t.inputFile,f,r;delete u;f=n.get_id()+"_file_"+i.generateGuid();r=$common.createElementFromTemplate({nodeName:"input",properties:{id:f,name:"act-file-data",type:"file",style:{zIndex:0,cursor:"pointer",position:"absolute"}}},u.parentNode);$common.setElementOpacity(r,0);this.attachFileInputEvents(r,!0);t.inputFile=r};this.attachFileInputEvents=function(n,t){t?$addHandlers(n,{change:this.onFileSelected$delegate}):$common.removeHandlers(n,{change:this.onFileSelected$delegate})};this.addFilesToQueue=function(u){for(var o,s,e,f=0;fr&&(s=Math.ceil(o.size/r)),e={id:i.generateGuid(),value:u[f],type:i.getFileType(u[f]),uploaded:!1,slices:s},!n.fileTypeIsValid(e.type)){n.confirmFileIsInvalid(e);continue}if(n.fileSizeExceeded(e.value.size)){n.confirmFileIsTooLarge(e);continue}if(!n.addFileToQueue(e))break}t.inputFile.value=null};this.cancelUpload=function(){f&&f.abort();n.cancelUpload()};this.startUpload=function(){var i=n.getNextFile();i?(i._sliceIndex===0&&n.setPercent(0),$common.setVisible(t.progressBarContainer,!0),this.upload(i)):(n._currentFileId=null,n.setPercent(0),$common.setVisible(t.progressBarContainer,!1),n.done())};this.resetUI=function(){$common.setVisible(t.progressBarContainer,!1);$common.setVisible(n._elements.uploadOrCancelButton,!1);var i=n.getNextFile();i._isUploaded=!0;i._isUploading=!1};this.upload=function(i){var o,s;if(n._isUploading){$common.setVisible(t.progressBar,!0);n.setAsUploading(i);var f=i.get_inputElementValue(),a=i._fileName,h=i._slices&&i._slices>0,v=i._sliceIndex==0;h&&(o=i._sliceIndex*r,s=o+r,f=f.slice(o,s>f.size?f.size:s));var c=new FormData,l=n._currentFileId=i._id,u=new XMLHttpRequest,y=this,e=function(n){return function(t){n.call(y,l,t)}};u.upload.addEventListener("progress",e(this.onProgressHandler),!1);u.addEventListener("load",e(this.onUploadCompleteHandler),!1);u.addEventListener("error",e(this.onUploadFailedHandler),!1);u.addEventListener("abort",e(this.onUploadCanceledHandler),!1);u.open("POST",(n.get_useAbsoluteHandlerPath()?"/":"")+n._uploadUrl+"?contextKey="+n.get_contextKey()+"&controlID="+n.get_id()+"&fileId="+l+"&fileName="+a+"&chunked="+(h?"true":"false")+"&firstChunk="+v,!0);c.append("act-file-data",f);u.send(c)}};this.onProgressHandler=function(t,i){if(n._isUploading&&i.lengthComputable){u=i.loaded;var r=n.getFileItem(t),f=r._slices,e=r._bytesUploaded+u,o=f-r._sliceIndex==1?e:i.total*f,s=f==0?(i.loaded*100/i.total).toFixed(2):(e/o*100).toFixed(2);n.setPercent(s)}};this.onUploadCompleteHandler=function(t){var e=this,r=n.getFileItem(t),f=r.get_inputElementValue();r._slices&&r._slices>0&&r._sliceIndex+10&&this._filesInQueue.length>=i?(alert(Sys.Extended.UI.Resources.AjaxFileUpload_MaxNumberOfFilesExceeded),!1):(t=new Sys.Extended.UI.AjaxFileUpload.Item(this.get_id(),n,Function.createDelegate(this,this.removeFileFromQueueHandler)),t.appendNodeTo(this._elements.queueContainer),t.setStatus("pending",Sys.Extended.UI.Resources.AjaxFileUpload_Pending),$common.setVisible(this._elements.queueContainer,!0),$common.setVisible(this._elements.uploadOrCancelButton,!0),this._filesInQueue.push(t),this._showFilesCount(),!0)},_showFilesCount:function(){var n=this._filesInQueue.length==0;this.setStatusMessage(n?Sys.Extended.UI.Resources.AjaxFileUpload_SelectFileToUpload:String.format(Sys.Extended.UI.Resources.AjaxFileUpload_FileInQueue,this._filesInQueue.length.toString()))},fileTypeIsValid:function(n){var i,t,r;if(!this._allowedFileTypes)return!0;for(i=this._allowedFileTypes.split(","),t=0;tthis.getMaxFileSizeInBytes()},confirmFileIsInvalid:function(n){var t=new Sys.Extended.UI.AjaxFileUpload.Utils;alert(String.format(Sys.Extended.UI.Resources.AjaxFileUpload_WrongFileType,t.getFileName(n.value),n.type))},confirmFileIsTooLarge:function(n){var t=new Sys.Extended.UI.AjaxFileUpload.Utils;alert(String.format(Sys.Extended.UI.Resources.AjaxFileUpload_TooLargeFile,t.getFileName(n.value),this.get_maxFileSize()))},getMaxFileSizeInBytes:function(){return this.get_maxFileSize()*1024},doneAndUploadNextFile:function(n){var t=new XMLHttpRequest,i=this;t.open("POST","?contextKey="+this.get_contextKey()+"&controlID="+this.get_id()+"&done=1&guid="+n._id+this.getQueryString(),!0);t.onreadystatechange=function(){if(t.readyState==4)if(t.status==200&&t.responseText!="")i.raise_uploadComplete(Sys.Serialization.JavaScriptSerializer.deserialize(t.responseText)),i._processor.startUpload();else{i.setFileStatus(n,"error",Sys.Extended.UI.Resources.AjaxFileUpload_error);i.raise_uploadError(t);throw"error raising upload complete event and start new upload";}};t.send()},getQueryString:function(){return"&"+window.location.search.replace("?","")},cancelUpload:function(){var i=this.getCurrentFileItem(),n,t;for(i._isUploaded=!1,i._isUploading=!1,this.setStatusMessage(Sys.Extended.UI.Resources.AjaxFileUpload_UploadCanceled),n=0;n=100&&(n="100");t.style.width=n+"%";$common.setText(t,String.format(Sys.Extended.UI.Resources.AjaxFileUpload_UploadedPercentage,n))},get_allowedFileTypes:function(){return this._allowedFileTypes},set_allowedFileTypes:function(n){this._allowedFileTypes=n},get_contextKey:function(){return this._contextKey},set_contextKey:function(n){this._contextKey=n},get_postBackUrl:function(){return this._postBackUrl},set_postBackUrl:function(n){this._postBackUrl=n},get_mode:function(){return this._mode},set_mode:function(n){this._mode=n},get_serverPollingSupport:function(){return this._serverPollingSupport},set_serverPollingSupport:function(n){this._serverPollingSupport=n},get_throbber:function(){return this._throbber},set_throbber:function(n){this._throbber=n},get_maximumNumberOfFiles:function(){return this._maximumNumberOfFiles},set_maximumNumberOfFiles:function(n){this._maximumNumberOfFiles=n},get_chunkSize:function(){return this._chunkSize},set_chunkSize:function(n){this._chunkSize=n},get_clearFileListAfterUpload:function(){return this._clearFileListAfterUpload},set_clearFileListAfterUpload:function(n){this._clearFileListAfterUpload=n},get_useAbsoluteHandlerPath:function(){return this._useAbsoluteHandlerPath},set_useAbsoluteHandlerPath:function(n){this._useAbsoluteHandlerPath=n},get_maxFileSize:function(){return this._maxFileSize},set_maxFileSize:function(n){this._maxFileSize=n},add_uploadStart:function(n){this.get_events().addHandler("uploadStart",n)},remove_uploadStart:function(n){this.get_events().removeHandler("uploadStart",n)},raiseUploadStart:function(n){Sys.Extended.Deprecated("raiseUploadStart(e)","raise_uploadStart(e)");this.raise_uploadStart(n)},raise_uploadStart:function(n){var t=this.get_events().getHandler("uploadStart"),i;t&&(i=new Sys.Extended.UI.AjaxFileUploadStartEventArgs(n.FilesInQueue,n.ServerArguments),t(this,i))},add_uploadComplete:function(n){this.get_events().addHandler("uploadComplete",n)},remove_uploadComplete:function(n){this.get_events().removeHandler("uploadComplete",n)},raiseUploadComplete:function(n){Sys.Extended.Deprecated("raiseUploadComplete(e)","raise_uploadComplete(e)");this.raise_uploadComplete(n)},raise_uploadComplete:function(n){var t=this.getCurrentFileItem(),i,r,u;if(!t||!n||n.FileId!==t._id)throw"Invalid finalizing upload server response.";this.setFileStatus(t,"uploaded",Sys.Extended.UI.Resources.AjaxFileUpload_Uploaded);this.setStatusMessage("Uploaded "+this._currentQueueIndex+" of "+this._filesInQueue.length+" file(s)");t._isUploaded=!0;t._isUploading=!1;t.hide();i=this.get_events().getHandler("uploadComplete");i&&(r=Array.indexOf(this._filesInQueue,t),u=new Sys.Extended.UI.AjaxFileUploadEventArgs(n.FileId,n.StatusMessage,n.FileName,n.FileSize,n.ContentType,n.PostedUrl,r,this._filesInQueue.length),i(this,u))},add_uploadCompleteAll:function(n){this.get_events().addHandler("uploadCompleteAll",n)},remove_uploadCompleteAll:function(n){this.get_events().removeHandler("uploadCompleteAll",n)},raiseUploadCompleteAll:function(){Sys.Extended.Deprecated("raiseUploadCompleteAll(e)","raise_uploadCompleteAll(e)");this.raise_uploadCompleteAll("raiseUploadCompleteAll(e)","raise_uploadCompleteAll(e)")},raise_uploadCompleteAll:function(n){var t=this.get_events().getHandler("uploadCompleteAll"),i;t&&(i=new Sys.Extended.UI.AjaxFileUploadCompleteAllEventArgs(n.FilesInQueue,n.FilesUploaded,n.Reason,n.ServerArguments),t(this,i))},add_uploadError:function(n){this.get_events().addHandler("uploadError",n)},remove_uploadError:function(n){this.get_events().removeHandler("uploadError",n)},raiseUploadError:function(n){Sys.Extended.Deprecated("raiseUploadError(e)","raise_uploadError(e)");this.raise_uploadError(n)},raise_uploadError:function(n){var t=this.get_events().getHandler("uploadError");t&&t(this,n);this._processor.resetUI();this._canceled=!1;this._isUploading=!1;this._isUploaded=!0;this.enableControls(!0)},getCurrentFileItem:function(){return this.getFileItem(this._currentFileId)},getNextFile:function(){var n,t;if(!this._isUploading)return null;for(n=0;n=0?n.lastIndexOf("\\"):n.lastIndexOf("/"),t=n.substring(r),(t.indexOf("\\")===0||t.indexOf("/")===0)&&(t=t.substring(1)),i=t)}return encodeURIComponent(i)};this.getFileType=function(n){if(!n)throw"file must defined or not null";if(!n.value&&n.name)return n.name.substring(n.name.lastIndexOf(".")+1);if(n.value&&(n=n.value),typeof n!="string")throw"can't resolve file type.";return n.substring(n.lastIndexOf(".")+1)};this.sizeToString=function(n){if(!n||n<=0)return"0 Kb";var t=Math.floor(Math.log(n)/Math.log(1024));return(n/Math.pow(1024,Math.floor(t))).toFixed(2)+" "+["bytes","kb","MB","GB","TB","PB"][t]};this.checkHtml5BrowserSupport=function(){return window.File&&window.FileReader&&window.FileList&&window.Blob&&(new XMLHttpRequest).upload}};Sys.Extended.UI.AjaxFileUpload.Item=function(n,t,i){this._deleteButton=null;this._parentId=n;this._inputElementValue=t.value;this._id=t.id;this._slices=t.slices;this._sliceIndex=0;this._fileInfoContainer=null;this._fileStatusText=null;this._isUploaded=!1;this._isUploading=!1;this._fileSize=0;this._fileName="";this._fileType="";this._bytesUploaded=0;this._ui=this.initUI(i)};Sys.Extended.UI.AjaxFileUpload.Item.prototype={initUI:function(n){var l=this,t=this._inputElementValue,e=new Sys.Extended.UI.AjaxFileUpload.Utils,a=e.checkHtml5BrowserSupport(),i=this._id,r=$common.createElementFromTemplate({nodeName:"div",properties:{id:this._parentId+"_FileItemContainer_"+i},cssClasses:["ajax__fileupload_fileItemInfo"]}),u=$common.createElementFromTemplate({nodeName:"div",properties:{id:this._parentId+"_FileInfoContainer_"+i,style:{display:"inline-block"}}}),o=$common.createElementFromTemplate({nodeName:"span",properties:{id:this._parentId+"_FileItemInfo_"+i},cssClasses:["ajax__fileupload_fileItemInfo"]}),h=$common.createElementFromTemplate({nodeName:"span",properties:{id:this._parentId+"_FileItemStatus_"+i},cssClasses:["uploadstatus"]}),f=$common.createElementFromTemplate({nodeName:"div",properties:{id:this._parentId+"_FileItemDeleteButton_"+i},cssClasses:["removeButton"]}),s,c;return this._fileName=e.getFileName(t),s=decodeURIComponent(this._fileName),a?(this._fileSize=t.size,c=t.type?'('+t.type+")<\/span>":"",o.innerHTML=''+s+"<\/span> "+c+' - '+e.sizeToString(t.size)+"<\/span> ",this._fileType=t.type):(o.innerHTML=''+s+"<\/span>",this._fileType=e.getFileType(t)),u.appendChild(o),u.appendChild(h),$common.setText(f,Sys.Extended.UI.Resources.AjaxFileUpload_Remove),$addHandlers(f,{click:Function.createDelegate(this,function(){n(l)})}),Sys.Browser.agent==Sys.Browser.InternetExplorer&&Sys.Browser.version<=8?(r.appendChild(f),r.appendChild(u)):(r.appendChild(u),r.appendChild(f)),this._fileInfoContainer=u,this._deleteButton=f,this._fileStatusText=h,r},setStatus:function(n,t){$common.setText(this._fileStatusText," ("+t+")");this._fileInfoContainer.setAttribute("class",n+"State")},disabled:function(n){this._deleteButton.disabled=n?"disabled":""},hide:function(){this._deleteButton.style.visibility="hidden"},destroy:function(){$common.removeElement(this._inputElementValue);$common.removeElement(this._deleteButton);$common.removeElement(this._ui)},get_inputElementValue:function(){return this._inputElementValue},appendNodeTo:function(n){n.appendChild(this._ui)},removeNodeFrom:function(n){n.removeChild(this._ui)}};Sys.Extended.UI.AjaxFileUpload.Processor=function(n,t){var r=new Sys.Extended.UI.AjaxFileUpload.Utils,i=new XMLHttpRequest;this._iframe=null;this._iframeName=n.get_id()+"_uploadIframe";this._form=null;this.initialize=function(){this.attachEvents();this.createIFrame();this.createForm()};this.attachEvents=function(){this.onFileSelected$delegate=Function.createDelegate(this,this.onFileSelectedHandler);this.attachFileInputEvents(t.inputFile,!0);var r=this;i.onreadystatechange=function(){if(i.readyState==4&&i.status==200){var t=i.responseText;t&&(t=parseFloat(t).toFixed(2),n.setPercent(t));t<100&&setTimeout(function(){r.pollingServerProgress(!0)},500)}}};this.attachFileInputEvents=function(n,t){t?$addHandlers(n,{change:this.onFileSelected$delegate}):$common.removeHandlers(n,{change:this.onFileSelected$delegate})};this.onFileSelectedHandler=function(){var i={id:r.generateGuid(),value:t.inputFile,type:r.getFileType(t.inputFile.value)};if(!n.fileTypeIsValid(i.type)){n.confirmFileIsInvalid(i);return}if(n.fileSizeExceeded(i.value.size)){n.confirmFileIsTooLarge(i);return}n.addFileToQueue(i);this.createInputFileElement()};this.createInputFileElement=function(){var i=t.inputFile,f,u;i.style.zIndex=-999;$common.setLocation(i,{x:-99999,y:-99999});this.attachFileInputEvents(i,!1);f=n.get_id()+"_file_"+r.generateGuid();u=$common.createElementFromTemplate({nodeName:"input",properties:{id:f,name:"act-file-data",type:"file",style:{zIndex:0,cursor:"pointer",position:"absolute"}}},i.parentNode);$common.setElementOpacity(u,0);this.attachFileInputEvents(u,!0);t.inputFile=u};this.startUpload=function(){var t=this._form,i=n.getNextFile(),r;if(!i){n._currentFileId=null;this.setThrobber(!1);n.done();return}for(n.setAsUploading(i),r=i.get_inputElementValue(),n._currentFileId=i._id,this.setThrobber(!0);t.firstChild;)t.removeChild(t.firstChild);r.name="act-file-data";t.appendChild(r);t.setAttribute("action",n._uploadUrl+"?contextKey="+n.get_contextKey()+"&controlID="+n.get_id()+"&fileId="+n._currentFileId+"&fileName="+i._fileName+"&usePoll="+(n.get_serverPollingSupport()?"true":"false"));t.submit()};this.cancelUpload=function(){var t=new XMLHttpRequest,r=this;i&&i.abort();t.open("POST","?contextKey="+n.get_contextKey()+"&controlID="+n.get_id()+"&cancel=1&guid="+n._currentFileId+r.getQueryString(),!0);t.onreadystatechange=function(){if(r.setThrobber(!1),t.readyState==4)if(t.status==200)n.cancelUpload();else{r.raiseUploadError(t);throw"Failed to cancel upload.";}};t.send(null)};this.getQueryString=function(){return"&"+window.location.search.replace("?","")};this.createIFrame=function(){var t=this._iframeName,n=document.createElement("IFRAME");n.width="0";n.height="0";n.style.display="none";n.src="about:blank";n.id=t;n.name=t;n.security="restricted";document.body.appendChild(n);n.contentWindow.name=t;$addHandlers(n,{load:Function.createDelegate(this,this.onIFrameLoadedHandler)});this._iframe=n};this.onIFrameLoadedHandler=function(t){if(n._currentFileId)try{var i=this._iframe,r=null;if(i.contentDocument?r=i.contentDocument:i.contentWindow?r=i.contentWindow.document:i.document&&(r=i.document),r==null)throw"Document not initialized";n.doneAndUploadNextFile(n.getCurrentFileItem())}catch(t){if(!n._canceled||!(t.message&&(t.message.indexOf("Access is denied")>-1||t.message.indexOf("Permission denied")>-1))){this.raiseUploadError(t);throw t;}}};this.setThrobber=function(i){if(n.get_serverPollingSupport()){n.setPercent(0);$common.setVisible(t.progressBar,i?!0:!1);$common.setVisible(t.progressBarContainer,i?!0:!1);this.pollingServerProgress(i);return}n.get_throbber()!=null&&(n.get_throbber().style.display=i?"":"none")};this.pollingServerProgress=function(t){t&&n._currentFileId&&(i.open("GET","?contextKey="+n.get_contextKey()+"&controlID="+n.get_id()+"&poll=1&guid="+n._currentFileId,!0),i.send(null))};this.createForm=function(){var t,i="___postForm"+n.get_id();try{t=document.createElement('')}catch(r){t=document.createElement("form");t.setAttribute("id",i);t.setAttribute("method","post");t.setAttribute("target",this._iframe.id);t.setAttribute("enctype","multipart/form-data")}t.style.visibility="hidden";t.style.display="none";document.body.appendChild(t);this._form=t};this.raiseUploadError=function(t){n.raise_uploadError(t);i&&i.abort();n._currentFileId=null};this.resetUI=function(){n.setFileStatus(n._currentFileId,"error",Sys.Extended.UI.Resources.AjaxFileUpload_error)}};Sys.Extended.UI.AjaxFileUpload.ProcessorHtml5=function(n,t){var i=new Sys.Extended.UI.AjaxFileUpload.Utils,r=n.get_chunkSize()*1e3,u=0,f=null;this.initialize=function(){$common.setVisible(t.dropZone,!0);t.dropZone.innerHTML=Sys.Extended.UI.Resources.AjaxFileUpload_DropFiles;this.attachEvents()};this.attachEvents=function(){this.onFileDropped$delegate=Function.createDelegate(this,this.onFileDroppedHandler);this.onFileDragOver$delegate=Function.createDelegate(this,this.onFileDragOverHandler);this.onFileSelected$delegate=Function.createDelegate(this,this.onFileSelectedHandler);t.inputFile.addEventListener("change",this.onFileSelected$delegate,!1);t.dropZone.addEventListener("drop",this.onFileDropped$delegate,!1);t.dropZone.addEventListener("dragover",this.onFileDragOver$delegate,!1)};this.onFileDroppedHandler=function(t){t.stopPropagation();t.preventDefault();this.addFilesToQueue(t.dataTransfer.files);n.get_autoStartUpload()&&n.startUpload()};this.onFileDragOverHandler=function(n){n.stopPropagation();n.preventDefault()};this.onFileSelectedHandler=function(t){this.addFilesToQueue(t.target.files);this.createInputFileElement();n.get_autoStartUpload()&&n.startUpload()};this.createInputFileElement=function(){var u=t.inputFile,f,r;delete u;f=n.get_id()+"_file_"+i.generateGuid();r=$common.createElementFromTemplate({nodeName:"input",properties:{id:f,name:"act-file-data",type:"file",style:{zIndex:0,cursor:"pointer",position:"absolute"}}},u.parentNode);$common.setElementOpacity(r,0);this.attachFileInputEvents(r,!0);t.inputFile=r};this.attachFileInputEvents=function(n,t){t?$addHandlers(n,{change:this.onFileSelected$delegate}):$common.removeHandlers(n,{change:this.onFileSelected$delegate})};this.addFilesToQueue=function(u){for(var o,s,e,f=0;fr&&(s=Math.ceil(o.size/r)),e={id:i.generateGuid(),value:u[f],type:i.getFileType(u[f]),uploaded:!1,slices:s},!n.fileTypeIsValid(e.type)){n.confirmFileIsInvalid(e);continue}if(n.fileSizeExceeded(e.value.size)){n.confirmFileIsTooLarge(e);continue}if(!n.addFileToQueue(e))break}t.inputFile.value=null};this.cancelUpload=function(){f&&f.abort();n.cancelUpload()};this.startUpload=function(){var i=n.getNextFile();i?(i._sliceIndex===0&&n.setPercent(0),$common.setVisible(t.progressBarContainer,!0),this.upload(i)):(n._currentFileId=null,n.setPercent(0),$common.setVisible(t.progressBarContainer,!1),n.done())};this.resetUI=function(){$common.setVisible(t.progressBarContainer,!1);$common.setVisible(n._elements.uploadOrCancelButton,!1);var i=n.getNextFile();i._isUploaded=!0;i._isUploading=!1};this.upload=function(i){var o,s;if(n._isUploading){$common.setVisible(t.progressBar,!0);n.setAsUploading(i);var f=i.get_inputElementValue(),a=i._fileName,h=i._slices&&i._slices>0,v=i._sliceIndex==0;h&&(o=i._sliceIndex*r,s=o+r,f=f.slice(o,s>f.size?f.size:s));var c=new FormData,l=n._currentFileId=i._id,u=new XMLHttpRequest,y=this,e=function(n){return function(t){n.call(y,l,t)}};u.upload.addEventListener("progress",e(this.onProgressHandler),!1);u.addEventListener("load",e(this.onUploadCompleteHandler),!1);u.addEventListener("error",e(this.onUploadFailedHandler),!1);u.addEventListener("abort",e(this.onUploadCanceledHandler),!1);u.open("POST",(n.get_useAbsoluteHandlerPath()?"/":"")+n._uploadUrl+"?contextKey="+n.get_contextKey()+"&controlID="+n.get_id()+"&fileId="+l+"&fileName="+a+"&chunked="+(h?"true":"false")+"&firstChunk="+v,!0);c.append("act-file-data",f);u.send(c)}};this.onProgressHandler=function(t,i){if(n._isUploading&&i.lengthComputable){u=i.loaded;var r=n.getFileItem(t),f=r._slices,e=r._bytesUploaded+u,o=f-r._sliceIndex==1?e:i.total*f,s=f==0?(i.loaded*100/i.total).toFixed(2):(e/o*100).toFixed(2);n.setPercent(s)}};this.onUploadCompleteHandler=function(t){var e=this,r=n.getFileItem(t),f=r.get_inputElementValue();r._slices&&r._slices>0&&r._sliceIndex+10&&this._filesInQueue.length>=i?(alert(Sys.Extended.UI.Resources.AjaxFileUpload_MaxNumberOfFilesExceeded),!1):(t=new Sys.Extended.UI.AjaxFileUpload.Item(this.get_id(),n,Function.createDelegate(this,this.removeFileFromQueueHandler)),t.appendNodeTo(this._elements.queueContainer),t.setStatus("pending",Sys.Extended.UI.Resources.AjaxFileUpload_Pending),$common.setVisible(this._elements.queueContainer,!0),$common.setVisible(this._elements.uploadOrCancelButton,!0),this._filesInQueue.push(t),this._showFilesCount(),!0)},_showFilesCount:function(){var n=this._filesInQueue.length==0;this.setStatusMessage(n?Sys.Extended.UI.Resources.AjaxFileUpload_SelectFileToUpload:String.format(Sys.Extended.UI.Resources.AjaxFileUpload_FileInQueue,this._filesInQueue.length.toString()))},fileTypeIsValid:function(n){var i,t,r;if(!this._allowedFileTypes)return!0;for(i=this._allowedFileTypes.split(","),t=0;tthis.getMaxFileSizeInBytes()},confirmFileIsInvalid:function(n){var t=new Sys.Extended.UI.AjaxFileUpload.Utils;alert(String.format(Sys.Extended.UI.Resources.AjaxFileUpload_WrongFileType,t.getFileName(n.value),n.type))},confirmFileIsTooLarge:function(n){var t=new Sys.Extended.UI.AjaxFileUpload.Utils;alert(String.format(Sys.Extended.UI.Resources.AjaxFileUpload_TooLargeFile,t.getFileName(n.value),this.get_maxFileSize()))},getMaxFileSizeInBytes:function(){return this.get_maxFileSize()*1024},doneAndUploadNextFile:function(n){var t=new XMLHttpRequest,i=this;t.open("POST","?contextKey="+this.get_contextKey()+"&controlID="+this.get_id()+"&done=1&guid="+n._id+this.getQueryString(),!0);t.onreadystatechange=function(){if(t.readyState==4)if(t.status==200&&t.responseText!="")i.raise_uploadComplete(Sys.Serialization.JavaScriptSerializer.deserialize(t.responseText)),i._processor.startUpload();else{i.setFileStatus(n,"error",Sys.Extended.UI.Resources.AjaxFileUpload_error);i.raise_uploadError(t);throw"error raising upload complete event and start new upload";}};t.send()},getQueryString:function(){return"&"+window.location.search.replace("?","")},cancelUpload:function(){var i=this.getCurrentFileItem(),n,t;for(i._isUploaded=!1,i._isUploading=!1,this.setStatusMessage(Sys.Extended.UI.Resources.AjaxFileUpload_UploadCanceled),n=0;n=100&&(n="100");t.style.width=n+"%";$common.setText(t,String.format(Sys.Extended.UI.Resources.AjaxFileUpload_UploadedPercentage,n))},get_allowedFileTypes:function(){return this._allowedFileTypes},set_allowedFileTypes:function(n){this._allowedFileTypes=n},get_contextKey:function(){return this._contextKey},set_contextKey:function(n){this._contextKey=n},get_postBackUrl:function(){return this._postBackUrl},set_postBackUrl:function(n){this._postBackUrl=n},get_mode:function(){return this._mode},set_mode:function(n){this._mode=n},get_autoStartUpload:function(){return this._autoStartUpload},set_autoStartUpload:function(n){this._autoStartUpload=n},get_serverPollingSupport:function(){return this._serverPollingSupport},set_serverPollingSupport:function(n){this._serverPollingSupport=n},get_throbber:function(){return this._throbber},set_throbber:function(n){this._throbber=n},get_maximumNumberOfFiles:function(){return this._maximumNumberOfFiles},set_maximumNumberOfFiles:function(n){this._maximumNumberOfFiles=n},get_chunkSize:function(){return this._chunkSize},set_chunkSize:function(n){this._chunkSize=n},get_clearFileListAfterUpload:function(){return this._clearFileListAfterUpload},set_clearFileListAfterUpload:function(n){this._clearFileListAfterUpload=n},get_useAbsoluteHandlerPath:function(){return this._useAbsoluteHandlerPath},set_useAbsoluteHandlerPath:function(n){this._useAbsoluteHandlerPath=n},get_maxFileSize:function(){return this._maxFileSize},set_maxFileSize:function(n){this._maxFileSize=n},add_uploadStart:function(n){this.get_events().addHandler("uploadStart",n)},remove_uploadStart:function(n){this.get_events().removeHandler("uploadStart",n)},raiseUploadStart:function(n){Sys.Extended.Deprecated("raiseUploadStart(e)","raise_uploadStart(e)");this.raise_uploadStart(n)},raise_uploadStart:function(n){var t=this.get_events().getHandler("uploadStart"),i;t&&(i=new Sys.Extended.UI.AjaxFileUploadStartEventArgs(n.FilesInQueue,n.ServerArguments),t(this,i))},add_uploadComplete:function(n){this.get_events().addHandler("uploadComplete",n)},remove_uploadComplete:function(n){this.get_events().removeHandler("uploadComplete",n)},raiseUploadComplete:function(n){Sys.Extended.Deprecated("raiseUploadComplete(e)","raise_uploadComplete(e)");this.raise_uploadComplete(n)},raise_uploadComplete:function(n){var t=this.getCurrentFileItem(),i,r,u;if(!t||!n||n.FileId!==t._id)throw"Invalid finalizing upload server response.";this.setFileStatus(t,"uploaded",Sys.Extended.UI.Resources.AjaxFileUpload_Uploaded);this.setStatusMessage("Uploaded "+this._currentQueueIndex+" of "+this._filesInQueue.length+" file(s)");t._isUploaded=!0;t._isUploading=!1;t.hide();i=this.get_events().getHandler("uploadComplete");i&&(r=Array.indexOf(this._filesInQueue,t),u=new Sys.Extended.UI.AjaxFileUploadEventArgs(n.FileId,n.StatusMessage,n.FileName,n.FileSize,n.ContentType,n.PostedUrl,r,this._filesInQueue.length),i(this,u))},add_uploadCompleteAll:function(n){this.get_events().addHandler("uploadCompleteAll",n)},remove_uploadCompleteAll:function(n){this.get_events().removeHandler("uploadCompleteAll",n)},raiseUploadCompleteAll:function(){Sys.Extended.Deprecated("raiseUploadCompleteAll(e)","raise_uploadCompleteAll(e)");this.raise_uploadCompleteAll("raiseUploadCompleteAll(e)","raise_uploadCompleteAll(e)")},raise_uploadCompleteAll:function(n){var t=this.get_events().getHandler("uploadCompleteAll"),i;t&&(i=new Sys.Extended.UI.AjaxFileUploadCompleteAllEventArgs(n.FilesInQueue,n.FilesUploaded,n.Reason,n.ServerArguments),t(this,i))},add_uploadError:function(n){this.get_events().addHandler("uploadError",n)},remove_uploadError:function(n){this.get_events().removeHandler("uploadError",n)},raiseUploadError:function(n){Sys.Extended.Deprecated("raiseUploadError(e)","raise_uploadError(e)");this.raise_uploadError(n)},raise_uploadError:function(n){var t=this.get_events().getHandler("uploadError");t&&t(this,n);this._processor.resetUI();this._canceled=!1;this._isUploading=!1;this._isUploaded=!0;this.enableControls(!0)},getCurrentFileItem:function(){return this.getFileItem(this._currentFileId)},getNextFile:function(){var n,t;if(!this._isUploading)return null;for(n=0;n