Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
(function(G,E,A){E.ajaxContainer=E.ajaxContainer||{};
if(E.ajaxContainer.jsfRequest){return 
}E.ajaxContainer.jsfRequest=A.ajax.request;
A.ajax.request=function(J,I,H){E.queue.push(J,I,H)
};
E.ajaxContainer.jsfResponse=A.ajax.response;
E.ajaxContainer.isIgnoreResponse=function(){return E.queue.isIgnoreResponse()
};
A.ajax.response=function(I,H){E.queue.response(I,H)
};
var F="pull";
var D="push";
var C=F;
var B="org.richfaces.queue.global";
E.queue=(function(){var Q={};
var H={};
var U=function(Y,d,c,Z){this.queue=Y;
this.source=d;
this.options=G.extend({},Z||{});
this.queueOptions={};
var e;
if(this.options.queueId){if(Q[this.options.queueId]){e=this.options.queueId
}delete this.options.queueId
}else{var a=E.getDomElement(d);
var b;
if(a){a=G(a).closest("form");
if(a.length>0){b=a.get(0)
}}if(b&&b.id&&Q[b.id]){e=b.id
}else{e=B
}}if(e){this.queueOptions=Q[e]||{};
if(this.queueOptions.queueId){this.queueOptions=G.extend({},(Q[this.queueOptions.queueId]||{}),this.queueOptions)
}else{var a=E.getDomElement(d);
var b;
if(a){a=G(a).closest("form");
if(a.length>0){b=a.get(0)
}}if(b&&b.id&&Q[b.id]){e=b.id
}else{e=B
}if(e){this.queueOptions=G.extend({},(Q[e]||{}),this.queueOptions)
}}}if(typeof this.queueOptions.requestGroupingId=="undefined"){this.queueOptions.requestGroupingId=typeof this.source=="string"?this.source:this.source.id
}if(c&&c instanceof Object){if("layerX" in c){delete c.layerX
}if("layerY" in c){delete c.layerY
}}this.event=G.extend({},c);
this.requestGroupingId=this.queueOptions.requestGroupingId;
this.eventsCount=1
};
G.extend(U.prototype,{isIgnoreDupResponses:function(){return this.queueOptions.ignoreDupResponses
},getRequestGroupId:function(){return this.requestGroupingId
},setRequestGroupId:function(Y){this.requestGroupingId=Y
},resetRequestGroupId:function(){this.requestGroupingId=undefined
},setReadyToSubmit:function(Y){this.readyToSubmit=Y
},getReadyToSubmit:function(){return this.readyToSubmit
},ondrop:function(){var Y=this.queueOptions.onqueuerequestdrop;
if(Y){Y.call(this.queue,this.source,this.options,this.event)
}},onRequestDelayPassed:function(){this.readyToSubmit=true;
M.call(this.queue)
},startTimer:function(){var Y=this.queueOptions.requestDelay;
if(typeof Y!="number"){Y=this.queueOptions.requestDelay||0
}E.log.debug("Queue will wait "+(Y||0)+"ms before submit");
if(Y){var Z=this;
this.timer=window.setTimeout(function(){try{Z.onRequestDelayPassed()
}finally{Z.timer=undefined;
Z=undefined
}},Y)
}else{this.onRequestDelayPassed()
}},stopTimer:function(){if(this.timer){window.clearTimeout(this.timer);
this.timer=undefined
}},clearEntry:function(){this.stopTimer();
if(this.request){this.request.shouldNotifyQueue=false;
this.request=undefined
}},getEventsCount:function(){return this.eventsCount
},setEventsCount:function(Y){this.eventsCount=Y
}});
var V="event";
var N="success";
var S="complete";
var R=[];
var T;
var P=function(Z){var Y="richfaces.queue: ajax submit error";
if(Z&&Z.message){Y+=": "+Z.message
}E.log.warn(Y);
T=null;
M()
};
var J=function(Y){if(Y.type==V&&Y.status==N){E.log.debug("richfaces.queue: ajax submit successfull");
T=null;
M()
}};
A.ajax.addOnEvent(J);
A.ajax.addOnError(P);
var M=function(){if(C==F&&T){E.log.debug("richfaces.queue: Waiting for previous submit results");
return 
}if(O()){E.log.debug("richfaces.queue: Nothing to submit");
return 
}var Z;
if(R[0].getReadyToSubmit()){try{Z=T=R.shift();
E.log.debug("richfaces.queue: will submit request NOW");
var a=T.options;
a["AJAX:EVENTS_COUNT"]=T.eventsCount;
E.ajaxContainer.jsfRequest(T.source,T.event,a);
if(a.queueonsubmit){a.queueonsubmit.call(Z)
}I("onrequestdequeue",Z)
}catch(Y){P(Y)
}}};
var O=function(){return(X()==0)
};
var X=function(){return R.length
};
var L=function(){var Y=R.length-1;
return R[Y]
};
var W=function(Y){var Z=R.length-1;
R[Z]=Y
};
var I=function(Z,c){var a=c.queueOptions[Z];
if(a){if(typeof (a)=="string"){new Function(a).call(null,c)
}else{a.call(null,c)
}}var b,Y;
if(c.queueOptions.queueId&&(b=Q[c.queueOptions.queueId])&&(Y=b[Z])&&Y!=a){Y.call(null,c)
}};
var K=function(Y){R.push(Y);
E.log.debug("New request added to queue. Queue requestGroupingId changed to "+Y.getRequestGroupId());
I("onrequestqueue",Y)
};
return{DEFAULT_QUEUE_ID:B,getSize:X,isEmpty:O,submitFirst:function(){if(!O()){var Y=R[0];
Y.stopTimer();
Y.setReadyToSubmit(true);
M()
}},push:function(c,b,Z){var a=new U(this,c,b,Z);
var d=a.getRequestGroupId();
var Y=L();
if(Y){if(Y.getRequestGroupId()==d){E.log.debug("Similar request currently in queue");
E.log.debug("Combine similar requests and reset timer");
Y.stopTimer();
a.setEventsCount(Y.getEventsCount()+1);
W(a);
I("onrequestqueue",a)
}else{E.log.debug("Last queue entry is not the last anymore. Stopping requestDelay timer and marking entry as ready for submission");
Y.stopTimer();
Y.resetRequestGroupId();
Y.setReadyToSubmit(true);
K(a);
M()
}}else{K(a)
}a.startTimer()
},response:function(Z,Y){if(this.isIgnoreResponse()){T=null;
M()
}else{E.ajaxContainer.jsfResponse(Z,Y)
}},isIgnoreResponse:function(){var Y=R[0];
return Y&&T.isIgnoreDupResponses()&&T.queueOptions.requestGroupingId==Y.queueOptions.requestGroupingId
},clear:function(){var Y=L();
if(Y){Y.stopTimer()
}R=[]
},setQueueOptions:function(a,Y){var Z=typeof a;
if(Z=="string"){if(Q[a]){throw"Queue already registered"
}else{Q[a]=Y
}}else{if(Z=="object"){G.extend(Q,a)
}}return E.queue
},getQueueOptions:function(Y){return Q[Y]||{}
}}
}())
}(jQuery,RichFaces,jsf));
New to GrepCode? Check out our FAQ X