recordset-min.js revision 9953a3f753a2e339b567f75c2566788b828ac1d9
YUI.add("recordset",function(C){function A(D){A.superclass.constructor.apply(this,arguments);}A.NAME="record";A.ATTRS={id:{valueFn:"_setId",writeOnce:true},data:{}};C.extend(A,C.Base,{_setId:function(){return C.guid();},initializer:function(D){},destructor:function(){},getValue:function(D){if(D===undefined){return this.get("data");}else{return this.get("data")[D];}return null;}});C.Record=A;function B(D){B.superclass.constructor.apply(this,arguments);}B.NAME="recordset";B.ATTRS={records:{value:null,setter:"_setRecords"},length:{value:0,readOnly:true}};C.extend(B,C.Base,{_setRecords:function(F){var E=[];function D(G){E.push(new C.Record({data:G}));}C.Array.each(F,D);return E;},initializer:function(){this._recordsetChanged();},destructor:function(){},_add:function(E,D){D=(C.Lang.isNumber(D)&&(D>-1))?D:this.get("records").length;this.get("records").splice(D,0,E);return E;},_updateGivenArray:function(D,E,G){var F=0,I=[],H=[];for(;F<D.length;F++){H[F]=this._changeToRecord(D[F]);if(F===0){I[F]=this.get("records").splice(E,1,H[F])[0];console.log(this.get("records"));}else{I[F]=this._updateGivenObject(H[F],E+F,G).overwritten[0];if(I[F]===undefined){I.pop();}}}return({updated:H,overwritten:I});},_updateGivenObject:function(F,D,E){var H=[],G=[];H[0]=this._changeToRecord(F);if(E){G[0]=this.get("records").splice(D,1,H[0])[0];}else{this.get("records").splice(D,0,H[0]);}return({updated:H,overwritten:G});},_changeToRecord:function(E){var D;if(E instanceof C.Record){D=E;}else{D=new C.Record({data:E});}return D;},_recordsetChanged:function(){this.on(["recordsetUpdatedEvent","recordsetAddedEvent","recordsetRemovedEvent","recordsetEmptiedEvent"],function(){this.fire("recordsetChangedEvent",{});});},_recordAdded:function(E,D){this.fire("recordsetAddedEvent",{data:E,index:D});},_recordRemoved:function(E,D){this.fire("recordsetRemovedEvent",{data:E,index:D});},_recordsetEmptied:function(){this.fire("recordsetEmptiedEvent",{});},_recordsetUpdated:function(G,E,D){var F={data:{updated:G,overwritten:E},index:D};this.fire("recordsetUpdatedEvent",F);},getRecord:function(D){return this.get("records")[D];},getRecords:function(F,E){var G=0,D=[];E=(C.Lang.isNumber(E)&&(E>0))?E:1;for(;G<E;G++){D.push(this.get("records")[F+G]);}return D;},getValuesByKey:function(F){var E=0,D=this.get("records").length,G=[];for(;E<D;E++){G.push(this.getRecord(E).getValue(F));}return G;},filter:function(E){var G=[],D=0,F;for(;D<this.get("records").length;D++){F=this.getRecord(D);if(E(F)){G.push(F);}}return G;},add:function(I,E){var G,H=[],D,F;if(C.Lang.isArray(I)){H=[];D=(C.Lang.isNumber(E)&&(E>-1))?E:this.get("records").length;for(F=0;F<I.length;F++){G=new C.Record({data:I[F]});H[F]=this._add(G,D);D++;}}else{if(C.Lang.isObject(I)&&!(I instanceof C.Record)){G=new C.Record({data:I});H[0]=this._add(G,E);}else{if(I instanceof C.Record){H[0]=this._add(G,E);}}}this._recordAdded(H,E);return({data:H,index:E});},remove:function(E,D){var F=[];E=(C.Lang.isNumber(E)&&(E>-1))?E:this.get("records").length-1;D=(C.Lang.isNumber(D)&&(D>0))?D:1;F=this.get("records").splice(E,D);this._recordRemoved(F,E);return({data:F,index:E});},empty:function(){this.set("records").value=[];this._recordsetEmptied();return null;},update:function(G,D,E){var F;if(C.Lang.isArray(G)){F=this._updateGivenArray(G,D,E);}else{if(C.Lang.isObject(G)){F=this._updateGivenObject(G,D,true);}}this._recordsetUpdated(F.updated,F.overwritten,D);return null;},sort:function(E,F,D){}});C.Recordset=B;},"@VERSION@",{requires:["base","record"]});