recordset-min.js revision 3322431c6a880983db785beaa61932d3697116aa
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(H){var F=this._items.length,I=H.added,G=H.index;if(G===F){this._items.push(I);}else{this._items.splice(G,0,I);}},_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;F=(E.Lang.isNumber(G)&&(G>-1))?G:this._items.length;if(E.Lang.isArray(J)){I=[];for(H=0;H<J.length;H++){I[H]=this._changeToRecord(J[H]);this.fire("add",{added:I[H],index:F+H});}}else{if(E.Lang.isObject(J)){this.fire("add",{added:this._changeToRecord(J),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(C){var A=C.ArraySort.compare;function B(D,E,F){B.superclass.constructor.apply(this,arguments);}C.mix(B,{NS:"sort",NAME:"recordsetSort",ATTRS:{state:{value:{}},defaultSorter:{value:function(F,D,G,H){var E=A(F.getValue(G),D.getValue(G),H);if(E===0){return A(F.get("id"),D.get("id"),H);}else{return E;}}}}});C.extend(B,C.Plugin.Base,{initializer:function(D){this.publish("sort",{defaultFn:C.bind("_defSortFn",this)});},destructor:function(D){},_defSortFn:function(D){this.get("host").get("records").sort(function(F,E){return(D.sorter)(F,E,D.field,D.desc);});},defsort:function(D,E,F){this.fire("sort",{field:D,desc:E,sorter:F||this.get("defaultSorter")});},resort:function(){var D=this.get("state");this.fire("sort",{field:D.field,desc:D.desc,sorter:this.get("defaultSorter")});},reverse:function(){this.get("host").get("records").reverse();}});C.namespace("Plugin").RecordsetSort=B;},"@VERSION@",{requires:["recordset-base","arraysort","plugin"]});YUI.add("recordset-filter",function(C){var B=C.Array;function A(D){A.superclass.constructor.apply(this,arguments);}C.mix(A,{NS:"filter",NAME:"recordsetFilter",ATTRS:{}});C.extend(A,C.Plugin.Base,{initializer:function(D){},destructor:function(D){},filter:function(H,E){var G=this.get("host").get("records"),D=G.length,F=0,I=[];if(C.Lang.isFunction(H)&&E===undefined){I=B.filter(G,H);}else{if(C.Lang.isString(H)&&C.Lang.isValue(E)){for(;F<D;F++){if(G[F].getValue(H)===E){I.push(G[F]);}}}}return new C.Recordset({records:I});},reject:function(D){return new C.Recordset({records:B.reject(this.get("host").get("records"),D)});},grep:function(D){return new C.Recordset({records:B.grep(this.get("host").get("records"),D)});}});C.namespace("Plugin").RecordsetFilter=A;},"@VERSION@",{requires:["recordset-base","plugin","array-extras"]});YUI.add("recordset",function(A){},"@VERSION@",{use:["recordset-base","recordset-sort","recordset-filter"]});