Files
SIG/Scripts/AjaxControlToolkit/Release/AsyncFileUpload.js
JORGE LUIS CAUDILLO ESPARZA c35cf91883 Commit inicial Ventas Productivo
2019-08-14 16:40:54 -07:00

1 line
9.6 KiB
JavaScript

Type.registerNamespace("Sys.Extended.UI");Sys.Extended.UI.AsyncFileUpload=function(n){Sys.Extended.UI.AsyncFileUpload.initializeBase(this,[n]);this._hiddenField=null;this._inputFile=null;this._innerTB=null;this._postBackUrl="";this._formName="";this._iframe=null;this._waitTimer=null;this._completeBackColor="";this._uploadingBackColor="";this._errorBackColor="";this._throbber=null;this._onchange$delegate=null;this._onload$delegate=null;this._app_onload$delegate=Function.createDelegate(this,this._app_onload);this._onmouseup$delegate=null};Sys.Extended.UI.AsyncFileUpload.prototype={get_throbber:function(){return this._throbber},set_throbber:function(n){this._throbber=n},get_completeBackColor:function(){return this._completeBackColor},set_completeBackColor:function(n){this._completeBackColor=n},get_errorBackColor:function(){return this._errorBackColor},set_errorBackColor:function(n){this._errorBackColor=n},get_uploadingBackColor:function(){return this._uploadingBackColor},set_uploadingBackColor:function(n){this._uploadingBackColor=n},get_inputFile:function(){return this._inputFile},set_inputFile:function(n){this._inputFile=n},get_hiddenField:function(){return this._hiddenField},set_hiddenField:function(n){this._hiddenField=n},get_innerTB:function(){return this._innerTB},set_innerTB:function(n){this._innerTB=n},get_postBackUrl:function(){return this._postBackUrl},set_postBackUrl:function(n){this._postBackUrl=n},get_formName:function(){return this._formName},set_formName:function(n){this._formName=n},add_uploadStarted:function(n){this.get_events().addHandler("uploadStarted",n)},remove_uploadStarted:function(n){this.get_events().removeHandler("uploadStarted",n)},raise_uploadStarted:function(n){var t=this.get_events().getHandler("uploadStarted");return t?t(this,n):!0},raiseUploadStarted:function(n){return Sys.Extended.Deprecated("raiseUploadStarted(e)","raise_uploadStarted(e)"),this.raise_uploadStarted(n)},add_uploadComplete:function(n){this.get_events().addHandler("uploadComplete",n)},remove_uploadComplete:function(n){this.get_events().removeHandler("uploadComplete",n)},raise_uploadComplete:function(n){var t=this.get_events().getHandler("uploadComplete");t&&t(this,n)},raiseUploadComplete:function(n){return Sys.Extended.Deprecated("raiseUploadComplete(e)","raise_uploadComplete(e)"),this.raise_uploadComplete(n)},add_uploadError:function(n){this.get_events().addHandler("uploadError",n)},remove_uploadError:function(n){this.get_events().removeHandler("uploadError",n)},raise_uploadError:function(n){var t=this.get_events().getHandler("uploadError");return t?(t(this,n),!0):!1},raiseUploadError:function(n){return Sys.Extended.Deprecated("raiseUploadError(e)","raise_uploadError(e)"),this.raise_uploadError(n)},setThrobber:function(n){this.get_throbber()!=null&&(this.get_throbber().style.display=n?"":"none")},_onStart:function(n){var t=this.raise_uploadStarted(new Sys.Extended.UI.AsyncFileUploadEventArgs(n,null,null,null));return typeof t=="undefined"&&(t=!0),t},initialize:function(){Sys.Extended.UI.AsyncFileUpload.callBaseMethod(this,"initialize");Sys.Application.add_load(this._app_onload$delegate);this._iframeName=this.get_element().id+"_iframe";this.setThrobber(!1)},dispose:function(){Sys.Application.remove_load(this._app_onload$delegate);this._onchange$delegate!=null&&($common.removeHandlers(this._inputFile,{change:this._onchange$delegate}),this._onchange$delegate=null);this._onmouseup$delegate!=null&&($common.removeHandlers(this._inputFile,{mouseup:this._onmouseup$delegate}),this._onmouseup$delegate=null);this._removeIframe();Sys.Extended.UI.AsyncFileUpload.callBaseMethod(this,"dispose")},_onmouseup:function(){var n=this._inputFile;return setTimeout(function(){n.blur()},0),!0},_app_onload:function(){if(this.setThrobber(!1),this._inputFile!=null&&(this._onchange$delegate==null&&(this._onchange$delegate=Function.createDelegate(this,this._onchange),$addHandlers(this._inputFile,{change:this._onchange$delegate})),this._innerTB!=null)){this._inputFile.blur();var n=this._inputFile;setTimeout(function(){n.blur()},0);this._innerTB.style.width=this._inputFile.offsetWidth-107+"px";this._inputFile.parentNode.style.width=this._inputFile.offsetWidth+"px";Sys.Browser.agent==Sys.Browser.InternetExplorer&&(this._onmouseup$delegate=Function.createDelegate(this,this._onmouseup),$addHandlers(this._inputFile,{mouseup:this._onmouseup$delegate}))}},_removeIframe:function(){this._removeTimer();this._iframe!=null&&(this._onload$delegate!=null&&($common.removeHandlers(this._iframe,{load:this._onload$delegate}),this._onload$delegate=null),document.body.removeChild(this._iframe),this._iframe=null)},_removeTimer:function(){this._waitTimer!=null&&(window.clearTimeout(this._waitTimer),this._waitTimer=null)},_onError:function(n){var t=Sys.Extended.UI.Resources.AsyncFileUpload_UnhandledException;this.setThrobber(!1);this.get_errorBackColor()!=""&&(this._innerTB!=null?this._innerTB.style.backgroundColor=this.get_errorBackColor():this._inputFile.style.backgroundColor=this.get_errorBackColor());this.raise_uploadError(new Sys.Extended.UI.AsyncFileUploadEventArgs(this._inputFile.value,null,null,n))||alert(t+": "+n)},_onchange:function(){var t=this._inputFile.value,n,i;if(t!=""){this._innerTB!=null&&(this._innerTB.value=t);this._hiddenField!=null&&(this._hiddenField.value=t);try{this._iframe==null?(this._onload$delegate=Function.createDelegate(this,this._onload),n=document.createElement("IFRAME"),n.width="0",n.height="0",n.style.display="none",n.src="about:blank",n.id=this._iframeName,n.name=this._iframeName,$addHandlers(n,{load:this._onload$delegate}),this._iframe=n,document.body.appendChild(this._iframe),n.contentWindow.name=this._iframeName):(this._removeIframe(),i=Sys.Extended.UI.Resources.AsyncFileUpload_InternalErrorMessage,this._onError(i))}catch(r){this._onError(r.message)}}},_stopLoad:function(n){var r=document.getElementById(this._formName),u,i,t;if(this._removeTimer(),this.setThrobber(!1),r.target="_top",r.action=this._postBackUrl,i="",t=n.split("------"),t.length>0){if(t[0]=="error"){this._onError(t[1]);return}u=parseInt(t[0])}t.length>1&&(i=t[1]);this.get_completeBackColor()!=""&&(this._innerTB!=null?this._innerTB.style.backgroundColor=this.get_completeBackColor():this._inputFile.style.backgroundColor=this.get_completeBackColor());this.raise_uploadComplete(new Sys.Extended.UI.AsyncFileUploadEventArgs(this._inputFile.value,u,i,null))},_onload:function(n){var l=!0,f=this,i=document.getElementById(this._formName),t,a,u,e,v,o,r,s,h,y,c,n;try{if(t=this._iframe.contentWindow.document,t==null||t.location==null){n={message:Sys.Extended.UI.Resources.AsyncFileUpload_UploadingProblem};throw n;}else if(t.location.href=="about:blank"){if(this._removeTimer(),this.get_uploadingBackColor()!=""&&(this._innerTB!=null?this._innerTB.style.backgroundColor=this.get_uploadingBackColor():this._inputFile.style.backgroundColor=this.get_uploadingBackColor()),a=this._onStart(this._inputFile.value),a)return u=this._postBackUrl,u+=u.indexOf("?")===-1?"?":"&",i.action=u+"AsyncFileUploadID="+this.get_element().id+"&rnd="+Math.random().toString().replace(/\./g,""),i.target=this._iframeName,l=!1,this.setThrobber(!0),setTimeout(function(){i.submit();f._waitTimer=setTimeout(function(){f._wait()},100)},0),!0}else{if(t.body.innerHTML=="")return!0;if(e=t.getElementById(this.get_element().id),o="",e!=null){if(r=e.innerHTML.split("------"),r.length>0){if(r[0]=="error"){n={message:r[1]};throw n;}v=parseInt(r[0])}r.length>1&&(o=r[1])}else{s=Sys.Extended.UI.Resources.AsyncFileUpload_UnknownServerError;function w(n,t){return s=t,""}if(t.body.innerHTML.replace(/Exception\]:([^\n\r]+)[\n\r]/,w),h=Sys.Extended.UI.Resources.AsyncFileUpload_ServerResponseError+": '"+s+"'",y=confirm(h+"\n\n"+Sys.Extended.UI.Resources.AsyncFileUpload_ConfirmToSeeErrorPage),y){c=window.open("","NotFoundInAnswer","toolbar=0,status=1,scrollbars=1,resizable=1,width=600,height=400");function p(){try{c.document||setTimeout(p,100)}catch(i){return}var n=c.document;n.open();n.write("<body>"+t.body.innerHTML+"<\/body>");n.close()}setTimeout(p,0)}n={message:h};throw n;}this._removeTimer();i.target="_top";i.action=this._postBackUrl;this.get_completeBackColor()!=""&&(this._innerTB!=null?this._innerTB.style.backgroundColor=this.get_completeBackColor():this._inputFile.style.backgroundColor=this.get_completeBackColor());this.setThrobber(!1);this.raise_uploadComplete(new Sys.Extended.UI.AsyncFileUploadEventArgs(this._inputFile.value,v,o,null))}}catch(b){this._removeTimer();i.target="_top";i.action=this._postBackUrl;this._onError(b.message)}finally{l&&setTimeout(function(){f._removeIframe()},100)}},_wait:function(){var n;if(this._waitTimer!=null){n=this;try{var t=this._iframe.contentWindow.document,i=t.location,r=i.href;this._waitTimer=setTimeout(function(){n._wait()},100)}catch(u){setTimeout(function(){n._removeIframe()},100);setTimeout(function(){n._onError(Sys.Extended.UI.Resources.AsyncFileUpload_UploadingProblem)},0);this._waitTimer=null}}}};Sys.Extended.UI.AsyncFileUpload.registerClass("Sys.Extended.UI.AsyncFileUpload",Sys.Extended.UI.ControlBase);Sys.Extended.UI.AsyncFileUploadEventArgs=function(n,t,i,r){if(arguments.length!=4)throw Error.parameterCount();Sys.Extended.UI.AsyncFileUploadEventArgs.initializeBase(this);this._fileName=n;this._length=t;this._contentType=i;this._errorMessage=r};Sys.Extended.UI.AsyncFileUploadEventArgs.prototype={get_fileName:function(){var n=this._fileName.lastIndexOf("/"),t=this._fileName.lastIndexOf("\\");return this._fileName.substr((n>t?n:t)+1)},get_path:function(){return this._fileName},get_length:function(){return this._length},get_contentType:function(){return this._contentType},get_errorMessage:function(){return this._errorMessage}};Sys.Extended.UI.AsyncFileUploadEventArgs.registerClass("Sys.Extended.UI.AsyncFileUploadEventArgs",Sys.EventArgs);