var ASSTable=Class.create({initialize:function(a,c,b,d,e,f,g){this.domNodeName=b;this.domNode=$(b+"-display");$(b+"-pagination")&&(this.paginator=new ASSPaginator(this,b+"-pagination",f));e&&(this.filter=new ASSFilter(this,b));this.action=g?g:"view";$(b+"-tagcloud")&&(this.tagCloud=new ASSTagCloud(this,b+"-tagcloud"));this.hasFilters=e;this.filters="";this.getHandler=d;this.totalRows=-1;this.fetchedRows=[];this.limit=c;this.getUrl=a;this.lastoffset=1;this.recvReqNo=this.sendReqNo=0;this.observeSortableColumns();
this.showRows(1,c)},observeSortableColumns:function(){var a=this;$(this.domNodeName).select("th[class*\x3dsortable]").each(function(c){c.hasClassName("selected")&&(a.selectedColumn=c);c.hasClassName("desc")||c.hasClassName("asc")||c.addClassName("desc");Event.observe(c,"click",function(b){if(b.element().hasClassName("selected")){var d=b.element().hasClassName("asc")?"asc":"desc",e="asc"==d?"desc":"asc";b.element().removeClassName(d);b.element().addClassName(e)}else a.selectedColumn&&a.selectedColumn.removeClassName("selected"),
b.element().addClassName("selected"),a.selectedColumn=b.element();a.totalRows=-1;a.showRows(1,a.limit)})})},getSortURLFragment:function(){var a="\x26sort\x3d";$(this.domNodeName).select("th[class*\x3d'selected']")[0]&&(a+=$(this.domNodeName).select("th[class*\x3d'selected']")[0].getAttribute("rel"));a+="\x26dir\x3d";$(this.domNodeName).select("th[class*\x3d'selected']")[0]&&(a+=$(this.domNodeName).select("th[class*\x3d'selected']")[0].hasClassName("desc")?"desc":"asc");return a},getRows:function(a,
c,b,d){var e=this.getUrl+"\x26offset\x3d"+a+"\x26limit\x3d"+c+"\x26reqNo\x3d"+ ++this.sendReqNo;this.hasFilters&&(this.filters=this.filter.getFilters(),""!=this.filters&&void 0!=this.filters&&(e+=this.filters));"undefined"!=typeof this.tags&&0<this.tags.length&&this.tags.each(function(g){e+="\x26tag\x3d"+g});e+=this.getSortURLFragment();var f=this;$(this.domNodeName+"-ajax-loader").style.display="block";new Ajax.Request(e,{method:"get",onComplete:function(g){$(f.domNodeName+"-ajax-loader").style.display=
"none"},onSuccess:function(g){g=eval("("+g.responseText+")");g.reqNo<f.sendReqNo||(f.recvReqNo=g.reqNo,$(f.domNodeName+"-ajax-loader").style.display="none",f.tagCloud&&g.matchingtags&&f.tagCloud.updateTagCloud(g.tags,g.matchingtags),f.updateFetchedRows(g),f.displayRows(b,d))}})},updateFetchedRows:function(a){this.json=a;this.totalRows=a.totalrows;for(var c=a.offset;c<a.offset+a.returnedrows;++c)this.fetchedRows[c]=a.rows[c-a.offset]},clearDisplay:function(){for(var a=this.domNode;a.hasChildNodes();)a.removeChild(a.firstChild)},
displayRows:function(a,c){c=a+c-1;c>this.totalRows&&(c=this.totalRows);a=0<this.totalRows?a:0;var b="\x3cstrong\x3e"+a+"\x3c/strong\x3e - \x3cstrong\x3e"+c+"\x3c/strong\x3e out of \x3cstrong\x3e"+this.totalRows+"\x3c/strong\x3e";b=b.toLowerCase();$(this.domNodeName+"-limits").innerHTML="Results "+b;for(this.clearDisplay();a<=c;a++)this.fetchedRows[a]&&(b=this.getHandler(this.fetchedRows[a],a,this),this.domNode.appendChild(b),document.fire("xwiki:grid:newrow",b));this.paginator&&this.paginator.refreshPaginator()},
showRows:function(a,c){this.lastoffset=a;var b="request to display rows "+a+" to "+(a+c)+" \x3cbr /\x3e\n";if(-1==this.totalRows)return this.getRows(a,c,a,c),b+"table is empty so we get all rows";for(var d=-1,e=-1,f=a;f<a+c;++f)void 0==this.fetchedRows[f]&&(-1==d&&(d=f),e=f);-1==d?(b+="no need to get new rows \x3cbr /\x3e\n",this.displayRows(a,c)):(b+="we need to get rows "+d+" to "+(e+1)+" \x3cbr /\x3e\n",this.getRows(d,e-d+1,a,c));this.paginator&&this.paginator.refreshPaginator();return b},deleteAndShiftRows:function(a){for(i in this.fetchedRows)i>=
a&&(this.fetchedRows[i]=this.fetchedRows[""+(parseInt(i)+1)])},debugFetchedRows:function(){var a="";for(i in this.fetchedRows)void 0!=this.fetchedRows[i]&&(a+=i+" ");return a},deleteRow:function(a){this.deleteAndShiftRows(a);var c=this.lastoffset;a>this.totalRows-this.limit-1&&--c;0>=c&&(c=1);--this.totalRows;this.totalRows<this.limit?this.showRows(c,this.totalRows):this.showRows(c,this.limit);this.paginator&&this.paginator.refreshPaginator()}});
ASSPaginator=Class.create({initialize:function(a,c,b){this.table=a;this.domNode=$(c);this.max=b},refreshPaginator:function(){this.domNode.innerHTML="";for(var a=Math.ceil(this.table.totalRows/this.table.limit),c=this.max?this.max:a,b=Math.floor(this.table.lastoffset/this.table.limit)+1,d=Math.floor(b/c)*c-1,e=0>=d?1:d;e<=Math.min(d+c+1,a);e++){var f=(new Element("span",{"class":"pagenumber"})).update(e);b==e&&f.addClassName("selected");this.domNode.appendChild(f);this.domNode.appendChild(document.createTextNode(" "));
Event.observe(f,"click",function(g){this.gotoPage(g.element().innerHTML)}.bind(this))}},gotoPage:function(a){this.table.showRows((parseInt(a)-1)*this.table.limit+1,this.table.limit)},gotoPrevPage:function(){var a=Math.floor(this.table.lastoffset/this.table.limit)+1-1;0<a&&this.table.showRows((parseInt(a)-1)*this.table.limit+1,this.table.limit)},gotoNextPage:function(){var a=Math.floor(this.table.lastoffset/this.table.limit)+1+1;a<=Math.ceil(this.table.totalRows/this.table.limit)&&this.table.showRows((parseInt(a)-
1)*this.table.limit+1,this.table.limit)}});
ASSFilter=Class.create({initialize:function(a,c){this.table=a;this.filterNode=$(c);this.filters={};this.attachEventHandlers()},makeRefreshHandler:function(a){return function(){a.refreshContent()}},attachEventHandlers:function(){for(var a=this.filterNode.getElementsByTagName("input"),c=this.filterNode.getElementsByTagName("select"),b=0;b<a.length;b++)"text"==a[b].type?Event.observe(a[b],"keyup",this.makeRefreshHandler(this)):Event.observe(a[b],"click",this.makeRefreshHandler(this));for(b=0;b<c.length;b++)Event.observe(c[b],
"change",this.makeRefreshHandler(this))},getFilters:function(){var a=this.filterNode.getElementsByTagName("input");this.filters={};var c={},b;for(b in this.filters)c[b]=!0;for(b=0;b<a.length;b++){var d=a[b].name;"radio"==a[b].type||"checkbox"==a[b].type?a[b].checked&&(this.filters[d]=a[b].value.strip()):this.filters[d]=a[b].value.strip()}a=this.filterNode.getElementsByTagName("select");for(b=0;b<a.length;b++)this.filters[a[b].name]=a[b].value.strip();a="";for(d in this.filters)c[d]||""==this.filters[d]||
(a+="\x26"+d+"\x3d"+this.filters[d]);delete c;return a},refreshContent:function(){var a=this.getFilters();a!=this.table.filters&&(this.table.totalRows=-1,this.table.fetchedRows=[],this.table.filters=a,this.table.showRows(1,this.table.limit))}});
ASSTagCloud=Class.create({initialize:function(a,c,b){this.table=a;this.domNode=$(c);this.cloudFilter=!1;this.initModes();"array"==typeof b&&(this.tags=b,0<b.length&&this.updateTagCloud(b))},tags:[],matchingTags:[],popularityLevels:"notPopular notVeryPopular somewhatPopular popular veryPopular ultraPopular".split(" "),updateTagCloud:function(a,c){this.tags=a;this.matchingTags=c;this.matchingTagsMap=this.buildPopularityMap(this.matchingTags);"matching"==this.mode?this.displayTagCloud(this.matchingTags,
this.matchingTagsMap):this.cloudFilter||(this.tagsMap=this.buildPopularityMap(this.tags),this.displayTagCloud(this.tags,this.tagsMap),this.cloudFilter=!0)},initModes:function(){var a=this.domNode.down("input[value\x3d'filter']"),c=this.domNode.down("input[value\x3d'matching']");a.selected||c.selected||(c.selected="selected");this.mode=this.domNode.down("input[value\x3d'filter']").checked?"filter":"matching";Event.observe(a,"click",this.updateMode.bind(this));Event.observe(c,"click",this.updateMode.bind(this))},
updateMode:function(){this.mode=this.domNode.down("input[value\x3d'filter']").checked?"filter":"matching";"matching"==this.mode?(this.displayTagCloud(this.matchingTags,this.matchingTagsMap),this.cloudFilter=!1):(this.tagsMap=this.buildPopularityMap(this.tags),this.displayTagCloud(this.tags,this.tagsMap),this.cloudFilter=!0)},displayTagCloud:function(a,c,b){this.domNode.down(".xwiki-grid-tagcloud").innerHTML="";b=new Element("ol",{"class":"tagCloud"});for(var d,e=0;e<a.length;e++){d="";for(var f=c.keys().reverse(),
g=0;g<f.length;g++)if(a[e].count>=f[g]||g==f.length-1){d=c.get(f[g]);break}tagClass=d+("filter"==this.mode?" selectable":"");d=(new Element("span")).update(a[e].tag);var h=this;"filter"==this.mode&&Event.observe(d,"click",function(l){l.element().up("li").toggleClassName("selected");h.table.tags=h.getSelectedTags();h.table.totalRows=-1;h.table.fetchedRows=[];h.table.showRows(1,h.table.limit)});d=(new Element("li",{"class":tagClass})).update(d);d.appendChild(document.createTextNode(" "));b.appendChild(d)}this.domNode.down(".xwiki-grid-tagcloud").appendChild(b)},
getSelectedTags:function(){var a=[];this.domNode.select("li.selected").each(function(c){a.push(c.down("span").innerHTML)});return a},buildPopularityMap:function(a){var c=0,b=0,d=-1;a.each(function(k){c+=k.count;if(k.count<b||0===b)b=k.count;if(k.count>d||-1===d)d=k.count});a=c/a.length;var e=this.popularityLevels.length/2,f=(d-a)/e,g=b,h=(a-b)/e,l=!1,n=0,m,p=new Hash;this.popularityLevels.each(function(k){n++;n>e&&!l&&(h=f,l=!0);m=g+h;p.set(m,k);g=m});return p}});
browser.isIE6x&&document.observe("xwiki:grid:newrow",function(a){Element.select(a.memo,"td").each(function(c){Event.observe(c,"mouseover",function(b){b.element().addClassName("editableCellHover")});Event.observe(c,"mouseout",function(b){b.element().removeClassName("editableCellHover")})});Event.observe(a.memo,"mouseover",function(c){c.element().up("tr").addClassName("rowHover")});Event.observe(a.memo,"mouseout",function(c){c.element().up("tr").removeClassName("rowHover")})});