text: BX.namespace("BX.Crm");if(typeof BX.Crm.EntityCounterManager==="undefined"){BX.Crm.EntityCounterManager=function(){this._id="";this._settings={};this._entityTypeId=0;this._codes=null;this._extras=null;this._counterData=null;this._serviceUrl="";this._isRequestRunning=false};BX.Crm.EntityCounterManager.prototype={initialize:function(t,e){this._id=BX.type.isNotEmptyString(t)?t:BX.util.getRandomString(4);this._settings=e?e:{};this._entityTypeId=BX.prop.getInteger(this._settings,"entityTypeId",0);this._codes=BX.prop.getArray(this._settings,"codes",[]);this._extras=BX.prop.getObject(this._settings,"extras",{});this._serviceUrl=BX.prop.getString(this._settings,"serviceUrl","");this._counterData={};BX.addCustomEvent("onPullEvent-main",BX.delegate(this.onPullEvent,this))},getId:function(){return this._id},getEntityTypeId:function(){return this._entityTypeId},getEntityTypeName:function(){return BX.CrmEntityType.resolveName(this._entityTypeId)},getCounterData:function(){return this._counterData},setCounterData:function(t){this._counterData=t},onPullEvent:function(t,e){if(t!=="user_counter"){return}var n=false;var i=BX.prop.getObject(e,BX.message("SITE_ID"),{});for(var s in i){if(!i.hasOwnProperty(s)){continue}if(this._codes.indexOf(s)<0){continue}if(BX.prop.getInteger(i,s,0)<0){n=true;break}}if(n){this.startRecalculationRequest()}},startRecalculationRequest:function(){if(this._isRequestRunning){return}this._isRequestRunning=true;BX.ajax({url:this._serviceUrl,method:"POST",dataType:"json",data:{ACTION:"RECALCULATE",ENTITY_TYPES:[BX.CrmEntityType.resolveName(this._entityTypeId)],EXTRAS:this._extras},onsuccess:BX.delegate(this.onRecalculationSuccess,this)})},onRecalculationSuccess:function(t){this._isRequestRunning=false;var e=BX.prop.getObject(t,"DATA",null);if(!e){return}this.setCounterData(BX.prop.getObject(e,BX.CrmEntityType.resolveName(this._entityTypeId),{}))}};BX.Crm.EntityCounterManager.instances={};BX.Crm.EntityCounterManager.create=function(t,e){var n=new BX.Crm.EntityCounterManager;n.initialize(t,e);this.instances[n.getId()]=n;return n}}