(function(){"use strict";u8.Crm.Widgets.BuyingCenterSidebar=function(e,t){this.Widget(e,$.extend(true,{},u8.Crm.Widgets.BuyingCenterSidebar.defaults,t));this._isCreated=false;Function.chain(Function.chain.onDisposedAbort,Function.join(this._using,this._loadMissingRoleGroups,this._readSuggestionTypes),this._createView).call(this,u8.tools.createdWhenReady.curry(this))};u8.Crm.Widgets.BuyingCenterSidebar.makeClass({name:"BuyingCenterSidebar",deriveFrom:u8.Base.Widgets.Widget,events:["Create"]});u8.Crm.Widgets.BuyingCenterSidebar.defaults={theme:{css:{root:"u8-buyingcentersidebar",suggestions:{root:"u8-buyingcentersidebar-suggestions",selection:"u8-buyingcentersidebar-suggestions-selection"}}}};$.extend(u8.Crm.Widgets.BuyingCenterSidebar.prototype,{dispose:function(){if(this._isDisposed){return}this.Widget_dispose()},_loadMissingRoleGroups:function(e){var t=this;if(this.missingRoleGroups||!this.missingRoleGroupsId){return e&&e()}u8.request("BuyingCenterChannel.GetMissingRoleGroups",{id:this.missingRoleGroupsId},function(e,i){t.missingRoleGroups=i.response}.chain(e))},_using:function(e){u8.using({texts:["net_core_texts","BuyingCenter"],templates:[{name:"u8-buyingCenter-sidebar",url:"~/crm/BuyingCenterSidebar.utml.htm"}]},e)},_readSuggestionTypes:function(e){var t=this;u8.services.sales.readParticipantSuggestionTypes(this.model.uid.infoAreaId,function(e,i){t._suggestionItems=i.types||[]}.chain(e))},_createView:function(e){var t={name:"u8-buyingCenter-sidebar",itemOptions:{parent:this},data:{id:this.id,css:this.theme.css,button:{id:this.id+"_newParticipant",textId:"TXT_net_core_texts_394",onClick:this._onNewParticipantButtonClick.bind(this)},suggestions:this._suggestionItems&&{comboBox:{id:this.id+"_suggestionType",items:this._suggestionItems,onValueChange:this._updateSuggestions.bind(this)},button:{id:this.id+"_suggestionRefresh",image:"u8-img-refresh-s",tooltip:$t("TXT_net_core_texts_81"),disabled:true,onClick:this._updateSuggestions.bind(this)},recordListBox:{id:this.id+"_suggestions",dataProvider:u8.services.tableCaptions.createDataProvider(),showTableCaptionImage:true,pageSize:this.suggestionPageSize,showMenu:false,grid:{collapseInvisibleRows:true,showPaging:true,draggableModel:{dataType:this.suggestionDataType,start:this._doDragStart.bind(this)}}}},missingRoles:this.missingRoleGroups&&{id:this.id+"_missingRoles",value:this.missingRoleGroups,queryExecuteOptions:{link:this.model.uid}}}};this.$(this.element).addClass(this.theme.css.root).addClass("u8-vstack spaced-l").utml(t,e)},_onNewParticipantButtonClick:function(){u8.services.actions.execute("A_NewParticipant"+this.model.uid.infoAreaId+"_BuyingCenter",{arguments:{uid:this.model.uid}})},_updateSuggestions:function(){var e=this.getWidget("suggestionRefresh");var t=this.getWidget("suggestionType");var i=this.getWidget("suggestions");var s=i.getWidget("grid");var n=t.getValue();var r=n&&t.getItemByKey(n);e.setDisabled(true);s.emptyGridText=r?$t("TXT_BuyingCenter_5"):null;i.dataProvider.set("uids",[]);if(!r){return}u8.services.sales.readParticipantSuggestions(this.model.uid,r,function(t,n){e.setDisabled(false);s.emptyGridText=$t("TXT_BuyingCenter_6");i.dataProvider.set("uids",n.uids)})},_doDragStart:function(e,t){var i=u8.Base.Widgets.Tools.closest(t.elTarget,"RecordListBox");e.data.uids=i.getSelection("uids");e.data.onDragDrop=this._doDragDrop.bind(this);e.data.success=false;t.html=" "},_doDragDrop:function(e,t){var i=e.draggable.data.uids;if(!i||i.length<=0){return}this._addItemsToCategory(i,t.categoryId);e.draggable.data.success=true},_addItemsToCategory:function(e,t){var i=this;this.model.createItems(e,t,function(e,t){if(t.error){return}i.getWidget("suggestions").updateRows(t.links,{disabled:true})})}})})();