(function(){function m(a,b){if(a){a=a.firstChild;for(var c;a;a=a.nextSibling)(c=a.treerow)&&b<c.nChildren&&c.getChildAt(b).rerender(),m(a.treechildren,b)}}function n(a,b,c,f,p){for(var g=[],e=0,q=0,d=a.firstChild;d;d=d.nextSibling,q++){d.treechildren&&n(d.treechildren,b,c,f,p);for(var h=0,k=d.getFirstCell();k;k=k.nextSibling,h++)h==b&&(g[e++]={wgt:k,index:q})}var u="ascending"==c?-1:1;g.sort(function(r,t){var l=f(r.wgt,t.wgt,p)*u;0==l&&(l=r.index<t.index?-1:1);return l});e=0;for(h=g.length;e<h;e++)a.appendChild(g[e].wgt.parent.parent)}
zul.sel.Treecol=zk.$extends(zul.mesh.SortWidget,{getTree:function(){return this.parent?this.parent.parent:null},getMeshBody:function(){var a=this.getTree();return a?a.treechildren:null},checkClientSort_:function(a){var b;return!(!this.getMeshBody()||!(b=this.getTree())||"paging"==b._mold)&&this.$supers("checkClientSort_",arguments)},replaceCavedChildrenInOrder_:function(a){var b=this.getMeshWidget(),c=this.getMeshBody(),f=c.desktop;try{c.unbind(),n(c,this.getChildIndex(),this.getSortDirection(),this.sorting,
"client(number)"==this[a?"_sortAscending":"_sortDescending"]),this._fixDirection(a)}finally{a=b._syncingbodyrows;b._syncingbodyrows=!0;try{b.clearCache(),jq(b.$n("rows")).replaceWith(c.redrawHTML_()),c.bind(f),b._bindDomNode()}finally{b._syncingbodyrows=a}}},$define:{maxlength:[function(a){return!a||0>a?0:a},function(){this.desktop&&(this.rerender(),this.updateCells_())}]},updateCells_:function(){var a=this.getTree();if(a){var b=this.getChildIndex(),c=a.treefoot;m(a.treechildren,b);c&&b<c.nChildren&&
c.getChildAt(b).rerender()}},bind_:function(){this.$supers(zul.sel.Treecol,"bind_",arguments);var a;(a=this.$n())&&this.domListen_(a,"onMouseOver","_doSortMouseEvt").domListen_(a,"onMouseOut","_doSortMouseEvt");if(a=this.$n("cm")){var b=this.getTree();b&&(b._headercm=a);this.domListen_(a,"onClick","_doCheckmarkClick")}},unbind_:function(){var a;(a=this.$n())&&this.domUnlisten_(a,"onMouseOver","_doSortMouseEvt").domUnlisten_(a,"onMouseOut","_doSortMouseEvt");if(a=this.$n("cm")){var b=this.getTree();
b&&(b._headercm=null);this._checked=null;this.domUnlisten_(a,"onClick","_doCheckmarkClick")}this.$supers(zul.sel.Treecol,"unbind_",arguments)},_doSortMouseEvt:function(a){if("none"!=this.getSortAscending())jq(this.$n())["onMouseOver"==a.name?"addClass":"removeClass"](this.getZclass()+"-sort-over")},domContent_:function(){var a=this.$supers("domContent_",arguments),b=this.getTree();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.getTree();return null!=a&&this.parent.firstChild==this&&a._checkmark&&a._multiple&&!a._tree$noSelectAll},domLabel_:function(){return zUtl.encodeXML(this.getLabel(),{maxlength:this._maxlength})},_doCheckmarkClick:function(a){this._checked=!this._checked;var b=this.getTree(),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.getTree(),c=this.$n("cm");if(b&&b._checkmark&&(b=a.domTarget,b==c||b.parentNode==c))return;this.$supers("doClick_",arguments)}})})();
