(function(){zul.mesh.ColumnMenuWidget=zk.$extends(zul.mesh.HeadWidget,{_menupopup:"none",_columnshide:!0,_columnsgroup:!0,$define:{columnshide:_zkf=function(){this.desktop&&this._initColMenu()},columnsgroup:_zkf,menupopup:function(){"auto"!=this._menupopup&&"auto-keep"!=this._menupopup&&(this._mpop=null);this.rerender()}},bind_:function(b,a,c){this.$supers(zul.mesh.ColumnMenuWidget,"bind_",arguments);zWatch.listen({onResponse:this});var d=this;"auto"!=this._menupopup&&"auto-keep"!=this._menupopup||
c.push(function(){d._initColMenu()})},unbind_:function(){zWatch.unlisten({onResponse:this});this._mpop&&("auto-keep"!=this._menupopup&&this._mpop.parent.removeChild(this._mpop),this._shallColMenu=this._mpop=null);this.$supers(zul.mesh.ColumnMenuWidget,"unbind_",arguments)},onResponse:function(){this._shallColMenu&&this.syncColMenu()},_syncColMenu:function(){this._shallColMenu=!0},_initColMenu:function(){this._mpop&&this._mpop.parent.removeChild(this._mpop);this._mpop=new zul.mesh.ColumnMenupopup({columns:this});
"auto-keep"==this._menupopup&&(this._mpop._keepOpen=!0)},syncColMenu:function(){this._shallColMenu=!1;this._mpop&&this._mpop.syncColMenu()},_onColVisi:function(b){b=b.currentTarget;var a=b.parent;"auto-keep"!=this._menupopup&&a.close({sendOnOpen:!0});var c=0;for(a=a.firstChild;a;a=a.nextSibling)a.$instanceof(zul.menu.Menuitem)&&a.isChecked()&&c++;0==c&&b.setChecked(!0);(c=zk.Widget.$(b._col))&&c.parent==this&&((a=this.getMeshWidget())&&a.isSizedByContent()&&a.clearCachedSize_(),c.setVisible(b.isChecked()))},
_onGroup:function(b){var a;(a=b.target.parent._ungroup)&&a.setVisible(!0);this._mref.fire("onGroup","ascending"!=this._mref.getSortDirection(),{toServer:!0})},_onUngroup:zk.$void,_onAsc:function(b){this._mref.fire("onSort",!0)},_onDesc:function(b){this._mref.fire("onSort",!1)},_onMenuPopup:function(b){var a=this._mref;a&&jq(a.$n()).removeClass(a.$s("visited")).removeClass(a.$s("hover"));this._mref=b.data.reference},onChildAdded_:function(b){this.$supers("onChildAdded_",arguments);this._syncColMenu();
var a=this.getMeshWidget();a&&a._syncEmpty&&a._syncEmpty()},onChildRemoved_:function(b){this.$supers("onChildRemoved_",arguments);this.childReplacing_||this._syncColMenu();var a=this.getMeshWidget();a&&a._syncEmpty()},getGroupPackage_:zk.$void,domClass_:function(b){var a="";"none"!=this._menupopup&&(a+=this.$s("menupopup")+" ");return a+this.$supers("domClass_",arguments)}});zul.mesh.ColumnMenupopup=zk.$extends(zul.menu.Menupopup,{$define:{columns:null},$init:function(){this.$supers("$init",arguments);
this.afterInit(this._init)},getAscitem:function(){return this._asc},getDescitem:function(){return this._desc},getGroupitem:function(){return this._group},getUngroupitem:zk.$void,_init:function(){var b=this._columns;this.listen({onOpen:[b,b._onMenuPopup]});if(zk.feature.pe&&b.isColumnsgroup()){zk.isLoaded(b.getGroupPackage_())||zk.load(b.getGroupPackage_());var a=new zul.menu.Menuitem({label:msgzul.GRID_GROUP,visible:!1});a.setSclass(b.$s("menugrouping"));a.listen({onClick:[b,b._onGroup]});this.appendChild(a);
this._group=a;zk.feature.ee&&(a=new zul.menu.Menuitem({label:msgzul.GRID_UNGROUP,visible:!1}),a.setSclass(b.$s("menuungrouping")),a.listen({onClick:[b,b._onUngroup]}),this.appendChild(a),this._ungroup=a)}a=new zul.menu.Menuitem({label:msgzul.GRID_ASC});a.setSclass(b.$s("menuascending"));a.listen({onClick:[b,b._onAsc]});this._asc=a;this.appendChild(a);a=new zul.menu.Menuitem({label:msgzul.GRID_DESC});a.setSclass(b.$s("menudescending"));a.listen({onClick:[b,b._onDesc]});this._desc=a;this.appendChild(a);
this.syncColMenu();b.getPage().appendChild(this)},syncColMenu:function(){for(var b=this._columns,a=this.lastChild,c;a!=this._desc;)c=a.previousSibling,this.removeChild(a),a=c;if(b&&b.isColumnshide())for(a=new zul.menu.Menuseparator,this.appendChild(a),a=b.firstChild;a;a=a.nextSibling)c=new zul.menu.Menuitem({label:a.getLabel(),autocheck:!0,checkmark:!0,checked:a.isVisible()}),c._col=a.uuid,c.listen({onClick:[b,b._onColVisi]}),this.appendChild(c)}})})();
