recordset-min.js revision 8d1fe12a5d98f50455e314225925f342e641ae9b
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",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++;}}},_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]);}},_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._items[F];},getRecords: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(H,G){var I,F;F=(!(E.Lang.isArray(H)))?[H]:H;I=this._items.slice(G,G+F.length);this.fire("update",{updated:F,overwritten:I,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}}});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:{hash:{valueFn:"_setDefaultHash",lazyAdd:false},defaultKey:{value:"id",setter:"_setDefaultKey"}}});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){},_setDefaultHash:function(){var D=this.get("host"),E={},C=this.get("defaultKey");D.each(function(){E[this.get(C)]=this;});return E;},_setDefaultKey:function(C){},_defAddHash:function(F){var E=this.get("hash"),D=this.get("defaultKey"),C=0;for(;C<F.added.length;C++){E[F.added[C].get(D)]=F.added[C];}},_defRemoveHash:function(F){var E=this.get("hash"),D=this.get("defaultKey"),C=0;for(;C<F.removed.length;
C++){delete E[F.removed[C].get(D)];}},_defUpdateHash:function(F){var E={},D=this.get("defaultKey"),C=0;for(;C<F.updated.length;C++){delete E[F.overwritten[C].get(D)];E[F.updated[C].get(D)]=F.updated[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"]});