(function(){u8.Crm.Widgets.AnalysisResultGrid=function(e,t){this.Widget(e,$.extend({},u8.Crm.Widgets.AnalysisResultGrid.defaults,t));$assert(this.model,"Failed to create widget 'AnalysisResultGrid'! Missing property 'model'.");this.model.bind("Execute",this._onModelExecute.bind(this),this.id);this._createDrillMenu=u8.Crm.Widgets.AnalysisResult.createDrillMenu;this._create()};u8.Crm.Widgets.AnalysisResultGrid.defaults={pageSize:10};u8.Crm.Widgets.AnalysisResultGrid.makeClass({name:"AnalysisResultGrid",deriveFrom:u8.Base.Widgets.Widget});$.extend(u8.Crm.Widgets.AnalysisResultGrid.prototype,{dispose:function(){if(this._isDisposed){return}this.model.unbind("*",this.id);this.Widget_dispose()},setCategory:function(e){this.category=e;this.update()},hasCategory:function(){return this.category!==null&&this.category!==undefined},update:function(){this._createModel();this._createView()},_createModel:function(){var e=this.model&&this.model.result;if(e){if(!this.hasCategory()){var t=e.buildGridModel();this._gridModel=u8.create("GridModel",{columns:t.columns,selectionMode:"single",superLabel:t.superLabel,footerRows:t.totalsRow?[{dataKey:0,actions:null,fn:u8._.attr("totalsRow")}]:[],pageSize:this.pageSize,rowActionCount:1,rowDefaults:{fn:function(e,t){return e.rows[t]},actions:[{name:"menu",image:"u8-img-contextmenu-s",tooltip:$t("TXT_net_ListIconLabels_4")}]}});this._gridModel.setData(t,{createRows:true,rowCount:t.rows.length})}else{this._resultSet=e.buildResultSet({cat:this.category})}this._captionsModel=e.buildCaptions({cat:this.category})}else{this._gridModel=null;this._resultSet=null;this._captionsModel=null}var i=this.model.settings;this._drillsModel=i&&i.getDrills()},_create:function(){if(!this.model.isLoaded){return}this.update()},_createView:function(){this.empty();this._$result=this.$("<div />").addClass("u8-analysisresult-grid").appendTo(this.element);if(this.hasCategory()){this._resultSetGrid=u8.create("ResultSetGrid",this._$result,{parent:this,resultSet:this._resultSet,pageSize:this.pageSize,selectionMode:"single",view:{header:{headerGroupName:"Special",headerName:"AnalysisResultGrid",parameters:{NumberOfRows:this._resultSet.getNumberOfRows()}}},executeOptions:{createNewTab:true}})}else if(this._gridModel){var e=this.model.analysis.maxBars||0;this._grid=u8.create("Grid",this._$result,{parent:this,model:this._gridModel,gridLayout:this.gridLayout,showPaging:e<=0||this.pageSize<e,onRowAction:this._onGridRowAction.bind(this),emptyGridText:$t("TXT_StatisticControllerText_12"),header:{headerGroupName:"Special",headerName:"AnalysisResultGrid",parameters:{NumberOfRows:this._gridModel.getRowCount()}}})}},_onModelExecute:function(){this.category=null;this.update()},_onGridRowAction:function(e,t){var i=t.rowIndex,s=e.model.getRowData(i),r=s.cat,a=this.model.settings.getDrillDowns({cat:r});if(s.label=="#null"){a=null}var o=this._createDrillMenu(a,s,$t("TXT_StatisticControllerText_30"));if(!o){return}o.alignTo=t.elSource;o.disposeOnHide=true;o.show()},"Command.Analysis/SetCategory":function(e,t,i){this.attr("category",i.commandArguments&&i.commandArguments.cat)},"Command.Analysis/ClearCategory":function(){this.attr("category",null)},"Command.Export":function(e,t,i){i.stopPropagation=false;if(this.hasCategory()){i.commandArguments.category=this.category}}})})();