recordset-min.js revision 46c91c32e9f555734bdd918e4157fb8a92746ae0
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:{}}});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){var G;if(F.index===0){this._items.pop();}else{this._items.splice(F.index,F.range);}},_defEmptyFn:function(F){this._items=[];},_defUpdateFn:function(H){var G=[],F=0;for(;F<H.updated.length;F++){G[F]=this._changeToRecord(data[F]);this._items[H.index+F]=G[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",{});});},_recordRemoved:function(G,F){this.fire("remove",{data:G,index:F});},_recordsetEmptied:function(){this.fire("empty",{});},_recordsetUpdated:function(I,G,F){var H={data:{updated:I,overwritten:G},index:F};this.fire("update",H);},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(K,G){var I,J=[],F,H;F=(E.Lang.isNumber(G)&&(G>-1))?G:this._items.length;if(E.Lang.isArray(K)){J=[];for(H=0;H<K.length;H++){J[H]=this._changeToRecord(K[H]);this.fire("add",{added:J[H],index:F+H});}}else{if(E.Lang.isObject(K)){this.fire("add",{added:this._changeToRecord(K),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,H){var G,J,F;F=(!(E.Lang.isArray(I)))?[I]:I;J=this._items.slice(H,H+F.length);this.fire("update",{updated:F,overwritten:J,index:H});return this;}},{ATTRS:{records:{validator:E.Lang.isArray,getter:function(){return E.Array(this._items);},setter:function(H){var G=[];function F(I){if(I instanceof E.Record){G.push(I);}else{o=new E.Record({data:I});G.push(o);}}E.Array.each(H,F);this._items=E.Array(G);},lazyAdd:false}}});E.augment(D,B);E.Recordset=D;},"@VERSION@",{requires:["base","record","collection"]});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:{lastSortProperties:{value:{field:undefined,desc:undefined,sorter:undefined}},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.set("lastSortProperties",D);this.get("host").get("records").sort(function(F,E){return(D.sorter)(F,E,D.field,D.desc);});},sort:function(D,E,F){this.fire("sort",{field:D,desc:E,sorter:F||this.get("defaultSorter")});},resort:function(){var D=this.get("lastSortProperties");this.fire("sort",{field:D.field,desc:D.desc,sorter:this.get("defaultSorter")});},reverse:function(){var E=this.get("host"),D=E.getLength()-1,G=0;for(;G<=D;G++){if(G<(D-G)){var H=E.getRecord(G);var F=E.getRecord(D-G);E.update(H,D-G);E.update(F,G);}}}});C.namespace("Plugin").RecordsetSort=B;},"@VERSION@",{requires:["recordset-base","arraysort","plugin"]});YUI.add("recordset-filter",function(B){function A(C){A.superclass.constructor.apply(this,arguments);}B.mix(A,{NS:"filter",NAME:"recordsetFilter",ATTRS:{}});B.extend(A,B.Plugin.Base,{initializer:function(C){},destructor:function(C){},alert:function(){alert("im working!!");},filter:function(E,D){var I=[],F=0,H,C,G;G=this.get("host");C=G.get("records").getLength();for(;F<C;F++){H=G.getRecord(F);if((B.Lang.isFunction(E)&&D===undefined&&E(H))||(B.Lang.isString(E)&&B.Lang.isValue(D)&&H.getValue(E)===D)){I.push(H);}}return new G.constructor({records:I});}});B.namespace("Plugin").RecordsetFilter=A;},"@VERSION@",{requires:["recordset-base","plugin"]});YUI.add("recordset",function(A){},"@VERSION@",{use:["recordset-base","recordset-sort","recordset-filter"]});