(function(){"use strict";var e=2e3;u8.Crm.Widgets.BuyingCenter=function(e,t){this.Widget(e,$.extend({},u8.Crm.Widgets.BuyingCenter.defaults,t));if(!u8.tools.isInstanceOfClass(this.model,"RecordWallModel")){this.model=u8.create("RecordWallModel",$.extend({__creator:this},this.model))}this.model.bind("Delete",this._onModelDelete.bind(this),this.id);this.commandBindings={Delete:this._onCommandDelete.bind(this)};this._isCreated=false;this._create()};u8.Crm.Widgets.BuyingCenter.defaults={settingsName:"BuyingCenter"};u8.Crm.Widgets.BuyingCenter.makeClass({name:"BuyingCenter",events:["Create"],deriveFrom:u8.Base.Widgets.Widget});$.extend(u8.Crm.Widgets.BuyingCenter.prototype,{dispose:function(){if(this._isDisposed){return}this.$(this.element).off("."+this.id);if(this.model){this.model.unbind("*",this.id);if(this.model.__creator===this){this.model.dispose()}}this.element.classList.remove("u8-buyingcenter");this.Widget_dispose()},_create:function(){Function.chain(this._using,this._createView).call(this,function(){this.$(this.element).on("resize."+this.id,this.layout.ifAlive(this).uncurry().despam());u8.tools.createdWhenReady(this,this.layout.bind(this).uncurry());this._createRelatedView.ifAlive(this).defer(e)})},_using:function(e){u8.using({templates:[{name:"u8-buyingCenter",url:"~/crm/BuyingCenter.utml.htm"}]},e)},_createView:function(e){this.empty();var t={name:"dock",settingsName:this.settingsName+"/SidebarLayout",expandos:{left:true,bottom:{open:false}}};var i=this.model.uid.infoAreaId;var s="application/x-vnd-update-buyingcenter-suggestion";this._viewModel={name:"u8-buyingCenter",itemOptions:{parent:this},data:{id:this.id,isDefault:this.isDefault,headerModel:this.showHeader!==false&&$.extend(true,{},this.header,{id:this.id+"_header",context:this.model,headerName:"Expand",headerGroupName:i+".BuyingCenter",alternateHeaders:[{headerName:"Expand",headerGroupName:i}],uid:this.model.uid,isDefault:this.isDefault,element:{attr:{"data-style":"page"}}}),sidebarModel:this.showSidebar!==false&&$.extend({},this.sidebarOptions,{id:this.id+"_sidebar",model:this.model,suggestionDataType:s}),wallModel:$.extend({},this.wallOptions,{id:this.id+"_view",model:this.model,itemOptions:{expandName:this.model.childInfoAreaId+".BuyingCenter"},externalDropDataTypes:[s]}),relatedViewModel:this.showRelatedView!==false&&$.extend({},this.relatedViewOptions,{id:this.id+"_related",value:this.model.uid,headerName:"ExpandChildren",headerGroupName:i+".BuyingCenter",alternateHeaders:[{headerName:"ExpandChildren",headerGroupName:i}],infoAreaId:i,dashboardPanel:{layout:"2Columns"},parent:this})}};var a=this;this.$(this.element).addClass("u8-buyingcenter").attr("data-infoareaid",this.model.uid.infoAreaId).utml(this._viewModel,function(){u8.Base.Dom.layout(a.element,t);var e=a._onExpando.bind(a);a.$(".left").on("open close",e.curry("left"));a.$(".bottom").on("open close",e.curry("bottom"))}.chain(e))},_createRelatedView:function(){var e=this.$("#"+this.id+"_related");if(!e.length){return}var t=e.data("expando");if(!t||!t.open){return}var i=e.widget();if(!i.length){e.widget("RelatedView",this._viewModel.data.relatedViewModel)}},_getWallWidget:function(){return this.getWidget("view")},_onExpando:function(e,t){if(this._isCreated===false){return}if(e=="bottom"&&t.type=="open"){this._createRelatedView()}var i=this._getWallWidget();if(i){i.update("all")}},_onCommandDelete:function(){this.model.deleteRecord()},_onModelDelete:function(){this._error("TXT_delete_text_0")},_error:function(e){this.empty();this.$("<div/>").addClass("u8-panel u8-margin").appendTo(this.element).widget("Message",{parent:this,image:"Error",message:e,buttons:this.isDefault?"Back":null,eatCommands:false})}})})();