(function(){"use strict";u8.Crm.Widgets.KpiDefinitionSelector=function(e,t){this.Widget(e,$.extend({},u8.Crm.Widgets.KpiDefinitionSelector.defaults,t));if(typeof this.pageSize=="undefined"){this.pageSize=u8.session.webConfigValues.getInt("Search.MaxResults",20)}this._isCreated=false;u8.using({texts:["KpiDefinitionSelector"]},this._create.bind(this))};u8.Crm.Widgets.KpiDefinitionSelector.makeClass({name:"KpiDefinitionSelector",deriveFrom:u8.Base.Widgets.Widget});u8.Crm.Widgets.KpiDefinitionSelector.defaults={headerName:"KpiDefinitionsSelect",headerGroupName:"Special",searchResultsListViewOptions:{model:{infoAreaId:"C000",fieldGroupName:"C000",fieldControlType:"List"},canEdit:true,autoLoad:true,header:{headerGroupName:"Special",headerName:"KpiDefinitionsSelectList"},grid:{showMiniDetails:false,showMenu:false,showQuickViewAction:false,useDefaultActionOnDblClick:true},defaultAction:"A_KpiDefinitionView",selectionMode:"multi",hideIfEmpty:false}};$.extend(u8.Crm.Widgets.KpiDefinitionSelector.prototype,{_create:function(){this.empty();this.headerId=this.id+"_header";this.filterFormId=this.id+"_filterForm";this.searchResultsId=this.id+"_searchResults";var e=["<div class='u8-panel'><div id='",this.headerId,"'></div><div id='",this.filterFormId,"'></div></div>","<div class='u8-panel' id='",this.searchResultsId,"' style='display: none;'></div>"].join("");this.$(this.element).html(e);this._createHeader();this._createFilterForm();this._isCreated=true},_createHeader:function(){if(this._header){this._header.dispose();this._header=null}var e={parent:this,headerName:this.headerName,headerGroupName:this.headerGroupName,onPreCreate:this._onHeaderPreCreate.bind(this)};if(this._filterForm){e.view={showCollapse:true};e.onCollapsedChange=this._onHeaderCollapsedChange.bind(this)}this._header=u8.widget("Header",this.$("#"+this.headerId),e)},_createFilterForm:function(){var e=$t("TXT_KpiDefinitionSelector_0");if(!e){return}if(this._filterForm){this._filterForm.dispose();this._filterForm=null}var t=e.split(",");this._filterForm=new u8.Base.Widgets.FilterForm(this.$("#"+this.filterFormId),{parent:this,defaultMaxRows:this.pageSize,onExecute:this._onFilterFormExecute.bind(this),filter:[{id:"KpiDefinitonName",label:t[0],maxLength:128,dataKey:"F7000",compareOperator:"=",attributes:{twoCol:true,autoWildcardSearch:true}},{id:"Infoarea",label:t[1],widget:{type:"KPIInfoAreaSelector",options:{prependEmptyValue:true}},compareOperator:"=",dataKey:"F7002",attributes:{oneCol:true}},{id:"SchedulerPeriod",label:t[2],dataType:"X",widget:{type:"CatalogInput",options:{infoAreaId:"C000",fieldId:7013}},maxLength:128,compareOperator:"=",dataKey:"F7013",attributes:{oneCol:true}},{id:"NextRunFrom",label:t[3],dataType:"D",compareOperator:">=",dataKey:"F7007",attributes:{oneCol:true}},{id:"NextRunTo",label:t[4],dataType:"D",compareOperator:"<=",dataKey:"F7007",attributes:{oneCol:true}}]})},_onHeaderCollapsedChange:function(e){this.$("#"+this.id+"_filterform").toggle(!e.getCollapsed())},_onHeaderPreCreate:function(e){u8.services.searchOptionProvider.addSettingsButton({owner:this,header:e,buttonName:"SearchSettingsGeneric",showLabel:true});u8.services.events.raise("u8.widgets.KpiDefinitionsSelector.onHeaderPreCreate",self,{header:e})},_createFilterString:function(e){var t="";if(e&&e.filter){for(var i=0;i<e.filter.length;i++){var r=e.filter[i];if(t!==""){t+=" and "}t+=r.dataKey+r.compareOperator+"'"+r.value+"'"}}var s="select from ('C000')";if(t!==""){s+=" where ("+t+")"}return s},_applyFilterToListView:function(e){if(!this._listView){this.searchResultsListViewOptions.parent=this;this.searchResultsListViewOptions.model.filter=e;this._listView=new u8.Crm.Widgets.ListView(this.$("#"+this.searchResultsId),this.searchResultsListViewOptions)}else{this._listView.model.filter=e;this._listView.model.update()}},_onFilterFormExecute:function(e,t){if(!this._isCreated){return}this._applyFilterToListView(this._createFilterString(t))}})})();