recordset-min.js revision e81af05b77b6bb6ebfc812494de2d3a621272d90
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{return this.get("data")[F];}return null;}},{ATTRS:{id:{valueFn:"_setId"},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:this._defAddFn});this.publish("remove",{defaultFn:this._defRemoveFn});this.publish("empty",{defaultFn:this._defEmptyFn});this.publish("update",{defaultFn:this._defUpdateFn});this._recordsetChanged();this._syncHashTable();},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++;}}},_defRemoveFn:function(F){if(F.index===0){this._items.pop();}else{this._items.splice(F.index,F.range);}},_defEmptyFn:function(F){this._items=[];},_defUpdateFn:function(G){for(var F=0;F<G.updated.length;F++){this._items[G.index+F]=this._changeToRecord(G.updated[F]);}},_defAddHash:function(I){var H=this.get("table"),G=this.get("key"),F=0;for(;F<I.added.length;F++){H[I.added[F].get(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].get(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++){if(I.overwritten[F]){delete H[I.overwritten[F].get(G)];}H[I.updated[F].get(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].get(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",{});});},_syncHashTable:function(){this.after("add",function(F){this._defAddHash(F);});this.after("remove",function(F){this._defRemoveHash(F);});this.after("update",function(F){this._defUpdateHash(F);});this.after("update",function(F){this._defEmptyHash();});},getRecord:function(F){if(E.Lang.isString(F)){return this.get("table")[F];}else{if(E.Lang.isNumber(F)){return this._items[F];}}return null;},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",readOnly:true}}});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;},_defAddHash:function(D){var C=this.get("hashTables");B.each(C,function(E,F){B.each(D.added||D.updated,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||E.overwritten,function(H){C=H.getValue(G);if(C&&F[C]===H){delete F[C];}});});},_defUpdateHash:function(C){C.added=C.updated;C.removed=C.overwritten;this._defAddHash(C);this._defRemoveHash(C);},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];}});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"]});