META-INF.adf.jsLibs.xhr.RequestQueue.js Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of trinidad-impl Show documentation
Show all versions of trinidad-impl Show documentation
Private implementation of the Apache MyFaces Trinidad project
The newest version!
function TrRequestQueue(a0)
{
this._state=TrRequestQueue.STATE_READY;
this._requestQueue=new Array();
this._stateChangeListeners=null;
this._window=a0;
this._useJsfBuiltInAjaxForXhr=(_agent.useJsfAjax&&typeof jsf!="undefined");
}
TrRequestQueue.STATE_READY=0;
TrRequestQueue.STATE_BUSY=1;
TrRequestQueue._MULTIPART_FRAME="_trDTSFrame";
TrRequestQueue._XMLHTTP_TYPE=0;
TrRequestQueue._MULTIPART_TYPE=1;
TrRequestQueue.prototype.dispose=function()
{
this._requestQueue=null;
this._stateChangeListeners=null;
this._window=null;
}
TrRequestQueue._RequestItem=function(
a1,
a2,
a3,
a4,
a5,
a6,
a7,
a8,
a9
)
{
this._type=a1;
this._context=a2;
this._actionURL=a3;
this._headerParams=a4;
this._content=a5;
this._method=a6;
this._event=a7;
this._source=a8;
this._formId=a9;
}
TrRequestQueue.prototype._broadcastRequestStatusChanged=function(
a10,a11,a12)
{
if(a11)
{
try
{
a11.call(a10,a12);
}
catch(e)
{
TrRequestQueue._logError(
"Error ",e," delivering XML request status changed to ",
a11);
}
}
}
TrRequestQueue.prototype._addRequestToQueue=function(
a13,
a14,
a15,
a16,
a17,
a18,
a19,
a20,
a21
)
{
var a22=new TrRequestQueue._RequestItem(
a13,a14,a16,a18,a17,
a15,a19,a20,a21);
if(this._useJsfBuiltInAjaxForXhr&&a13==TrRequestQueue._XMLHTTP_TYPE)
{
this._state=TrRequestQueue.STATE_BUSY;
this._broadcastStateChangeEvent(TrRequestQueue.STATE_BUSY);
this._doXmlHttpRequest(a22);
return;
}
this._requestQueue.push(a22);
try
{
var a23=new TrXMLRequestEvent(
TrXMLRequestEvent.STATUS_QUEUED,
null,
a20);
this._broadcastRequestStatusChanged(a14,a15,a23);
}
catch(e)
{
TrRequestQueue._logError("Error on listener callback invocation - STATUS_QUEUED",e);
}
if(this._state==TrRequestQueue.STATE_READY)
{
this._state=TrRequestQueue.STATE_BUSY;
this._broadcastStateChangeEvent(TrRequestQueue.STATE_BUSY);
this._doRequest();
}
}
TrRequestQueue.prototype.sendFormPost=function(
a24,
a25,
a26,
a27,
a28,
a29
)
{
var a30;
try
{
a30=a26.getAttribute("_trinPPRAction");
}
catch(e){;}
var a31=a30?a30:a26.action;
if(this._isMultipartForm(a26))
{
this.sendMultipartRequest(a24,a25,a31,a26,a27);
}
else
{
if(_agent.isIE)
this._autoCompleteForm(a26);
if(this._useJsfBuiltInAjaxForXhr)
{
this.sendRequest(a24,a25,a31,a27,a28,a29,
a27?a27.source:null,a26.id);
}
else
{
var a32=this._getPostbackContent(a26,a27);
this.sendRequest(a24,a25,a31,a32,a28,a29,
a27?a27.source:null,a26.id);
}
}
}
TrRequestQueue.prototype._autoCompleteForm=function(a33)
{
var a34=window.external;
if(a34&&(typeof a34.AutoCompleteSaveForm!="undefined"))
{
try
{
a34.AutoCompleteSaveForm(a33);
}
catch(e)
{
}
}
}
TrRequestQueue.prototype._isMultipartForm=function(a35)
{
if(!_agent.supportsDomDocument)
{
return false;
}
if(a35.enctype.toLowerCase()!="multipart/form-data")
return false;
var a36=a35.getElementsByTagName("input"),
inputCount=a36.length,multiPartForm=null;
for(var a37=0;a370)
{
a56=a56+"&";
}
return a56+a57+"="+a58.toString().replace(/\%/g,'%25')
.replace(/\+/g,'%2B')
.replace(/\//g,'%2F')
.replace(/\&/g,'%26')
.replace(/\"/g,'%22')
.replace(/\'/g,'%27');
}
TrRequestQueue.prototype.sendRequest=function(
a59,
a60,
a61,
a62,
a63,
a64,
a65,
a66
)
{
this._addRequestToQueue(TrRequestQueue._XMLHTTP_TYPE,a59,a60,a61,a62,
a63,a64,a65,a66);
}
TrRequestQueue.prototype.sendMultipartRequest=function(
a67,
a68,
a69,
a70,
a71
)
{
var a72=
{"htmlForm":a70,"params":a71,"context":a67,"method":a68};
this._addRequestToQueue(TrRequestQueue._MULTIPART_TYPE,a72,null,a69,
a71?a71.source:null,a70.id);
}
TrRequestQueue.prototype._doRequest=function()
{
var a73=this._requestQueue.shift();
switch(a73._type)
{
case TrRequestQueue._XMLHTTP_TYPE:
this._doXmlHttpRequest(a73);
break;
case TrRequestQueue._MULTIPART_TYPE:
this._doRequestThroughIframe(a73);
break;
}
}
TrRequestQueue.prototype._doXmlHttpRequest=function(a74)
{
var a75;
if(this._useJsfBuiltInAjaxForXhr)
{
a75=new TrXMLJsfAjaxRequest(a74._event,a74._content,
a74._formId);
}
else
{
a75=new TrXMLRequest();
}
a75.__dtsRequestContext=a74._context;
a75.__dtsRequestMethod=a74._method;
a75.__dtsRequestSource=a74._source;
a75.__dtsRequestFormId=a74._formId;
var a76=TrUIUtils.createCallback(this,this._handleRequestCallback);
a75.setCallback(a76);
if(!this._useJsfBuiltInAjaxForXhr)
{
a75.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
var a77=a74._headerParams;
if(a77!=null)
{
for(var a78 in a77)
{
var a79=a77[a78];
if(a79["join"])
a79=a79.join(',')
a75.setRequestHeader(a78,a79);
}
}
}
a75.send(a74._actionURL,a74._content);
}
TrRequestQueue.prototype._doRequestThroughIframe=function(a80)
{
var a81=a80._context.htmlForm;
var a82=a80._actionURL;
var a83=a80._context.params;
var a84=TrRequestQueue._MULTIPART_FRAME;
var a85=this._getDomDocument();
var a86=a85.getElementById(a84),iframeDoc;
var a87=_agent.isIE;
if(!a86)
{
a86=a85.createElement('iframe');
a86.name=a84;
a86.id=a84;
var a88=a86.style;
a88.top=a88.left='0px';
a88.width=a88.height='1px'
a88.position='absolute';
a88.visibility="hidden";
a85.body.appendChild(a86);
}
if(a87)
{
a86=a85.frames[a84];
a86.name=a84;
iframeDoc=a86.document;
}
else if(_agent.isSafari)
{
iframeDoc=a86.document;
}
else
{
iframeDoc=a86.contentDocument;
}
if(iframeDoc&&iframeDoc.firstChild)
iframeDoc.removeChild(iframeDoc.firstChild);
this._source=a80.params?
a80.params["javax.faces.source"]||a80.params["source"]:null;
this._dtsContext=a80._context.context;
this._dtsRequestMethod=a80._context.method;
this._htmlForm=a81;
this._dtsSource=a80._source;
this._savedActionUrl=a81.action;
this._savedTarget=a81.target;
a81.method="POST";
a81.action=a82;
a81.target=a84;
this._appendParamNode(a85,a81,"Tr-XHR-Message","true");
if(a83)
{
for(var a89 in a83)
{
var a90=a83[a89];
this._appendParamNode(a85,a81,a89,a90);
}
}
if(this._iframeLoadCallback==null)
this._iframeLoadCallback=TrUIUtils.createCallback(this,this._handleIFrameLoad);
if(_agent.isIE)
this._autoCompleteForm(a81);
try
{
a81.submit();
}
catch(e)
{
if(this._isMultipartForm(a81))
{
var a91=_createFacesMessage(
'org.apache.myfaces.trinidad.component.core.input.CoreInputFile.INPUT_FILE_ERROR');
if(!TrMessageBox.isPresent())
alert(a91.getDetail());
else
TrMessageBox.addMessage(null,null,a91);
}
else
{
throw e;
}
}
this._window.setTimeout(this._iframeLoadCallback,50);
}
TrRequestQueue.prototype._appendParamNode=function(a92,a93,a94,a95)
{
var a96=this._paramNodes;
if(!a96)
{
a96=new Array();
this._paramNodes=a96;
}
if(a94=="source")
{
var a97=a92.getElementsByName("source");
if(a97.length>0)
{
for(var a98=0,size=a97.length;a98=300)&&(a117!=0))
{
TrRequestQueue._alertError();
TrRequestQueue._logError("Error StatusCode(",
a117,
") while performing request\n",
a115.getResponseText());
}
try
{
if(a117!=0)
{
var a119=new TrXMLRequestEvent(
TrXMLRequestEvent.STATUS_COMPLETE,
a115,
a115.__dtsRequestSource,
a115.__dtsRequestFormId);
this._broadcastRequestStatusChanged(
a115.__dtsRequestContext,
a115.__dtsRequestMethod,
a119);
}
}
finally
{
a115.cleanup();
delete a115;
this._requestDone();
}
}
TrRequestQueue.prototype._requestDone=function()
{
if(this._requestQueue.length>0)
{
this._doRequest();
}
else
{
this._state=TrRequestQueue.STATE_READY;
this._broadcastStateChangeEvent(TrRequestQueue.STATE_READY);
}
}
TrRequestQueue.prototype.addStateChangeListener=function(a120,a121)
{
var a122=this._stateChangeListeners;
if(!a122)
{
a122=new Array();
this._stateChangeListeners=a122;
}
a122.push(a120);
a122.push(a121);
}
TrRequestQueue.prototype.removeStateChangeListener=function(a123,a124)
{
var a125=this._stateChangeListeners;
var a126=a125.length;
for(var a127=0;a127