datasource-min.js revision 9e58396d3563168e91dc995170288bc18b84ab6f
YUI.add("datasource-base",function(C){C.namespace("DataSource");var A=C.Lang,B=function(){B.superclass.constructor.apply(this,arguments);};C.mix(B,{NAME:"DataSource",ATTRS:{source:{value:null}},_tId:0,issueCallback:function(E){if(E.callback){var F=E.callback.scope||window,D=(E.error&&E.callback.failure)||E.callback.success;if(D){D.apply(F,[E]);}}}});C.extend(B,C.Base,{_queue:null,initializer:function(){this._queue={interval:null,conn:null,requests:[]};this._initEvents();},destructor:function(){},_initEvents:function(){this.publish("request",{defaultFn:this._handleRequest});this.publish("data",{defaultFn:this._handleData});this.publish("response",{defaultFn:this._handleResponse});},_handleRequest:function(E,F){var D=this.get("source");if(A.isUndefined(D)){F.error=true;}if(F.error){this.fire("error",null,F);}this.fire("data",null,C.mix(F,{data:D}));},_handleData:function(D,E){E.results=E.data;if(!E.results){E.results=[];}if(!E.meta){E.meta={};}this.fire("response",null,E);},_handleResponse:function(D,E){B.issueCallback(E);},sendRequest:function(D,F){var E=B._tId++;this.fire("request",null,{tId:E,request:D,callback:F});return E;}});C.DataSource=B;},"@VERSION@",{requires:["base"]});YUI.add("datasource-xhr",function(B){var A=function(){A.superclass.constructor.apply(this,arguments);};B.mix(A,{NAME:"DataSource.XHR",ATTRS:{io:{value:B.io}}});B.extend(A,B.DataSource,{_handleRequest:function(E,F){var D=this.get("source"),C={on:{success:function(I,G,H){this.fire("data",null,B.mix(H,{data:G}));},failure:function(I,G,H){H.error=true;this.fire("error",null,B.mix(H,{data:G}));this.fire("data",null,B.mix(H,{data:G}));}},context:this,arguments:{tId:F.tId,request:F.request,callback:F.callback}};this.get("io")(D,C);return F.tId;}});B.DataSource.XHR=A;},"@VERSION@",{requires:["datasource-base"]});YUI.add("datasource-cache",function(C){var B=C.DataSource,A=function(){};A.ATTRS={cache:{value:null,validator:function(D){return((D instanceof C.Cache)||(D===null));},set:function(D){this.on("request",this._beforeRequest);this.on("response",this._beforeResponse);}}};A.prototype={_beforeRequest:function(E,F){var D=(this.get("cache")&&this.get("cache").retrieve(F.request,F.callback))||null;if(D&&D.response){E.stopImmediatePropagation();this.fire("response",null,C.mix(F,D.response));}},_beforeResponse:function(D,E){if(this.get("cache")){this.get("cache").add(E.request,E,(E.callback&&E.callback.argument));}}};C.Base.build(B,[A],{dynamic:false});},"@VERSION@",{requires:["datasource-base"]});YUI.add("datasource-dataparser",function(C){var B=C.DataSource,A=function(){};A.ATTRS={parser:{value:null,validator:function(D){return((D instanceof C.DataParser.Base)||(D===null));}}};A.prototype={_handleData:function(E,F){var D=(this.get("parser")&&this.get("parser").parse(F.data));if(!D){D={meta:{},results:F.data};}this.fire("response",null,C.mix(F,D));}};C.Base.build(B,[A],{dynamic:false});},"@VERSION@",{requires:["datasource","dataparser"]});YUI.add("datasource-polling",function(D){var B=D.Lang,A=D.DataSource,C=function(){};C.prototype={_intervals:null,setInterval:function(G,F,I){if(B.isNumber(G)&&(G>=0)){var E=this,H=setInterval(function(){E.sendRequest(F,I);},G);if(!this._intervals){this._intervals=[];}this._intervals.push(H);return H;}else{}},clearInterval:function(G){var F=this._intervals||[],E=F.length-1;for(;E>-1;E--){if(F[E]===G){F.splice(E,1);clearInterval(G);}}}};D.Base.build(A,[C],{dynamic:false});},"@VERSION@",{requires:["datasource-base"]});YUI.add("datasource",function(A){},"@VERSION@",{use:["datasource-base","datasource-xhr","datasource-cache","datasource-dataparser","datasource-polling"]});