(function(){"use strict";u8.Crm.Widgets.QueryCompactResultPresenter=function(e,t){var i=u8.tools.extend({},u8.Crm.Widgets.QueryCompactResultPresenter.defaults,t);if(t.grid){i.grid=$.extend(true,{},u8.Crm.Widgets.QueryCompactResultPresenter.defaults.grid,t.grid)}this.QueryResultPresenter(e,i);this._idLink=this.id+"_link";if(this.maxRows&&this.grid){this.grid.pageSize=this.maxRows}if(this.resultSet){this.resultSet.bind("Load",this._onResultSetLoad.bind(this),this._idLink)}};u8.Crm.Widgets.QueryCompactResultPresenter.defaults={displayMode:1,maxRows:20,parameterFormTemplateName:"QueryParametersTemplate",displayText:"{1}",grid:{view:{collapseInvisibleRows:true},header:false}};$.extend(u8.Crm.Widgets.QueryCompactResultPresenter.prototype,{dispose:function(){if(this.isDisposed){return}if(this.resultSet){this.resultSet.unbind("Load",this._idLink)}this.QueryResultPresenter_dispose()},_create:function(){if(this._isDisposed){return}this.empty();var e=this.$(this.element).addClass("u8-querycompactresultpresenter");if(this._isParameterFormRequired()){return this._createParameterForm()}if(!this._queryParameterForm){var t=this.$("<div/>").addClass("links").appendTo(e);var i=this.displayMode==2;if(i){this.$("<span />").addClass("u8-clickable u8-margin-right").sprite("u8-img-quickview-s").on("click",this._onPopupLinkClick.bind(this)).appendTo(t)}var s=this.displayMode==1||this.displayMode==2||this.displayMode==4;if(s){var r=this.$("<a id='"+this._idLink+"'></a>").on("click",this._onQueryLinkClick.bind(this));if(this.linkClassName||this.linkClassNameEmpty){if(this.linkClassNameEmpty&&this.resultSet.getNumberOfRows()<=0){r=this.$("<div class='"+this.linkClassNameEmpty+"' />").append(r)}else if(this.linkClassName){r=this.$("<div class='"+this.linkClassName+"' />").append(r)}}r.appendTo(t);this._updateLink()}if(this.displayMode==3||this.displayMode==4){this.$("<div id='"+this._idGrid+"'></div>").addClass("grid").appendTo(e);this._createGrid()}}else{this._queryParameterForm.setNumberOfRows(this.resultSet.getNumberOfRows(),this.maxRows);this._createGrid()}var a=this;u8.tools.createdWhenReady(this,function(){if(a.autoExecute){a.executeQuery()}})},_navigateToQueryRun:function(e){e=$.extend(e,{pageOptions:u8.tools.extendSome({},["query"],this)});u8.services.navigation.navigateToPage("QueryRun",{maxRows:this.queryRunMaxRows},e)},_showResultGridInPopup:function(){this._navigateToQueryRun({createNewPopup:true})},_updateLink:function(){var e;if(!this.resultSet.isLoaded()){e="?"}else if(this.resultSet.moreRowsExist){e=">"+this.maxRows.toString()}else{e=this.resultSet.getNumberOfRows().toString()}this._linkText=u8.format(this.displayText||"",{1:e});this.$("#"+this._idLink).text(this._linkText)},_onPopupLinkClick:function(e){this._showResultGridInPopup()},_onQueryLinkClick:function(e){this._navigateToQueryRun({createNewPopup:false,elEvent:e})},_onResultSetLoad:function(){this._updateLink()}});u8.Crm.Widgets.QueryCompactResultPresenter.makeClass({name:"QueryCompactResultPresenter",deriveFrom:u8.Crm.Widgets.QueryResultPresenter})})();