(function(){u8.Crm.Widgets.RepListInput=function(e,t){t=$.extend({},u8.Crm.Widgets.RepListInput.defaults,{searchProvider:this._createSearchProvider()},t);t.onItemCreate=this._onItemCreate.bind(this);this.ListInput(e,t);var s=this.value;if(typeof s!="undefined"){delete this.value;this.withoutEvents(this.setValue,s)}if(typeof this.autoCompleteMinChars=="undefined"){this.autoCompleteMinChars=u8.session.webConfigValues.getInt("Rep.AutocompleteCharacters")}this._typeIcons={Group:"u8-img-repgroup-s",Resource:"u8-img-resource-s"}};u8.Crm.Widgets.RepListInput.makeClass({name:"RepListInput",deriveFrom:u8.Base.Widgets.ListInput,override:["setValue","getValue"]});u8.Crm.Widgets.RepListInput.defaults={disabled:false,readonly:false,canSelectRep:true,canSelectGroup:false,canSelectResource:false};$.extend(u8.Crm.Widgets.RepListInput.prototype,{setValue:function(e,t){if(!this._isCreated){this.value=e}if(!e||e.length==0){this.ListInput_setValue(e,t);return}var s=[];var i=function(){this.ListInput_setValue(s,t)}.bind(this);var r={default:true};for(var n=0;n<e.length;n++){u8.services.reps.get(e[n],r,function(t,r,n){var u=n?n.rep:n.rep;if(u){s.push(this._repToItem(u))}if(s.length===e.length){i()}}.bind(this,n))}},getValue:function(){var e=this.ListInput_getValue();return e?e.map(Number):e},_getRep:function(e){return u8.services.reps.get(e,{default:true})},_onItemCreate:function(e,t){if(t.item&&typeof t.item.key!="number"){t.cancel=true}},_createSearchProvider:function(){return{search:this._searchToken.bind(this),abort:u8._.nop}},_searchToken:function(e,t){if(e.length<this.autoCompleteMinChars){t({});return{}}var s=this._repToItem.bind(this);var i={pattern:e,types:{All:false,Rep:this.canSelectRep,Group:this.canSelectGroup,Resource:this.canSelectResource},filterName:this.filterName,includeInactive:u8.services.reps.canSelectInactive("filter"),maxRows:u8.session.webConfigValues.getInt("Rep.MaxAutocompleteResults",50)};u8.services.reps.find(i,function(e,i){t({items:i.matches.map(s),moreRowsExist:false})});return{}},_repToItem:function(e){var t={};t[this.keyProperty]=e.repId;t[this.textProperty]=e.name||"";t[this.imageProperty]=this._typeIcons[e.type];return t}})})();