recordset-min.js revision 5d8d3401ad8bc8975c27975c7fffc1c4d18cf81c
YUI.add("recordset-base",function(E){var A=E.Base.create("record",E.Base,[],{_setId:function(){return E.guid();},initializer:function(F){},destructor:function(){},getValue:function(F){if(F===undefined){return this.get("data");}else{if(F==="id"){return this.get("id");}else{return this.get("data")[F];}}return null;}},{ATTRS:{id:{valueFn:"_setId",writeOnce:true},data:{value:null}}});E.Record=A;var B=E.ArrayList,C=E.bind,D=E.Base.create("recordset",E.Base,[],{initializer:function(){this.publish("add",{defaultFn:C("_defAddFn",this)});this.publish("remove",{defaultFn:C("_defRemoveFn",this)});this.publish("empty",{defaultFn:C("_defEmptyFn",this)});this.publish("update",{defaultFn:C("_defUpdateFn",this)});this._recordsetChanged();},destructor:function(){},_defAddFn:function(J){var F=this._items.length,I=J.added,G=J.index,H=0;for(;H<I.length;H++){if(G===F){this._items.push(I[H]);}else{this._items.splice(G,0,I[H]);G++;}}this._defAddHash(J);},_defRemoveFn:function(F){if(F.index===0){this._items.pop();}else{this._items.splice(F.index,F.range);}this._defRemoveHash(F);},_defEmptyFn:function(F){this._items=[];this._defEmptyHash();},_defUpdateFn:function(G){for(var F=0;F<G.updated.length;F++){this._items[G.index+F]=this._changeToRecord(G.updated[F]);}this._defUpdateHash(G);},_defAddHash:function(I){var H=this.get("table"),G=this.get("key"),F=0;for(;F<I.added.length;F++){H[I.added[F].getValue(G)]=I.added[F];}this.set("table",H);},_defRemoveHash:function(I){var H=this.get("table"),G=this.get("key"),F=0;for(;F<I.removed.length;F++){delete H[I.removed[F].getValue(G)];}this.set("table",H);},_defUpdateHash:function(I){var H=this.get("table"),G=this.get("key"),F=0;for(;F<I.updated.length;F++){delete H[I.overwritten[F].get(G)];H[I.updated[F].getValue(G)]=I.updated[F];}this.set("table",H);},_defEmptyHash:function(){this.set("table",{});},_setHashTable:function(){var I={},H=this.get("key"),G=0,F=this._items.length;for(;G<F;G++){I[this._items[G].getValue(H)]=this._items[G];}return I;},_changeToRecord:function(G){var F;if(G instanceof E.Record){F=G;}else{F=new E.Record({data:G});}return F;},_recordsetChanged:function(){this.on(["update","add","remove","empty"],function(){this.fire("change",{});});},getRecord:function(F){return this.get("table")[F];},getRecordByIndex:function(F){return this._items[F];},getRecordsByIndex:function(H,G){var I=0,F=[];G=(E.Lang.isNumber(G)&&(G>0))?G:1;for(;I<G;I++){F.push(this._items[H+I]);}return F;},getLength:function(){return this.size();},getValuesByKey:function(H){var G=0,F=this._items.length,I=[];for(;G<F;G++){I.push(this._items[G].getValue(H));}return I;},add:function(J,G){var I=[],F,H=0;F=(E.Lang.isNumber(G)&&(G>-1))?G:this._items.length;if(E.Lang.isArray(J)){for(;H<J.length;H++){I[H]=this._changeToRecord(J[H]);}}else{if(E.Lang.isObject(J)){I[0]=this._changeToRecord(J);}}this.fire("add",{added:I,index:F});return this;},remove:function(G,F){var H=[];G=(G>-1)?G:(this.size()-1);F=(F>0)?F:1;H=this._items.slice(G,(G+F));this.fire("remove",{removed:H,range:F,index:G});return this;},empty:function(){this.fire("empty",{});return this;},update:function(I,G){var J,F,H=0;F=(!(E.Lang.isArray(I)))?[I]:I;J=this._items.slice(G,G+F.length);for(;H<F.length;H++){F[H]=this._changeToRecord(F[H]);}this.fire("update",{updated:F,overwritten:J,index:G});return this;}},{ATTRS:{records:{validator:E.Lang.isArray,getter:function(){return E.Array(this._items);},setter:function(H){var G=[];function F(I){var J;if(I instanceof E.Record){G.push(I);}else{J=new E.Record({data:I});G.push(J);}}E.Array.each(H,F);this._items=E.Array(G);},lazyAdd:false},table:{valueFn:"_setHashTable"},key:{value:"id"}}});E.augment(D,B);E.Recordset=D;},"@VERSION@",{requires:["base","record","arraylist"]});YUI.add("recordset-sort",function(D){var A=D.ArraySort.compare,C=D.Lang.isValue;function B(E,F,G){B.superclass.constructor.apply(this,arguments);}D.mix(B,{NS:"sort",NAME:"recordsetSort",ATTRS:{lastSortProperties:{value:{field:undefined,desc:true,sorter:undefined},validator:function(E){return(C(E.field)&&C(E.desc)&&C(E.sorter));}},defaultSorter:{value:function(G,E,H,I){var F=A(G.getValue(H),E.getValue(H),I);if(F===0){return A(G.get("id"),E.get("id"),I);}else{return F;}}},isSorted:{value:false,valueFn:"_getState"}}});D.extend(B,D.Plugin.Base,{initializer:function(E){this.publish("sort",{defaultFn:D.bind("_defSortFn",this)});},destructor:function(E){},_getState:function(){var F=this.get("host"),E=D.bind(function(){this.set("isSorted",false);},this);this.on("sort",function(){this.set("isSorted",true);});this.onHostEvent("add",E,F);this.onHostEvent("update",E,F);},_defSortFn:function(E){this.set("lastSortProperties",E);this.get("host")._items.sort(function(G,F){return(E.sorter)(G,F,E.field,E.desc);});},sort:function(E,F,G){this.fire("sort",{field:E,desc:F,sorter:G||this.get("defaultSorter")});},resort:function(){var E=this.get("lastSortProperties");this.fire("sort",{field:E.field,desc:E.desc,sorter:E.sorter||this.get("defaultSorter")});},reverse:function(){this.get("host")._items.reverse();},flip:function(){var E=this.get("lastSortProperties");if(C(E.field)){this.fire("sort",{field:E.field,desc:!E.desc,sorter:E.sorter||this.get("defaultSorter")});}else{}}});D.namespace("Plugin").RecordsetSort=B;},"@VERSION@",{requires:["recordset-base","arraysort","plugin"]});YUI.add("recordset-filter",function(D){var C=D.Array,B=D.Lang;function A(E){A.superclass.constructor.apply(this,arguments);}D.mix(A,{NS:"filter",NAME:"recordsetFilter",ATTRS:{}});D.extend(A,D.Plugin.Base,{initializer:function(E){},destructor:function(E){},filter:function(J,F){var I=this.get("host").get("records"),E=I.length,G=0,K=[],H=J;if(B.isString(J)&&B.isValue(F)){H=function(L){if(L.getValue(J)===F){return true;}else{return false;}};}K=C.filter(I,H);return new D.Recordset({records:K});},reject:function(E){return new D.Recordset({records:C.reject(this.get("host").get("records"),E)});},grep:function(E){return new D.Recordset({records:C.grep(this.get("host").get("records"),E)});}});D.namespace("Plugin").RecordsetFilter=A;
},"@VERSION@",{requires:["recordset-base","plugin","array-extras"]});YUI.add("recordset-indexer",function(B){function A(C){A.superclass.constructor.apply(this,arguments);}B.mix(A,{NS:"indexer",NAME:"recordsetIndexer",ATTRS:{hashTables:{value:{}},keys:{value:{}}}});B.extend(A,B.Plugin.Base,{initializer:function(C){var D=this.get("host");this.onHostEvent("add",B.bind("_defAddHash",this),D);this.onHostEvent("remove",B.bind("_defRemoveHash",this),D);this.onHostEvent("update",B.bind("_defUpdateHash",this),D);},destructor:function(C){},_setHashTable:function(E){var F=this.get("host"),G={},D=0,C=F.getLength();for(;D<C;D++){G[F._items[D].getValue(E)]=F._items[D];}return G;},createTable:function(C){var D=this.get("hashTables");D[C]=this._setHashTable(C);this.set("hashTables",D);return D[C];},getTable:function(C){return this.get("hashTables")[C];},_defAddHash:function(D){var C=this.get("hashTables");B.each(C,function(E,F){B.each(D.added,function(G){if(G.getValue(F)){E[G.getValue(F)]=G;}});});},_defRemoveHash:function(E){var D=this.get("hashTables"),C;B.each(D,function(F,G){B.each(E.removed,function(H){C=H.getValue(G);if(F[C]==H){delete F[C];}});});},_defUpdateHash:function(F){var E=this.get("hashTables"),D,C;B.each(E,function(G,H){B.each(F.updated,function(J,I){D=J.getValue(H);if(F.overwritten[I]){overwritten=F.overwritten[I];}if(D){G[D]=J;}if((B.Lang.isValue(overwritten))&&(G[overwritten.getValue(H)]==overwritten)){delete G[overwritten.getValue(H)];}});});}});B.namespace("Plugin").RecordsetIndexer=A;},"@VERSION@",{requires:["recordset-base","plugin"]});YUI.add("recordset",function(A){},"@VERSION@",{use:["recordset-base","recordset-sort","recordset-filter","recordset-indexer"]});