(function(){"use strict";u8.Crm.QuerySearchProvider=function(e){$.extend(this,e)};$.extend(u8.Crm.QuerySearchProvider.prototype,{search:function(e,t){var r={};this.query.load(function(i,n){if(this._shouldAbort(r,n,t)){return}this._buildFilterParameters(e);if(this.maxRows){this.query.maxRows=this.maxRows}if(this.catalogValueEncoding){this.query.catalogValueEncoding=this.catalogValueEncoding}this.query.execute({},function(e,i){if(this._shouldAbort(r,i,t)){return}var n=i.resultSet;var a=n.getNumberOfRows();var u,o=[];for(var s=0;s<a;s++){u=n.getRowAt(s);o.push({key:this._getRowKey(u),text:this._getRowText(u)})}t({items:o,moreRowsExist:n.moreRowsExist})}.bind(this))}.bind(this));return r},abort:function(e){e.abort=true},canExecute:function(e){this.query.load(function(){var t=true;if(!this.query.statement.isEmpty()){this.query.statement.each(function(e){if(e.infoAreaId&&!u8.services.schema.getInfoArea(e.infoAreaId).canView()){t=false}})}e(this,{canExecute:t})}.bind(this))},"QuickSearch.onHeaderClick":function(e){u8.services.navigation.navigateToPage("QueryRun",{queryStatement:this.query.getStatementString(),catalogValueEncoding:this.query.catalogValueEncoding})},_shouldAbort:function(e,t,r){if(!e.abort&&!t.error){return false}var i={};if(e.abort){i.abort=true}if(t.error){i.error=true}r(i);return true},_buildFilterParameters:function(e){var t=this.query.statement.at("root");if(!t||!t.filter){return}var r=t.getParameters();if(!r){return}var i=e?e.split(","):[];for(var n=0;n<r.length;n++){e=n<i.length?i[n]:undefined;if(i&&i.length==1&&this.useFirstSearchTermForAllParameters){e=i[0]}if(!e){e=undefined}if(e){e=e.trim()}if(e&&e.indexOf("*")<0){e+="*"}r[n].rValue._parameter={value:e}}},_getRowKey:function(e){return u8.recordUidToString(e.uids[0])},_getRowText:function(e){var t=e.values,r=[];for(var i=0;i<t.length;i++){if(t[i]!==""){r.push(t[i])}}return r.join(", ")}})})();