YUI.add("gallery-paginator-view",function(a){a.PaginatorModel=a.Base.create("paginatorModel",a.Model,[],{_npages:null,_subscr:null,initializer:function(){this._recalcPagnParams();this._subscr=[];this._subscr.push(this.after("totalItemsChange",this._recalcPagnParams));this._subscr.push(this.after("itemsPerPageChange",this._recalcPagnParams));this._subscr.push(this.on("pageChange",this._changePage));return this;},destructor:function(){a.Array.each(this._subscr,function(b){b.detach();});this._subscr=null;},_changePage:function(d){var b=d.newVal,c=true;if(b<1||!this.get("totalPages")||!this.get("itemsPerPage")){c=false;}if(this.get("totalPages")&&b>this.get("totalPages")){c=false;}if(c){this.set("lastPage",d.prevVal);}else{d.preventDefault();}},_recalcPagnParams:function(){var c=this.get("itemsPerPage"),b=this.get("totalItems");if(b&&c&&b>0&&c>0){np=Math.floor(b/c);if(b%c>0){np++;}this._npages=np;this.set("page",1);return true;}return false;},_getItemIndexStart:function(){return(this.get("page")-1)*this.get("itemsPerPage");},_getItemIndexEnd:function(){var b=this.get("totalItems"),c=this.get("itemIndexStart")+this.get("itemsPerPage");return(c>b)?b:c;}},{ATTRS:{totalItems:{value:null,validator:a.Lang.isNumber},itemsPerPage:{value:null,validator:a.Lang.isNumber},page:{value:1,validator:a.Lang.isNumber},lastPage:{value:null,validator:a.Lang.isNumber},totalPages:{value:null,validator:a.Lang.isNumber,getter:function(){return this._npages;}},itemIndexStart:{value:null,validator:a.Lang.isNumber,getter:"_getItemIndexStart"},itemIndexEnd:{value:null,validator:a.Lang.isNumber,getter:"_getItemIndexEnd"}}});a.PaginatorView=a.Base.create("paginatorView",a.View,[],{TMPL_PAGINATOR:'First | '+'Prev | '+"{pageLinks}"+' | Next | '+'Last',TMPL_LINK:'{page}',TMPL_basic:"{firstPage} {prevPage} {pageLinks} {nextPage} {lastPage}",TMPL_pglinks:"{pageLinks}",TMPL_selectRPP:'',TMPL_selectPage:'',TMPL_inputRPP:'',TMPL_inputPage:'',model:null,_pagHTML:null,_cssPre:"yui3-pagview",_classContainer:null,_classLinkPage:null,_classLinkPageList:null,_classLinkPageActive:null,_classSelectRPP:null,_classSelectPage:null,_classInputRPP:null,_classInputPage:null,_subscr:null,_myClassName:function(){if(arguments&&arguments.length>0){var c=this._cssPre;for(var b=0;b=h){f=h;}c+=a.Lang.sub(e,{page:(g+1),pageLinkClass:plClass||"",pageStartIndex:m,pageEndIndex:f});}}var k=this._pagHTML;o.setStyle("visibility","hidden");o.setHTML("");k=''+k+"
";var n=a.substitute(k,a.mix({pageLinks:c||"",pageLinkClass:this._classLinkPage,pagClass:this._classContainer,selectRowsPerPage:this.TMPL_selectRPP||"",selectPage:this.TMPL_selectPage||"",inputPage:this.TMPL_inputPage||"",inputRowsPerPage:this.TMPL_inputRPP||"",selectRPPClass:this._classSelectRPP,selectPageClass:this._classSelectPage,inputRPPClass:this._classInputRPP,inputPageClass:this._classInputPage},j.getAttrs()),null,true);o.append(n);o.setStyle("visibility","");this._processPageChange(b);this.fire("render");
return this;},_processPageChange:function(b){var g=this.get("model"),c=g.get("totalPages"),f=g.get("lastPage"),e=this.get("maxPageLinks"),m=this.get("container"),j=this.get("linkListOffset"),k=m.all("."+this._classLinkPageList);if(k&&this.get("linkHighLight")){var i=(k&&(b-1)'+this.get("pageLinkFiller")+""),d=a.Node.create(''+this.get("pageLinkFiller")+"");m.all("."+this._myClassName("more")).remove();var l=this._calcOffset(b,j);k.each(function(o,n){if(n==0&&this.get("alwaysShowFirst")||n==c-1&&this.get("alwaysShowLast")){return true;}if(n+1l.right){o.addClass(this._myClassName("hide"));}else{o.removeClass(this._myClassName("hide"));}},this);if(l.left-j>0){k.item(l.left-1).insert(h,"before");}if(l.right+j<=c){k.item(l.right-1).insert(d,"after");}return true;},_calcOffset:function(d,f){var c=this.get("model").get("totalPages"),b=(d-f<1)?1:(d-f),e=(d+f>c)?c:(d+f);return{left:b,right:e};},_disablePageSelector:function(b,e){b=(!a.Lang.isArray(b))?[b]:b;e=(e)?e:false;var d='[data-{suffix}="{sdata}"]',c=this.get("container");a.Array.each(b,function(g){var f=c.one(a.Lang.sub(d,{suffix:"pglink",sdata:g}));if(f){if(e){f.removeClass(this._myClassName("disabled"));}else{f.addClass(this._myClassName("disabled"));}}},this);},_setModel:function(b){if(!b){return;}this.model=b;return b;},_modelPageChange:function(c){var b=c.newVal;if(b){this._processPageChange(b);}},_modelStateChange:function(c){var b=c.newVal;if(b&&!c.silent){this.render();}},_updateRPPSelect:function(){var g=this.get("container"),c=this.get("model"),f=g.one("."+this._classSelectRPP),e=this.get("pageOptions");if(e&&f){if(a.Lang.isArray(e)){var d=f.getDOMNode().options;d.length=0;a.Array.each(e,function(h){var i=new Option(h);d[d.length]=i;});}}if(f){var b=(c&&c.get("itemsPerPage")===c.get("totalItems"))?true:false;var d=f.get("options");d.each(function(h){if(h.get("value")==c.get("itemsPerPage")||(h.get("value").search(/all/i)!==-1&&b)){h.set("selected",true);}},this);}if(g.one("."+this._classSelectPage)){this._updatePageSelect();}},_updatePageSelect:function(){var d=this.get("container"),b=this.get("model"),c=d.one("."+this._classSelectPage);},_inputChangePage:function(d){var b=d.target,f=+b.get("value")||1,c=this.get("model");if(f<1||f>c.get("totalPages")){f=1;b.set("value",f);}c.set("page",f);},_clickChangePage:function(h){var b=h.target,c=this.get("model");h.preventDefault();if(h.target.hasClass(this._myClassName("disabled"))||h.currentTarget.hasClass(this._myClassName("disabled"))){return;}var g=b.getData("pglink")||h.currentTarget.getData("pglink"),f=c.get("totalPages"),d=c.get("page");if(d&&d===g){return;}switch(g){case"first":g=1;break;case"last":g=f;break;case"prev":g=(!d)?1:(d===1)?f:d-1;break;case"next":g=(!d)?1:(d===f)?1:d+1;break;default:g=+g;}c.set("page",g);},_selectChangeRowOptions:function(c){var b=c.target,d=+b.get("value")||b.get("value");if(a.Lang.isString(d)&&d.toLowerCase()==="all"){d=this.get("model").get("totalItems");}this.get("model").set("itemsPerPage",d);this.render();}},{ATTRS:{model:{value:null,setter:"_setModel"},container:{value:null},pageOptions:{value:[10,20,"All"],validator:a.Lang.isArray},paginatorTemplate:{valueFn:function(){return this.TMPL_PAGINATOR;}},pageLinkTemplate:{valueFn:function(){return this.TMPL_LINK;}},linkHighLight:{value:true,validator:a.Lang.isBoolean},maxPageLinks:{value:9999,validator:a.Lang.isNumber},linkListOffset:{value:1,validator:a.Lang.isNumber},pageLinkFiller:{value:"...",validator:a.Lang.isString},alwaysShowFirst:{value:false,validator:a.Lang.isBoolean},alwaysShowLast:{value:false,validator:a.Lang.isBoolean},selectPageFormat:{value:"Page {page}",validator:a.Lang.isString},circular:{value:false,validator:a.Lang.isBoolean}}});},"gallery-2012.08.29-20-10",{skinnable:true,requires:["base-build","model","view","substitute"]});YUI.add("gallery-datatable-paginator",function(b){function a(){}a.ATTRS={paginator:{value:null,setter:"_setPaginator"},serverPaginationMap:{valueFn:"_defPagMap",setter:"_setPagMap",validator:b.Lang.isObject},paginationState:{valueFn:"_defPagState",setter:"_setPagState",getter:"_getPagState"},requestStringTemplate:{value:"",validator:b.Lang.isString},paginatorResize:{value:false,validator:b.Lang.isBoolean}};b.mix(a.prototype,{_mlistArray:null,_pagDataSrc:null,paginator:null,pagModel:null,initializer:function(){if(this.get("paginator")){this.paginator=this.get("paginator");this._eventHandles.paginator=[];this._eventHandles.paginator.push(this.data.after("response",this._afterMLResponse,this));if(this.paginator.get("model")){this.pagModel=this.get("paginator").get("model");this._eventHandles.paginator.push(this.pagModel.after("pageChange",b.bind(this._pageChangeListener,this)));}if(this.get("data")&&this.get("data").size()>0){this._setLocalData();}this._eventHandles.paginator.push(this.data.after(["load","change","add","remove","reset"],b.bind(this._dataChange,this)));this._eventHandles.paginator.push(b.Do.after(this._afterSyncUI,this,"_syncUI",this));this._eventHandles.paginator.push(this.after("renderView",this._notifyRender));}return this;},destructor:function(){b.Array.each(this._eventHandles.paginator,function(c){c.detach();});this._mlistArray=null;this._eventHandles.paginator=null;},processPageRequest:function(m,c){var j=this._mlistArray,o=this.get("paginator"),e=o.get("model"),p=e.get("itemsPerPage");var f,q,g;if(c){f=c.itemIndexStart;q=c.itemIndexEnd||f+p;}else{f=(m-1)*p;q=f+p;q=(q>j.length)?j.length:q;g=q-f+1;}if(this._pagDataSrc!=="local"){var l={},h=this._srvPagMapObj("itemIndexStart"),i=this._srvPagMapObj("totalItems"),d=this._srvPagMapObj("itemsPerPage");l[h]=f;l[d]=p;l["sortBy"]=b.JSON.stringify(this.get("sortBy")||{})||null;l=b.mix(l,this.pagModel.getAttrs(true));l["page"]=this.pagModel.get("page");}switch(this._pagDataSrc){case"ds":var n=this.get("requestStringTemplate")||"";this.datasource.load({request:b.Lang.sub(n,l)});break;case"mlist":case"rest":this.data.load(l);break;default:var k=j.slice(f,q);this.data.reset(k,{silent:true});this.syncUI();}this.resizePaginator();this.fire("pageUpdate",{state:c,view:o});},resizePaginator:function(){if(this.get("paginatorResize")!==true){return;}b.later(25,this,function(){this._syncPaginatorSize();});},dataReset:function(c){if(c instanceof b.ModelList){this._mlistArray=[];c.each(function(d){this._mlistArray.push(d.toJSON());},this);}else{if(b.Lang.isArray(c)){this._mlistArray=[];this._mlistArray=c;}}this.processPageRequest(this.pagModel.get("page"));return this;},_srvPagMapObj:function(f,d){var e=this.get("serverPaginationMap")||{},c=e[f];d=d||"to";if(c&&d=="to"&&c.toServer){c=c.toServer;}if(c&&d!="to"&&c.fromServer){c=c.fromServer;}return c;},_afterSyncUI:function(c){if(!this._pagDataSrc){this._dataChange({});}},_dataChange:function(c){if(this._pagDataSrc){return;}if(!this.datasource&&this.data.url&&!this._pagDataSrc){this._pagDataSrc="mlist";}if(this.datasource&&!this.data.url&&!this._pagDataSrc){this._pagDataSrc="ds";this._eventHandles.paginator.push(this.datasource.get("datasource").after(["*:response","response"],b.bind(this._afterDSResponse,this)));}if(!this._pagDataSrc&&c.models&&b.Lang.isArray(c.models)&&c.models.length>0){c.preventDefault();this._setLocalData(c);}},_setLocalData:function(){var c=this.get("data");this._pagDataSrc="local";this._mlistArray=[];c.each(function(d){this._mlistArray.push(d.toJSON());},this);this.pagModel.set("totalItems",c.size());this.processPageRequest(this.pagModel.get("page"));},_afterDSResponse:function(d){var f=d.response,c=this.get("serverPaginationMap")["totalItems"]||null;if(f.results&&f.results.length>0){if(c&&f.meta&&f.meta[c]&&f.meta[c]>0){this.pagModel.set("totalItems",f.meta[c]);}}this.resizePaginator();},_afterMLResponse:function(d){var c=this.get("serverPaginationMap")["totalItems"]||null;if(d.results&&d.results.length>0){if(c&&d.meta&&d.meta[c]&&d.meta[c]>0){this.pagModel.set("totalItems",d.meta[c]);}}this.resizePaginator();},_pageChangeListener:function(d){var c=+d.newVal||1;this.processPageRequest(c,this.pagModel.getAttrs(true));},_syncPaginatorSize:function(){var c=this.get("boundingBox").one("table");if(!c){return false;}this.paginator.get("container").setStyle("width",c.getComputedStyle("width"));this.fire("paginatorResize");return true;},_defPagMap:function(){return{totalItems:"totalItems",itemsPerPage:"itemsPerPage",page:"page",itemIndexStart:"itemIndexStart"};},_setPagMap:function(d){var c=this._defPagMap();return b.merge(c,d);},_defPagState:function(){var c={};if(this.get("paginator")&&this.get("paginator").model){c=this.get("paginator").model.getAttrs();c.sortBy=this.get("sortBy");}return c;},_getPagState:function(){var c=(this.pagModel)?this.pagModel.getAttrs(true):{};delete c.initialized;c.sortBy=this.get("sortBy");return c;},_setPagState:function(c){if(c.initialized!==undefined){delete c.initialized;}if(c.sortBy!==undefined){this.set("sortBy",c.sortBy);}if(this.pagModel){this.pagModel.setAttrs(c);}return c;},_setPaginator:function(c){if(!c){return;}this.paginator=c;this.initializer();return c;},_notifyRender:function(){if(this.get("paginatorResize")===true){this.resizePaginator();}this.fire("render");}});b.DataTable.Paginator=a;b.Base.mix(b.DataTable,[b.DataTable.Paginator]);},"gallery-2012.09.05-20-01",{requires:["base-build","datatable-base","event-custom"],skinnable:false});