Your IP : 3.137.216.202
BX.namespace("BX.Crm");if(typeof BX.Crm.BatchDeletionManager==="undefined"){BX.Crm.BatchDeletionManager=function(){this._id="";this._settings={};this._gridId="";this._entityTypeId=BX.CrmEntityType.enumeration.undefined;this._entityIds=null;this._filter=null;this._operationHash="";this._containerId="";this._errors=null;this._progress=null;this._hasLayout=false;this._isRunning=false;this._progressChangeHandler=BX.delegate(this.onProgress,this);this._documentUnloadHandler=BX.delegate(this.onDocumentUnload,this);this._summaryLayoutHandler=BX.delegate(this.onSummaryLayout,this);this._summaryClearLayoutHandler=BX.delegate(this.onSummaryClearLayout,this)};BX.Crm.BatchDeletionManager.prototype={initialize:function(t,e){this._id=BX.type.isNotEmptyString(t)?t:"crm_batch_deletion_mgr_"+Math.random().toString().substring(2);this._settings=e?e:{};this._gridId=BX.prop.getString(this._settings,"gridId",this._id);this._entityTypeId=BX.prop.getInteger(this._settings,"entityTypeId",BX.CrmEntityType.enumeration.undefined);this._containerId=BX.prop.getString(this._settings,"container","");if(this._containerId===""){throw"BX.Crm.BatchDeletionManager: Could not find container."}this._progress=BX.AutorunProcessManager.create(this._id,{controllerActionName:"crm.api.entity.processDeletion",container:this._containerId,enableCancellation:true,title:this.getMessage("title"),timeout:1e3,stateTemplate:BX.prop.getString(this._settings,"stateTemplate","#processed# / #total#"),enableLayout:false});this._errors=[]},getId:function(){return this._id},getEntityIds:function(){return this._entityIds},setEntityIds:function(t){this._entityIds=BX.type.isArray(t)?t:[]},resetEntityIds:function(){this._entityIds=[]},getFilter:function(){return this._filter},setFilter:function(t){this._filter=BX.type.isPlainObject(t)?t:null},getMessage:function(t){var e=BX.prop.getObject(this._settings,"messages",BX.Crm.BatchDeletionManager.messages);return BX.prop.getString(e,t,t)},scrollInToView:function(){if(this._progress){this._progress.scrollInToView();this.refreshGridHeader()}},refreshGridHeader:function(){window.requestAnimationFrame(function(){var t=BX.Main.gridManager.getById(this._gridId);if(t&&t.instance&&t.instance.pinHeader){t.instance.pinHeader.refreshRect();t.instance.pinHeader._onScroll()}}.bind(this))},layout:function(){if(this._hasLayout){return}this._progress.layout();this._hasLayout=true},clearLayout:function(){if(!this._hasLayout){return}this._progress.clearLayout();this._hasLayout=false},getState:function(){return this._progress.getState()},getProcessedItemCount:function(){return this._progress.getProcessedItemCount()},getTotalItemCount:function(){return this._progress.getTotalItemCount()},execute:function(){var t=this._id.toLowerCase()+"_batch_delete";var e=BX.Crm.ConfirmationDialog.get(t);if(!e){e=BX.Crm.ConfirmationDialog.create(t,{title:this.getMessage("title"),content:this.getMessage("confirmation")})}if(!e.isOpened()){e.open().then(function(t){if(!BX.prop.getBoolean(t,"cancel",true)){this.layout();this.run();window.setTimeout(this.scrollInToView.bind(this),100)}}.bind(this))}},isRunning:function(){return this._isRunning},run:function(){if(this._isRunning){return}this._isRunning=true;BX.bind(window,"beforeunload",this._documentUnloadHandler);this.enableGridFilter(false);var t={gridId:this._gridId,entityTypeId:this._entityTypeId,extras:BX.prop.getObject(this._settings,"extras",{})};if(BX.type.isArray(this._entityIds)&&this._entityIds.length>0){t["entityIds"]=this._entityIds}BX.ajax.runAction("crm.api.entity.prepareDeletion",{data:{params:t}}).then(function(t){var e=BX.prop.getString(BX.prop.getObject(t,"data",{}),"hash","");if(e===""){this.reset();return}this._operationHash=e;this._progress.setParams({hash:this._operationHash});this._progress.run();BX.addCustomEvent(this._progress,"ON_AUTORUN_PROCESS_STATE_CHANGE",this._progressChangeHandler)}.bind(this))},stop:function(){if(!this._isRunning){return}this._isRunning=false;BX.ajax.runAction("crm.api.entity.cancelDeletion",{data:{params:{hash:this._operationHash}}});this.reset()},reset:function(){BX.unbind(window,"beforeunload",this._documentUnloadHandler);BX.removeCustomEvent(this._progress,"ON_AUTORUN_PROCESS_STATE_CHANGE",this._progressChangeHandler);this._isRunning=false;this._operationHash="";this._errors=[];var t=this._progress.getProcessedItemCount()>0;this._progress.reset();if(this._hasLayout){window.setTimeout(BX.delegate(this.clearLayout,this),100)}this.enableGridFilter(true);if(t){BX.Main.gridManager.reload(this._gridId)}},enableGridFilter:function(t){var e=this._gridId!==""?BX(this._gridId+"_search_container"):null;if(!e){return}if(t){BX.removeClass(e,"main-ui-disable")}else{BX.addClass(e,"main-ui-disable")}},getErrorCount:function(){return this._errors?this._errors.length:0},getErrors:function(){return this._errors?this._errors:[]},onDocumentUnload:function(t){return t.returnValue=this.getMessage("windowCloseConfirm")},onProgress:function(t){var e=this._progress.getState();if(e===BX.AutoRunProcessState.stopped){this.stop();return}var i=this._progress.getErrors();if(i.length>0){if(!this._errors){this._errors=i}else{this._errors=this._errors.concat(i)}}if(e===BX.AutoRunProcessState.completed){var s=this.getErrorCount();var r=this.getProcessedItemCount()-s;BX.addCustomEvent(window,"BX.Crm.ProcessSummaryPanel:onLayout",this._summaryLayoutHandler);BX.Crm.ProcessSummaryPanel.create(this._id,{container:this._containerId,data:{succeededCount:r,failedCount:s,errors:this.getErrors()},messages:BX.prop.getObject(this._settings,"messages",null),numberSubstitution:"#number#",displayTimeout:1500}).layout();this.reset();window.setTimeout(function(){BX.onCustomEvent(window,"BX.Crm.BatchDeletionManager:onProcessComplete",[this])}.bind(this),300)}},onSummaryLayout:function(){this.refreshGridHeader();BX.removeCustomEvent(window,"BX.Crm.ProcessSummaryPanel:onLayout",this._summaryLayoutHandler);BX.addCustomEvent(window,"BX.Crm.ProcessSummaryPanel:onClearLayout",this._summaryClearLayoutHandler)},onSummaryClearLayout:function(){this.refreshGridHeader();BX.removeCustomEvent(window,"BX.Crm.ProcessSummaryPanel:onClearLayout",this._summaryClearLayoutHandler)}};if(typeof BX.Crm.BatchDeletionManager.messages==="undefined"){BX.Crm.BatchDeletionManager.messages={}}BX.Crm.BatchDeletionManager.items={};BX.Crm.BatchDeletionManager.getItem=function(t){return BX.prop.get(this.items,t,null)};BX.Crm.BatchDeletionManager.create=function(t,e){var i=new BX.Crm.BatchDeletionManager;i.initialize(t,e);this.items[i.getId()]=i;return i}}
//# sourceMappingURL=batch_deletion.map.js