From 4e8bd8c1435a363e022f6d61135d5fd37f406580 Mon Sep 17 00:00:00 2001 From: Moshe Alfih Date: Wed, 13 Oct 2021 14:27:51 -0400 Subject: [PATCH] Resolves #414 --- AjaxControlToolkit/Scripts/AjaxFileUpload.js | 14 +++++++------- AjaxControlToolkit/Scripts/AjaxFileUpload.min.js | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/AjaxControlToolkit/Scripts/AjaxFileUpload.js b/AjaxControlToolkit/Scripts/AjaxFileUpload.js index f59e51cfe..6d23d4519 100644 --- a/AjaxControlToolkit/Scripts/AjaxFileUpload.js +++ b/AjaxControlToolkit/Scripts/AjaxFileUpload.js @@ -388,7 +388,7 @@ Sys.Extended.UI.AjaxFileUpload.Processor = function(control, elements) { // only add 1 file input element to be uploaded form.appendChild(inputElement); form.setAttribute("action", control.get_uploadHandlerPath() - + '?contextKey=' + control.get_contextKey() + + '?contextKey=' + encodeURIComponent(control.get_contextKey()) + '&controlID=' + control.get_id() + '&fileId=' + control._currentFileId + '&fileName=' + encodeURIComponent(fileItem._fileName) @@ -408,7 +408,7 @@ Sys.Extended.UI.AjaxFileUpload.Processor = function(control, elements) { xhrPoll.abort(); xhr.open("POST", - '?contextKey=' + control.get_contextKey() + '?contextKey=' + encodeURIComponent(control.get_contextKey()) + '&controlID=' + control.get_id() + '&cancel=1&guid=' + control._currentFileId + self.getQueryString(), true); @@ -514,7 +514,7 @@ Sys.Extended.UI.AjaxFileUpload.Processor = function(control, elements) { return; xhrPoll.open("GET", - '?contextKey=' + control.get_contextKey() + '?contextKey=' + encodeURIComponent(control.get_contextKey()) + '&controlID=' + control.get_id() + '&poll=1&guid=' + control._currentFileId, true); xhrPoll.send(null); @@ -765,7 +765,7 @@ Sys.Extended.UI.AjaxFileUpload.ProcessorHtml5 = function(control, elements) { xhrReq.addEventListener("abort", xhrDelegate(this.onUploadCanceledHandler), false); xhrReq.open("POST", control.get_uploadHandlerPath() - + '?contextKey=' + control.get_contextKey() + + '?contextKey=' + encodeURIComponent(control.get_contextKey()) + '&controlID=' + control.get_id() + '&fileId=' + id + '&fileName=' + encodeURIComponent(fileItem._fileName) @@ -1198,7 +1198,7 @@ Sys.Extended.UI.AjaxFileUpload.Control.prototype = { self = this; xhr.open("POST", - '?contextKey=' + this.get_contextKey() + '?contextKey=' + encodeURIComponent(this.get_contextKey()) + '&controlID=' + this.get_id() + '&start=1&queue=' + this._filesInQueue.length + this.getQueryString()); @@ -1290,7 +1290,7 @@ Sys.Extended.UI.AjaxFileUpload.Control.prototype = { currentFile = this._filesInQueue[this._currentQueueIndex - 1]; xhr.open("POST", - '?contextKey=' + this.get_contextKey() + '?contextKey=' + encodeURIComponent(this.get_contextKey()) + '&controlID=' + this.get_id() + '&complete=1&queue=' + this._filesInQueue.length + '&uploaded=' + (this._currentQueueIndex - (currentFile._isUploaded ? 0 : 1)) @@ -1466,7 +1466,7 @@ Sys.Extended.UI.AjaxFileUpload.Control.prototype = { self = this; xhr.open("POST", - '?contextKey=' + this.get_contextKey() + '?contextKey=' + encodeURIComponent(this.get_contextKey()) + '&controlID=' + this.get_id() + '&done=1&guid=' + fileItem._id + this.getQueryString(), true); diff --git a/AjaxControlToolkit/Scripts/AjaxFileUpload.min.js b/AjaxControlToolkit/Scripts/AjaxFileUpload.min.js index 2d6f3cb3b..b72f821e5 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(){function e(e){var t=e.lastIndexOf(".")+1;return t?e.substring(t):""}this.generateGuid=function(){var e,t,i;for(e="",i=0;i<32;i++)8!=i&&12!=i&&16!=i&&20!=i||(e+="-"),t=Math.floor(16*Math.random()).toString(16).toUpperCase(),e+=t;return e},this.getFileName=function(e){var t="";if(!e)return"";if(!e.value&&e.name)t=e.name;else{if(!e.value&&"string"!=typeof e)throw"Invalid parameter. fullPath parameter must be a string of full path or file element.";if(e.value&&(e=e.value),e){var i=e.indexOf("\\")>=0?e.lastIndexOf("\\"):e.lastIndexOf("/"),n=e.substring(i);0!==n.indexOf("\\")&&0!==n.indexOf("/")||(n=n.substring(1)),t=n}}return t},this.getFileType=function(t){if(!t)throw"file must defined or not null";if(!t.value&&t.name)return e(t.name);if(t.value&&(t=t.value),"string"!=typeof t)throw"can't resolve file type.";return e(t)},this.sizeToString=function(e){if(!e||e<=0)return"0 Kb";var t=["bytes","kb","MB","GB","TB","PB"],i=Math.floor(Math.log(e)/Math.log(1024));return(e/Math.pow(1024,Math.floor(i))).toFixed(2)+" "+t[i]},this.checkHtml5BrowserSupport=function(){return window.File&&window.FileReader&&window.FileList&&window.Blob&&(new XMLHttpRequest).upload}},Sys.Extended.UI.AjaxFileUpload.Item=function(e,t,i){this._deleteButton=null,this._parentId=e,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(e){var t=this,i=this._inputElementValue,n=new Sys.Extended.UI.AjaxFileUpload.Utils,l=n.checkHtml5BrowserSupport(),s=this._id,o=$common.createElementFromTemplate({nodeName:"div",properties:{id:this._parentId+"_FileItemContainer_"+s},cssClasses:["ajax__fileupload_fileItemInfo"]}),a=$common.createElementFromTemplate({nodeName:"div",properties:{id:this._parentId+"_FileInfoContainer_"+s,style:{display:"inline-block"}}}),r=$common.createElementFromTemplate({nodeName:"span",properties:{id:this._parentId+"_FileItemInfo_"+s},cssClasses:["ajax__fileupload_fileItemInfo"]}),d=$common.createElementFromTemplate({nodeName:"span",properties:{id:this._parentId+"_FileItemStatus_"+s},cssClasses:["uploadstatus"]}),u=$common.createElementFromTemplate({nodeName:"div",properties:{id:this._parentId+"_FileItemDeleteButton_"+s},cssClasses:["removeButton"]});this._fileName=n.getFileName(i);var p=Sys.Extended.UI.htmlEncode;if(l){this._fileSize=i.size;var c=i.type?'('+p(i.type)+")":"";r.innerHTML=''+p(this._fileName)+" "+c+' - '+n.sizeToString(i.size)+" ",this._fileType=i.type}else r.innerHTML=''+p(this._fileName)+"",this._fileType=n.getFileType(i);return a.appendChild(r),a.appendChild(d),$common.setText(u,Sys.Extended.UI.Resources.AjaxFileUpload_Remove),$addHandlers(u,{click:Function.createDelegate(this,function(){e(t)})}),Sys.Browser.agent==Sys.Browser.InternetExplorer&&Sys.Browser.version<=8?(o.appendChild(u),o.appendChild(a)):(o.appendChild(a),o.appendChild(u)),this._fileInfoContainer=a,this._deleteButton=u,this._fileStatusText=d,o},setStatus:function(e,t){$common.setText(this._fileStatusText," ("+t+")"),this._fileInfoContainer.setAttribute("class",e+"State")},disabled:function(e){e?this._deleteButton.disabled="disabled":this._deleteButton.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(e){e.appendChild(this._ui)},removeNodeFrom:function(e){e.removeChild(this._ui)}},Sys.Extended.UI.AjaxFileUpload.Processor=function(e,t){var i=new Sys.Extended.UI.AjaxFileUpload.Utils,n=new XMLHttpRequest;this._iframe=null,this._iframeName=e.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 i=this;n.onreadystatechange=function(t){if(4==n.readyState&&200==n.status){var l=n.responseText;l&&(l=parseFloat(l).toFixed(2),e.setPercent(l)),l<100&&setTimeout(function(){i.pollingServerProgress(!0)},500)}}},this.attachFileInputEvents=function(e,t){t?$addHandlers(e,{change:this.onFileSelected$delegate}):$common.removeHandlers(e,{change:this.onFileSelected$delegate})},this.onFileSelectedHandler=function(n){var l={id:i.generateGuid(),value:t.inputFile,type:i.getFileType(t.inputFile.value)};return e.fileTypeIsValid(l.type)?e.fileSizeExceeded(l.value.size)?void e.confirmFileIsTooLarge(l):(e.addFileToQueue(l),void this.createInputFileElement()):void e.confirmFileIsInvalid(l)},this.createInputFileElement=function(){var n=t.inputFile;n.style.zIndex=-999,$common.setLocation(n,{x:-99999,y:-99999}),this.attachFileInputEvents(n,!1);var l=e.get_id()+"_file_"+i.generateGuid(),s=$common.createElementFromTemplate({nodeName:"input",properties:{id:l,name:"act-file-data",type:"file",style:{zIndex:0,cursor:"pointer",position:"absolute"},multiple:!0}},n.parentNode);$common.setElementOpacity(s,0),this.attachFileInputEvents(s,!0),t.inputFile=s},this.startUpload=function(){var t=this._form,i=e.getNextFile();if(!i)return e._currentFileId=null,this.setThrobber(!1),void e.done();e.setAsUploading(i);var n=i.get_inputElementValue();for(e._currentFileId=i._id,this.setThrobber(!0);t.firstChild;)t.removeChild(t.firstChild);n.name="act-file-data",t.appendChild(n),t.setAttribute("action",e.get_uploadHandlerPath()+"?contextKey="+e.get_contextKey()+"&controlID="+e.get_id()+"&fileId="+e._currentFileId+"&fileName="+encodeURIComponent(i._fileName)+"&usePoll="+(e.get_serverPollingSupport()?"true":"false")),t.submit()},this.cancelUpload=function(){var t=new XMLHttpRequest,i=this;n&&n.abort(),t.open("POST","?contextKey="+e.get_contextKey()+"&controlID="+e.get_id()+"&cancel=1&guid="+e._currentFileId+i.getQueryString(),!0),t.onreadystatechange=function(){if(i.setThrobber(!1),4==t.readyState){if(200!=t.status)throw i.raiseUploadError(t),"Failed to cancel upload.";e.cancelUpload()}},t.send(null)},this.getQueryString=function(){return"&"+window.location.search.replace("?","")},this.createIFrame=function(){var e=this._iframeName,t=document.createElement("IFRAME");t.width="0",t.height="0",t.style.display="none",t.src="about:blank",t.id=e,t.name=e,t.security="restricted",document.body.appendChild(t),t.contentWindow.name=e,$addHandlers(t,{load:Function.createDelegate(this,this.onIFrameLoadedHandler)}),this._iframe=t},this.onIFrameLoadedHandler=function(t){if(e._currentFileId)try{var i=this._iframe,n=null;if(i.contentDocument?n=i.contentDocument:i.contentWindow?n=i.contentWindow.document:i.document&&(n=i.document),null==n)throw"Document not initialized";e.doneAndUploadNextFile(e.getCurrentFileItem())}catch(t){if(!e._canceled||!t.message||!(t.message.indexOf("Access is denied")>-1||t.message.indexOf("Permission denied")>-1))throw this.raiseUploadError(t),t}},this.setThrobber=function(i){return e.get_serverPollingSupport()?(e.setPercent(0),$common.setVisible(t.progressBar,!!i),$common.setVisible(t.progressBarContainer,!!i),void this.pollingServerProgress(i)):void(null!=e.get_throbber()&&(e.get_throbber().style.display=i?"":"none"))},this.pollingServerProgress=function(t){t&&e._currentFileId&&(n.open("GET","?contextKey="+e.get_contextKey()+"&controlID="+e.get_id()+"&poll=1&guid="+e._currentFileId,!0),n.send(null))},this.createForm=function(){var t,i="___postForm"+e.get_id();try{t=document.createElement('
')}catch(e){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){e.raise_uploadError(t),n&&n.abort(),e._currentFileId=null},this.resetUI=function(){e.setFileStatus(e._currentFileId,"error",Sys.Extended.UI.Resources.AjaxFileUpload_error)}},Sys.Extended.UI.AjaxFileUpload.ProcessorHtml5=function(e,t){var i=new Sys.Extended.UI.AjaxFileUpload.Utils,n=1e3*e.get_chunkSize(),l=0,s=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(),e.get_enabled()&&(this.addFilesToQueue(t.dataTransfer.files),e.get_autoStartUpload()&&e.startUpload())},this.onFileDragOverHandler=function(e){e.stopPropagation(),e.preventDefault()},this.onFileSelectedHandler=function(t){this.addFilesToQueue(t.target.files),this.createInputFileElement(),e.get_autoStartUpload()&&e.startUpload()},this.createInputFileElement=function(){var n=t.inputFile;delete n;var l=e.get_id()+"_file_"+i.generateGuid(),s=$common.createElementFromTemplate({nodeName:"input",properties:{id:l,name:"act-file-data",type:"file",style:{zIndex:0,cursor:"pointer",position:"absolute"},multiple:!0}},n.parentNode);$common.setElementOpacity(s,0),this.attachFileInputEvents(s,!0),t.inputFile=s},this.attachFileInputEvents=function(e,t){t?$addHandlers(e,{change:this.onFileSelected$delegate}):$common.removeHandlers(e,{change:this.onFileSelected$delegate})},this.addFilesToQueue=function(l){for(var s=0;sn&&(a=Math.ceil(o.size/n));var r={id:i.generateGuid(),value:l[s],type:i.getFileType(l[s]),uploaded:!1,slices:a};if(e.fileTypeIsValid(r.type)){if(e.fileSizeExceeded(r.value.size))e.confirmFileIsTooLarge(r);else if(!e.addFileToQueue(r))break}else e.confirmFileIsInvalid(r)}t.inputFile.value=null},this.cancelUpload=function(){s&&s.abort(),e.cancelUpload()},this.startUpload=function(){var i=e.getNextFile();i?(0===i._sliceIndex&&e.setPercent(0),$common.setVisible(t.progressBarContainer,!0),this.upload(i)):(e._currentFileId=null,e.setPercent(0),$common.setVisible(t.progressBarContainer,!1),e.done())},this.resetUI=function(){$common.setVisible(t.progressBarContainer,!1),$common.setVisible(e._elements.uploadOrCancelButton,!1);var i=e.getNextFile();i._isUploaded=!0,i._isUploading=!1},this.upload=function(i){if(e._isUploading){$common.setVisible(t.progressBar,!0),e.setAsUploading(i);var l=i.get_inputElementValue(),s=i._slices&&i._slices>0,o=0==i._sliceIndex;if(s){var a=i._sliceIndex*n,r=a+n;l=l.slice(a,r>l.size?l.size:r)}var d=new FormData,u=e._currentFileId=i._id,p=new XMLHttpRequest,c=this,h=function(e){return function(t){e.call(c,u,t)}};p.upload.addEventListener("progress",h(this.onProgressHandler),!1),p.addEventListener("load",h(this.onUploadCompleteHandler),!1),p.addEventListener("error",h(this.onUploadFailedHandler),!1),p.addEventListener("abort",h(this.onUploadCanceledHandler),!1),p.open("POST",e.get_uploadHandlerPath()+"?contextKey="+e.get_contextKey()+"&controlID="+e.get_id()+"&fileId="+u+"&fileName="+encodeURIComponent(i._fileName)+"&chunked="+(s?"true":"false")+"&firstChunk="+o,!0),d.append("act-file-data",l),p.send(d)}},this.onProgressHandler=function(t,i){if(e._isUploading&&i.lengthComputable){l=i.loaded;var n=e.getFileItem(t),s=n._slices,o=n._bytesUploaded+l,a=s-n._sliceIndex==1?o:i.total*s,r=0==s?(100*i.loaded/i.total).toFixed(2):(o/a*100).toFixed(2);e.setPercent(r)}},this.onUploadCompleteHandler=function(t,n){var s=this,o=e.getFileItem(t),a=o.get_inputElementValue();o._slices&&o._slices>0&&o._sliceIndex+10&&this._filesInQueue.length>=t)return alert(Sys.Extended.UI.Resources.AjaxFileUpload_MaxNumberOfFilesExceeded),!1;var i=new Sys.Extended.UI.AjaxFileUpload.Item(this.get_id(),e,Function.createDelegate(this,this.removeFileFromQueueHandler));return i.appendNodeTo(this._elements.queueContainer),i.setStatus("pending",Sys.Extended.UI.Resources.AjaxFileUpload_Pending),$common.setVisible(this._elements.queueContainer,!0),$common.setVisible(this._elements.uploadOrCancelButton,!0),this._filesInQueue.push(i),this._showFilesCount(),!0},_showFilesCount:function(){var e=0==this._filesInQueue.length;this.setStatusMessage(e?Sys.Extended.UI.Resources.AjaxFileUpload_SelectFileToUpload:String.format(Sys.Extended.UI.Resources.AjaxFileUpload_FileInQueue,this._filesInQueue.length.toString()))},fileTypeIsValid:function(e){if(!this._allowedFileTypes)return!0;for(var t=this._allowedFileTypes.split(","),i=0;ithis.getMaxFileSizeInBytes()},confirmFileIsInvalid:function(e){var t=new Sys.Extended.UI.AjaxFileUpload.Utils;alert(String.format(Sys.Extended.UI.Resources.AjaxFileUpload_WrongFileType,t.getFileName(e.value),e.type))},confirmFileIsTooLarge:function(e){var t=new Sys.Extended.UI.AjaxFileUpload.Utils;alert(String.format(Sys.Extended.UI.Resources.AjaxFileUpload_TooLargeFile,t.getFileName(e.value),this.get_maxFileSize()))},getMaxFileSizeInBytes:function(){return 1024*this.get_maxFileSize()},doneAndUploadNextFile:function(e){var t=new XMLHttpRequest,i=this;t.open("POST","?contextKey="+this.get_contextKey()+"&controlID="+this.get_id()+"&done=1&guid="+e._id+this.getQueryString(),!0),t.onreadystatechange=function(n){if(4==t.readyState){if(200!=t.status||""==t.responseText)throw i.setFileStatus(e,"error",Sys.Extended.UI.Resources.AjaxFileUpload_error),i.raise_uploadError(t),"error raising upload complete event and start new upload";i.raise_uploadComplete(Sys.Serialization.JavaScriptSerializer.deserialize(t.responseText)),i._processor.startUpload()}},t.send()},getQueryString:function(){return"&"+window.location.search.replace("?","")},cancelUpload:function(){var e=this.getCurrentFileItem();e._isUploaded=!1,e._isUploading=!1,this.setStatusMessage(Sys.Extended.UI.Resources.AjaxFileUpload_UploadCanceled);for(var t=0;t=100&&(e="100"),t.style.width=e+"%",$common.setText(t,String.format(Sys.Extended.UI.Resources.AjaxFileUpload_UploadedPercentage,e))},get_allowedFileTypes:function(){return this._allowedFileTypes},set_allowedFileTypes:function(e){this._allowedFileTypes=e},get_contextKey:function(){return this._contextKey},set_contextKey:function(e){this._contextKey=e},get_postBackUrl:function(){return this._postBackUrl},set_postBackUrl:function(e){this._postBackUrl=e},get_mode:function(){return this._mode},set_mode:function(e){this._mode=e},get_autoStartUpload:function(){return this._autoStartUpload},set_autoStartUpload:function(e){this._autoStartUpload=e},get_serverPollingSupport:function(){return this._serverPollingSupport},set_serverPollingSupport:function(e){this._serverPollingSupport=e},get_throbber:function(){return this._throbber},set_throbber:function(e){this._throbber=e},get_maximumNumberOfFiles:function(){return this._maximumNumberOfFiles},set_maximumNumberOfFiles:function(e){this._maximumNumberOfFiles=e},get_chunkSize:function(){return this._chunkSize},set_chunkSize:function(e){this._chunkSize=e},get_clearFileListAfterUpload:function(){return this._clearFileListAfterUpload},set_clearFileListAfterUpload:function(e){this._clearFileListAfterUpload=e},get_useAbsoluteHandlerPath:function(){return this._useAbsoluteHandlerPath},set_useAbsoluteHandlerPath:function(e){this._useAbsoluteHandlerPath=e},get_maxFileSize:function(){return this._maxFileSize},set_maxFileSize:function(e){this._maxFileSize=e},get_uploadHandlerPath:function(){return this._uploadHandlerPath},set_uploadHandlerPath:function(e){this._uploadHandlerPath=e},get_enabled:function(){return this.enabled},set_enabled:function(e){this.enabled=e},add_uploadStart:function(e){this.get_events().addHandler("uploadStart",e)},remove_uploadStart:function(e){this.get_events().removeHandler("uploadStart",e)},raiseUploadStart:function(e){Sys.Extended.Deprecated("raiseUploadStart(e)","raise_uploadStart(e)"),this.raise_uploadStart(e)},raise_uploadStart:function(e){var t=this.get_events().getHandler("uploadStart");if(t){var i=new Sys.Extended.UI.AjaxFileUploadStartEventArgs(e.FilesInQueue,e.ServerArguments);t(this,i)}},add_uploadComplete:function(e){this.get_events().addHandler("uploadComplete",e)},remove_uploadComplete:function(e){this.get_events().removeHandler("uploadComplete",e)},raiseUploadComplete:function(e){Sys.Extended.Deprecated("raiseUploadComplete(e)","raise_uploadComplete(e)"),this.raise_uploadComplete(e)},raise_uploadComplete:function(e){var t=this.getCurrentFileItem();if(!t||!e||e.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();var i=this.get_events().getHandler("uploadComplete");if(i){var n=Array.indexOf(this._filesInQueue,t),l=new Sys.Extended.UI.AjaxFileUploadEventArgs(e.FileId,e.StatusMessage,e.FileName,e.FileSize,e.ContentType,e.PostedUrl,n,this._filesInQueue.length);i(this,l)}},add_uploadCompleteAll:function(e){this.get_events().addHandler("uploadCompleteAll",e)},remove_uploadCompleteAll:function(e){this.get_events().removeHandler("uploadCompleteAll",e)},raiseUploadCompleteAll:function(e){Sys.Extended.Deprecated("raiseUploadCompleteAll(e)","raise_uploadCompleteAll(e)"),this.raise_uploadCompleteAll("raiseUploadCompleteAll(e)","raise_uploadCompleteAll(e)")},raise_uploadCompleteAll:function(e){var t=this.get_events().getHandler("uploadCompleteAll");if(t){var i=new Sys.Extended.UI.AjaxFileUploadCompleteAllEventArgs(e.FilesInQueue,e.FilesUploaded,e.Reason,e.ServerArguments);t(this,i)}},add_uploadError:function(e){this.get_events().addHandler("uploadError",e)},remove_uploadError:function(e){this.get_events().removeHandler("uploadError",e)},raiseUploadError:function(e){Sys.Extended.Deprecated("raiseUploadError(e)","raise_uploadError(e)"),this.raise_uploadError(e)},raise_uploadError:function(e){var t=this.get_events().getHandler("uploadError");t&&t(this,e),this._processor.resetUI(),this._canceled=!1,this._isUploading=!1,this._isUploaded=!0,this.enableControls(!0)},getCurrentFileItem:function(){return this.getFileItem(this._currentFileId)},getNextFile:function(){if(!this._isUploading)return null;for(var e=0;e=0?e.lastIndexOf("\\"):e.lastIndexOf("/"),n=e.substring(i);0!==n.indexOf("\\")&&0!==n.indexOf("/")||(n=n.substring(1)),t=n}}return t},this.getFileType=function(t){if(!t)throw"file must defined or not null";if(!t.value&&t.name)return e(t.name);if(t.value&&(t=t.value),"string"!=typeof t)throw"can't resolve file type.";return e(t)},this.sizeToString=function(e){if(!e||e<=0)return"0 Kb";var t=["bytes","kb","MB","GB","TB","PB"],i=Math.floor(Math.log(e)/Math.log(1024));return(e/Math.pow(1024,Math.floor(i))).toFixed(2)+" "+t[i]},this.checkHtml5BrowserSupport=function(){return window.File&&window.FileReader&&window.FileList&&window.Blob&&(new XMLHttpRequest).upload}},Sys.Extended.UI.AjaxFileUpload.Item=function(e,t,i){this._deleteButton=null,this._parentId=e,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(e){var t=this,i=this._inputElementValue,n=new Sys.Extended.UI.AjaxFileUpload.Utils,l=n.checkHtml5BrowserSupport(),s=this._id,o=$common.createElementFromTemplate({nodeName:"div",properties:{id:this._parentId+"_FileItemContainer_"+s},cssClasses:["ajax__fileupload_fileItemInfo"]}),a=$common.createElementFromTemplate({nodeName:"div",properties:{id:this._parentId+"_FileInfoContainer_"+s,style:{display:"inline-block"}}}),r=$common.createElementFromTemplate({nodeName:"span",properties:{id:this._parentId+"_FileItemInfo_"+s},cssClasses:["ajax__fileupload_fileItemInfo"]}),d=$common.createElementFromTemplate({nodeName:"span",properties:{id:this._parentId+"_FileItemStatus_"+s},cssClasses:["uploadstatus"]}),u=$common.createElementFromTemplate({nodeName:"div",properties:{id:this._parentId+"_FileItemDeleteButton_"+s},cssClasses:["removeButton"]});this._fileName=n.getFileName(i);var p=Sys.Extended.UI.htmlEncode;if(l){this._fileSize=i.size;var c=i.type?'('+p(i.type)+")":"";r.innerHTML=''+p(this._fileName)+" "+c+' - '+n.sizeToString(i.size)+" ",this._fileType=i.type}else r.innerHTML=''+p(this._fileName)+"",this._fileType=n.getFileType(i);return a.appendChild(r),a.appendChild(d),$common.setText(u,Sys.Extended.UI.Resources.AjaxFileUpload_Remove),$addHandlers(u,{click:Function.createDelegate(this,function(){e(t)})}),Sys.Browser.agent==Sys.Browser.InternetExplorer&&Sys.Browser.version<=8?(o.appendChild(u),o.appendChild(a)):(o.appendChild(a),o.appendChild(u)),this._fileInfoContainer=a,this._deleteButton=u,this._fileStatusText=d,o},setStatus:function(e,t){$common.setText(this._fileStatusText," ("+t+")"),this._fileInfoContainer.setAttribute("class",e+"State")},disabled:function(e){e?this._deleteButton.disabled="disabled":this._deleteButton.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(e){e.appendChild(this._ui)},removeNodeFrom:function(e){e.removeChild(this._ui)}},Sys.Extended.UI.AjaxFileUpload.Processor=function(e,t){var i=new Sys.Extended.UI.AjaxFileUpload.Utils,n=new XMLHttpRequest;this._iframe=null,this._iframeName=e.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 i=this;n.onreadystatechange=function(t){if(4==n.readyState&&200==n.status){var l=n.responseText;l&&(l=parseFloat(l).toFixed(2),e.setPercent(l)),l<100&&setTimeout(function(){i.pollingServerProgress(!0)},500)}}},this.attachFileInputEvents=function(e,t){t?$addHandlers(e,{change:this.onFileSelected$delegate}):$common.removeHandlers(e,{change:this.onFileSelected$delegate})},this.onFileSelectedHandler=function(n){var l={id:i.generateGuid(),value:t.inputFile,type:i.getFileType(t.inputFile.value)};return e.fileTypeIsValid(l.type)?e.fileSizeExceeded(l.value.size)?void e.confirmFileIsTooLarge(l):(e.addFileToQueue(l),void this.createInputFileElement()):void e.confirmFileIsInvalid(l)},this.createInputFileElement=function(){var n=t.inputFile;n.style.zIndex=-999,$common.setLocation(n,{x:-99999,y:-99999}),this.attachFileInputEvents(n,!1);var l=e.get_id()+"_file_"+i.generateGuid(),s=$common.createElementFromTemplate({nodeName:"input",properties:{id:l,name:"act-file-data",type:"file",style:{zIndex:0,cursor:"pointer",position:"absolute"},multiple:!0}},n.parentNode);$common.setElementOpacity(s,0),this.attachFileInputEvents(s,!0),t.inputFile=s},this.startUpload=function(){var t=this._form,i=e.getNextFile();if(!i)return e._currentFileId=null,this.setThrobber(!1),void e.done();e.setAsUploading(i);var n=i.get_inputElementValue();for(e._currentFileId=i._id,this.setThrobber(!0);t.firstChild;)t.removeChild(t.firstChild);n.name="act-file-data",t.appendChild(n),t.setAttribute("action",e.get_uploadHandlerPath()+"?contextKey="+encodeURIComponent(e.get_contextKey())+"&controlID="+e.get_id()+"&fileId="+e._currentFileId+"&fileName="+encodeURIComponent(i._fileName)+"&usePoll="+(e.get_serverPollingSupport()?"true":"false")),t.submit()},this.cancelUpload=function(){var t=new XMLHttpRequest,i=this;n&&n.abort(),t.open("POST","?contextKey="+encodeURIComponent(e.get_contextKey())+"&controlID="+e.get_id()+"&cancel=1&guid="+e._currentFileId+i.getQueryString(),!0),t.onreadystatechange=function(){if(i.setThrobber(!1),4==t.readyState){if(200!=t.status)throw i.raiseUploadError(t),"Failed to cancel upload.";e.cancelUpload()}},t.send(null)},this.getQueryString=function(){return"&"+window.location.search.replace("?","")},this.createIFrame=function(){var e=this._iframeName,t=document.createElement("IFRAME");t.width="0",t.height="0",t.style.display="none",t.src="about:blank",t.id=e,t.name=e,t.security="restricted",document.body.appendChild(t),t.contentWindow.name=e,$addHandlers(t,{load:Function.createDelegate(this,this.onIFrameLoadedHandler)}),this._iframe=t},this.onIFrameLoadedHandler=function(t){if(e._currentFileId)try{var i=this._iframe,n=null;if(i.contentDocument?n=i.contentDocument:i.contentWindow?n=i.contentWindow.document:i.document&&(n=i.document),null==n)throw"Document not initialized";e.doneAndUploadNextFile(e.getCurrentFileItem())}catch(t){if(!e._canceled||!t.message||!(t.message.indexOf("Access is denied")>-1||t.message.indexOf("Permission denied")>-1))throw this.raiseUploadError(t),t}},this.setThrobber=function(i){return e.get_serverPollingSupport()?(e.setPercent(0),$common.setVisible(t.progressBar,!!i),$common.setVisible(t.progressBarContainer,!!i),void this.pollingServerProgress(i)):void(null!=e.get_throbber()&&(e.get_throbber().style.display=i?"":"none"))},this.pollingServerProgress=function(t){t&&e._currentFileId&&(n.open("GET","?contextKey="+encodeURIComponent(e.get_contextKey())+"&controlID="+e.get_id()+"&poll=1&guid="+e._currentFileId,!0),n.send(null))},this.createForm=function(){var t,i="___postForm"+e.get_id();try{t=document.createElement('')}catch(e){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){e.raise_uploadError(t),n&&n.abort(),e._currentFileId=null},this.resetUI=function(){e.setFileStatus(e._currentFileId,"error",Sys.Extended.UI.Resources.AjaxFileUpload_error)}},Sys.Extended.UI.AjaxFileUpload.ProcessorHtml5=function(e,t){var i=new Sys.Extended.UI.AjaxFileUpload.Utils,n=1e3*e.get_chunkSize(),l=0,s=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(),e.get_enabled()&&(this.addFilesToQueue(t.dataTransfer.files),e.get_autoStartUpload()&&e.startUpload())},this.onFileDragOverHandler=function(e){e.stopPropagation(),e.preventDefault()},this.onFileSelectedHandler=function(t){this.addFilesToQueue(t.target.files),this.createInputFileElement(),e.get_autoStartUpload()&&e.startUpload()},this.createInputFileElement=function(){var n=t.inputFile;delete n;var l=e.get_id()+"_file_"+i.generateGuid(),s=$common.createElementFromTemplate({nodeName:"input",properties:{id:l,name:"act-file-data",type:"file",style:{zIndex:0,cursor:"pointer",position:"absolute"},multiple:!0}},n.parentNode);$common.setElementOpacity(s,0),this.attachFileInputEvents(s,!0),t.inputFile=s},this.attachFileInputEvents=function(e,t){t?$addHandlers(e,{change:this.onFileSelected$delegate}):$common.removeHandlers(e,{change:this.onFileSelected$delegate})},this.addFilesToQueue=function(l){for(var s=0;sn&&(a=Math.ceil(o.size/n));var r={id:i.generateGuid(),value:l[s],type:i.getFileType(l[s]),uploaded:!1,slices:a};if(e.fileTypeIsValid(r.type)){if(e.fileSizeExceeded(r.value.size))e.confirmFileIsTooLarge(r);else if(!e.addFileToQueue(r))break}else e.confirmFileIsInvalid(r)}t.inputFile.value=null},this.cancelUpload=function(){s&&s.abort(),e.cancelUpload()},this.startUpload=function(){var i=e.getNextFile();i?(0===i._sliceIndex&&e.setPercent(0),$common.setVisible(t.progressBarContainer,!0),this.upload(i)):(e._currentFileId=null,e.setPercent(0),$common.setVisible(t.progressBarContainer,!1),e.done())},this.resetUI=function(){$common.setVisible(t.progressBarContainer,!1),$common.setVisible(e._elements.uploadOrCancelButton,!1);var i=e.getNextFile();i._isUploaded=!0,i._isUploading=!1},this.upload=function(i){if(e._isUploading){$common.setVisible(t.progressBar,!0),e.setAsUploading(i);var l=i.get_inputElementValue(),s=i._slices&&i._slices>0,o=0==i._sliceIndex;if(s){var a=i._sliceIndex*n,r=a+n;l=l.slice(a,r>l.size?l.size:r)}var d=new FormData,u=e._currentFileId=i._id,p=new XMLHttpRequest,c=this,h=function(e){return function(t){e.call(c,u,t)}};p.upload.addEventListener("progress",h(this.onProgressHandler),!1),p.addEventListener("load",h(this.onUploadCompleteHandler),!1),p.addEventListener("error",h(this.onUploadFailedHandler),!1),p.addEventListener("abort",h(this.onUploadCanceledHandler),!1),p.open("POST",e.get_uploadHandlerPath()+"?contextKey="+encodeURIComponent(e.get_contextKey())+"&controlID="+e.get_id()+"&fileId="+u+"&fileName="+encodeURIComponent(i._fileName)+"&chunked="+(s?"true":"false")+"&firstChunk="+o,!0),d.append("act-file-data",l),p.send(d)}},this.onProgressHandler=function(t,i){if(e._isUploading&&i.lengthComputable){l=i.loaded;var n=e.getFileItem(t),s=n._slices,o=n._bytesUploaded+l,a=s-n._sliceIndex==1?o:i.total*s,r=0==s?(100*i.loaded/i.total).toFixed(2):(o/a*100).toFixed(2);e.setPercent(r)}},this.onUploadCompleteHandler=function(t,n){var s=this,o=e.getFileItem(t),a=o.get_inputElementValue();o._slices&&o._slices>0&&o._sliceIndex+10&&this._filesInQueue.length>=t)return alert(Sys.Extended.UI.Resources.AjaxFileUpload_MaxNumberOfFilesExceeded),!1;var i=new Sys.Extended.UI.AjaxFileUpload.Item(this.get_id(),e,Function.createDelegate(this,this.removeFileFromQueueHandler));return i.appendNodeTo(this._elements.queueContainer),i.setStatus("pending",Sys.Extended.UI.Resources.AjaxFileUpload_Pending),$common.setVisible(this._elements.queueContainer,!0),$common.setVisible(this._elements.uploadOrCancelButton,!0),this._filesInQueue.push(i),this._showFilesCount(),!0},_showFilesCount:function(){var e=0==this._filesInQueue.length;this.setStatusMessage(e?Sys.Extended.UI.Resources.AjaxFileUpload_SelectFileToUpload:String.format(Sys.Extended.UI.Resources.AjaxFileUpload_FileInQueue,this._filesInQueue.length.toString()))},fileTypeIsValid:function(e){if(!this._allowedFileTypes)return!0;for(var t=this._allowedFileTypes.split(","),i=0;ithis.getMaxFileSizeInBytes()},confirmFileIsInvalid:function(e){var t=new Sys.Extended.UI.AjaxFileUpload.Utils;alert(String.format(Sys.Extended.UI.Resources.AjaxFileUpload_WrongFileType,t.getFileName(e.value),e.type))},confirmFileIsTooLarge:function(e){var t=new Sys.Extended.UI.AjaxFileUpload.Utils;alert(String.format(Sys.Extended.UI.Resources.AjaxFileUpload_TooLargeFile,t.getFileName(e.value),this.get_maxFileSize()))},getMaxFileSizeInBytes:function(){return 1024*this.get_maxFileSize()},doneAndUploadNextFile:function(e){var t=new XMLHttpRequest,i=this;t.open("POST","?contextKey="+encodeURIComponent(this.get_contextKey())+"&controlID="+this.get_id()+"&done=1&guid="+e._id+this.getQueryString(),!0),t.onreadystatechange=function(n){if(4==t.readyState){if(200!=t.status||""==t.responseText)throw i.setFileStatus(e,"error",Sys.Extended.UI.Resources.AjaxFileUpload_error),i.raise_uploadError(t),"error raising upload complete event and start new upload";i.raise_uploadComplete(Sys.Serialization.JavaScriptSerializer.deserialize(t.responseText)),i._processor.startUpload()}},t.send()},getQueryString:function(){return"&"+window.location.search.replace("?","")},cancelUpload:function(){var e=this.getCurrentFileItem();e._isUploaded=!1,e._isUploading=!1,this.setStatusMessage(Sys.Extended.UI.Resources.AjaxFileUpload_UploadCanceled);for(var t=0;t=100&&(e="100"),t.style.width=e+"%",$common.setText(t,String.format(Sys.Extended.UI.Resources.AjaxFileUpload_UploadedPercentage,e))},get_allowedFileTypes:function(){return this._allowedFileTypes},set_allowedFileTypes:function(e){this._allowedFileTypes=e},get_contextKey:function(){return this._contextKey},set_contextKey:function(e){this._contextKey=e},get_postBackUrl:function(){return this._postBackUrl},set_postBackUrl:function(e){this._postBackUrl=e},get_mode:function(){return this._mode},set_mode:function(e){this._mode=e},get_autoStartUpload:function(){return this._autoStartUpload},set_autoStartUpload:function(e){this._autoStartUpload=e},get_serverPollingSupport:function(){return this._serverPollingSupport},set_serverPollingSupport:function(e){this._serverPollingSupport=e},get_throbber:function(){return this._throbber},set_throbber:function(e){this._throbber=e},get_maximumNumberOfFiles:function(){return this._maximumNumberOfFiles},set_maximumNumberOfFiles:function(e){this._maximumNumberOfFiles=e},get_chunkSize:function(){return this._chunkSize},set_chunkSize:function(e){this._chunkSize=e},get_clearFileListAfterUpload:function(){return this._clearFileListAfterUpload},set_clearFileListAfterUpload:function(e){this._clearFileListAfterUpload=e},get_useAbsoluteHandlerPath:function(){return this._useAbsoluteHandlerPath},set_useAbsoluteHandlerPath:function(e){this._useAbsoluteHandlerPath=e},get_maxFileSize:function(){return this._maxFileSize},set_maxFileSize:function(e){this._maxFileSize=e},get_uploadHandlerPath:function(){return this._uploadHandlerPath},set_uploadHandlerPath:function(e){this._uploadHandlerPath=e},get_enabled:function(){return this.enabled},set_enabled:function(e){this.enabled=e},add_uploadStart:function(e){this.get_events().addHandler("uploadStart",e)},remove_uploadStart:function(e){this.get_events().removeHandler("uploadStart",e)},raiseUploadStart:function(e){Sys.Extended.Deprecated("raiseUploadStart(e)","raise_uploadStart(e)"),this.raise_uploadStart(e)},raise_uploadStart:function(e){var t=this.get_events().getHandler("uploadStart");if(t){var i=new Sys.Extended.UI.AjaxFileUploadStartEventArgs(e.FilesInQueue,e.ServerArguments);t(this,i)}},add_uploadComplete:function(e){this.get_events().addHandler("uploadComplete",e)},remove_uploadComplete:function(e){this.get_events().removeHandler("uploadComplete",e)},raiseUploadComplete:function(e){Sys.Extended.Deprecated("raiseUploadComplete(e)","raise_uploadComplete(e)"),this.raise_uploadComplete(e)},raise_uploadComplete:function(e){var t=this.getCurrentFileItem();if(!t||!e||e.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();var i=this.get_events().getHandler("uploadComplete");if(i){var n=Array.indexOf(this._filesInQueue,t),l=new Sys.Extended.UI.AjaxFileUploadEventArgs(e.FileId,e.StatusMessage,e.FileName,e.FileSize,e.ContentType,e.PostedUrl,n,this._filesInQueue.length);i(this,l)}},add_uploadCompleteAll:function(e){this.get_events().addHandler("uploadCompleteAll",e)},remove_uploadCompleteAll:function(e){this.get_events().removeHandler("uploadCompleteAll",e)},raiseUploadCompleteAll:function(e){Sys.Extended.Deprecated("raiseUploadCompleteAll(e)","raise_uploadCompleteAll(e)"),this.raise_uploadCompleteAll("raiseUploadCompleteAll(e)","raise_uploadCompleteAll(e)")},raise_uploadCompleteAll:function(e){var t=this.get_events().getHandler("uploadCompleteAll");if(t){var i=new Sys.Extended.UI.AjaxFileUploadCompleteAllEventArgs(e.FilesInQueue,e.FilesUploaded,e.Reason,e.ServerArguments);t(this,i)}},add_uploadError:function(e){this.get_events().addHandler("uploadError",e)},remove_uploadError:function(e){this.get_events().removeHandler("uploadError",e)},raiseUploadError:function(e){Sys.Extended.Deprecated("raiseUploadError(e)","raise_uploadError(e)"),this.raise_uploadError(e)},raise_uploadError:function(e){var t=this.get_events().getHandler("uploadError");t&&t(this,e),this._processor.resetUI(),this._canceled=!1,this._isUploading=!1,this._isUploaded=!0,this.enableControls(!0)},getCurrentFileItem:function(){return this.getFileItem(this._currentFileId)},getNextFile:function(){if(!this._isUploading)return null;for(var e=0;e