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=this.getSortDirection();if(a){if("ascending"==c)return!1}else if("descending"==c)return!1;var h=a?this._sortAscending:this._sortDescending;if("fromServer"==h)return!1;if("none"==h)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 A=d.$n();try{d.unbind();if(d.hasGroup())for(var g=
d.getGroups(),e=g.length;0<=--e;)d.removeChild(g[e]);g=[];for(var B=this.getChildIndex(),r=e=0,C=n.getBodyWidgetIterator(),t;t=C.next();r++)for(var k=0,f=t.firstChild;f;f=f.nextSibling,k++)k==B&&(g[e++]={wgt:f,index:r});var D="ascending"==c?-1:1,u=this.sorting,v="client(number)"==h;g.sort(function(w,x){var p=u(w.wgt,x.wgt,v)*D;0==p&&(p=w.index<x.index?-1:1);return p});for(var l=d.firstItem;l;l=d.nextItem(l))d.removeChild(l);var E=this.getChildIndex();e=0;for(k=g.length;e<k;e++){var m=g[e];if(!y||
0!=u(y.wgt,m.wgt,v)){if(f=m.wgt.parent.getChildAt(E))if(f.getLabel())var z=new zkex.sel.Listgroup({label:f.getLabel()});else{var q=f.firstChild;z=q&&q.$instanceof(zul.wgt.Label)?new zkex.sel.Listgroup({label:q.getValue()}):new zkex.sel.Listgroup({label:msgzul.GRID_OTHER})}d.appendChild(z)}d.appendChild(m.wgt.parent);var y=m}this._fixDirection(a)}finally{d.replaceHTML(A,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,h=a.getBodyWidgetIterator();c=h.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();this._hasCheckbox()&&(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},_hasCheckbox:function(){var a=this.getListbox();return null!=a&&this.parent.firstChild==this&&a._checkmark&&a._multiple&&!a._listbox$noSelectAll},domLabel_:function(){return zUtl.encodeXML(this.getLabel(),{maxlength:this._maxlength})},getContentWidth_:function(){var a=zk(this.$n("cave")),b=this.nChildren||this._iconSclass||this._hasCheckbox()?a.textSize()[0]:a.textWidth();return Math.ceil(b+a.padBorderWidth()+zk(this.$n()).padBorderWidth())}});
