zul.sel.Listheader=zk.$extends(zul.mesh.SortWidget,{getListbox:_zkf=function(){return this.parent?this.parent.parent:null},$init:function(){this.$supers("$init",arguments);this.listen({onGroup:this},-1E3)},getMeshBody:_zkf,checkClientSort_:function(a){var b;return!(!(b=this.getMeshBody())||b.hasGroup())&&this.$supers("checkClientSort_",arguments)},$define:{maxlength:[function(a){return!a||0>a?0:a},function(){this.desktop&&(this.rerender(),this.updateCells_())}]},setVisible:function(a){this.isVisible()!=
a&&(this.$supers("setVisible",arguments),this.desktop&&this.smartUpdate("visible",a))},group:function(a,b){var c,g=this.getSortDirection();if(a){if("ascending"==g)return!1}else if("descending"==g)return!1;var m=a?this._sortAscending:this._sortDescending;if("fromServer"==m)return!1;if("none"==m)return b.stop(),!1;var n=this.getMeshWidget();if(!n||n.isModel()||!zk.feature.pe||!zk.isLoaded("zkex.sel"))return!1;var d=this.getMeshBody();if(!d)return!1;b.stop();b=d.desktop;var x=d.$n();try{d.unbind();if(d.hasGroup())for(var f=
d.getGroups(),e=f.length;0<=--e;)d.removeChild(f[e]);f=[];for(var y=this.getChildIndex(),q=e=0,z=n.getBodyWidgetIterator(),r;r=z.next();q++){var h=0;for(c=r.firstChild;c;c=c.nextSibling,h++)h==y&&(f[e++]={wgt:c,index:q})}var A="ascending"==g?-1:1,t=this.sorting,u="client(number)"==m;f.sort(function(a,b){var c=t(a.wgt,b.wgt,u)*A;0==c&&(c=a.index<b.index?-1:1);return c});for(var k=d.firstItem;k;k=d.nextItem(k))d.removeChild(k);var B=this.getChildIndex();e=0;for(h=f.length;e<h;e++){var l=f[e];if(!v||
0!=t(v.wgt,l.wgt,u)){if(c=l.wgt.parent.getChildAt(B))if(c.getLabel())var w=new zkex.sel.Listgroup({label:c.getLabel()});else{var p=c.firstChild;w=p&&p.$instanceof(zul.wgt.Label)?new zkex.sel.Listgroup({label:p.getValue()}):new zkex.sel.Listgroup({label:msgzul.GRID_OTHER})}d.appendChild(w)}d.appendChild(l.wgt.parent);var v=l}this._fixDirection(a)}finally{d.replaceHTML(x,b)}return!0},onGroup:function(a){var b=this.getSortDirection();"ascending"==b?this.group(!1,a):"descending"==b?this.group(!0,a):this.group(!0,
a)||this.group(!1,a)},updateCells_:function(){var a=this.getListbox();if(null!=a&&"select"!=a.getMold()){for(var b=this.getChildIndex(),c,g=a.getBodyWidgetIterator();c=g.next();)b<c.nChildren&&c.getChildAt(b).rerender();(c=a.listfoot)&&b<c.nChildren&&c.getChildAt(b).rerender()}},bind_:function(){this.$supers(zul.sel.Listheader,"bind_",arguments);var a=this.$n("cm"),b=this.$n();if(a){var c=this.getListbox();c&&(c._headercm=a);this.domListen_(a,"onClick","_doClick")}b&&this.domListen_(b,"onMouseOver",
"_doMouseOver").domListen_(b,"onMouseOut","_doMouseOut");(a=this.$n("btn"))&&this.domListen_(a,"onClick","_doMenuClick")},unbind_:function(){var a=this.$n("cm"),b=this.$n();if(a){var c=this.getListbox();c&&(c._headercm=null);this._checked=null;this.domUnlisten_(a,"onClick","_doClick")}b&&this.domUnlisten_(b,"onMouseOver","_doMouseOver").domUnlisten_(b,"onMouseOut","_doMouseOut");(a=this.$n("btn"))&&this.domUnlisten_(a,"onClick","_doMenuClick");this.$supers(zul.sel.Listheader,"unbind_",arguments)},
_doMouseOver:function(a){(this.isSortable_()||this.parent._menupopup&&"none"!=this.parent._menupopup)&&jq(this.$n()).addClass(this.$s("hover"))},_doMouseOut:function(a){if(this.isSortable_()||this.parent._menupopup&&"none"!=this.parent._menupopup)a=jq(this.$n()),a.hasClass(this.$s("visited"))||a.removeClass(this.$s("hover"))},_doClick:function(a){this._checked=!this._checked;var b=this.getListbox(),c=this.$n("cm");c=jq(c);this._checked?(c.addClass(this.$s("checked")),b.selectAll(!0,a)):(c.removeClass(this.$s("checked")),
b._select(null,a));b.fire("onCheckSelectAll",this._checked,{toServer:!0})},doClick_:function(a){var b=this.getListbox(),c=this.$n("cm");if(b&&b._checkmark&&(b=a.domTarget,b==c||b.parentNode==c))return;this.$supers("doClick_",arguments)},domContent_:function(){var a=this.$supers("domContent_",arguments),b=this.getListbox();null!=b&&this.parent.firstChild==this&&b._checkmark&&b._multiple&&!b._listbox$noSelectAll&&(a='<span id="'+this.uuid+'-cm" class="'+this.$s("checkable")+(b.$$selectAll?" "+this.$s("checked"):
"")+'"><i class="'+this.$s("icon")+' z-icon-check"></i></span>'+(a?"&nbsp;"+a:""));return a},domLabel_:function(){return zUtl.encodeXML(this.getLabel(),{maxlength:this._maxlength})}});
