Current Path : /var/www/www-root/data/www/www.monolith-realty.ru/bitrix/js/ui/entity-editor/js/ |
Current File : /var/www/www-root/data/www/www.monolith-realty.ru/bitrix/js/ui/entity-editor/js/editor.min.js |
BX.namespace("BX.UI");if(typeof BX.UI.EntityEditor==="undefined"){BX.UI.EntityEditor=function(){this._id="";this._settings={};this._entityTypeName="";this._entityId=0;this._userFieldManager=null;this.additionalFieldsData={};this._container=null;this._layoutContainer=null;this._buttonContainer=null;this._createSectionButton=null;this._configMenuButton=null;this._configIcon=null;this._pageTitle=null;this._pageTitleInput=null;this._buttonWrapper=null;this._editPageTitleButton=null;this._copyPageUrlButton=null;this._actionTypes=null;this._formElement=null;this._ajaxForm=null;this._ajaxForms=null;this._reloadAjaxForm=null;this._formSubmitHandler=BX.delegate(this.onFormSubmit,this);this._controllers=null;this._controls=null;this._activeControls=null;this._toolPanel=null;this._model=null;this._scheme=null;this._config=null;this._context=null;this._contextId="";this._externalContextId="";this._mode=BX.UI.EntityEditorMode.intermediate;this._isNew=false;this._readOnly=false;this._enableRequiredUserFieldCheck=true;this._enableAjaxForm=true;this._enableSectionEdit=false;this._enableSectionCreation=false;this._enableModeToggle=true;this._enableVisibilityPolicy=true;this._enablePageTitleControls=true;this._enableToolPanel=true;this._isToolPanelAlwaysVisible=false;this._enableBottomPanel=true;this._enableConfigControl=true;this._enableFieldsContextMenu=true;this._canHideField=true;this._serviceUrl="";this._htmlEditorConfigs=null;this._pageTitleExternalClickHandler=BX.delegate(this.onPageTitleExternalClick,this);this._pageTitleKeyPressHandler=BX.delegate(this.onPageTitleKeyPress,this);this._validators=null;this._modeSwitch=null;this._delayedSaveHandle=0;this._isEmbedded=false;this._isRequestRunning=false;this._isConfigMenuShown=false;this._isReleased=false;this._enableCloseConfirmation=true;this._closeConfirmationHandler=BX.delegate(this.onCloseConfirmButtonClick,this);this._cancelConfirmationHandler=BX.delegate(this.onCancelConfirmButtonClick,this);this._windowResizeHandler=BX.debounce(BX.delegate(this.onResize,this),50);this._sliderOpenHandler=BX.delegate(this.onSliderOpen,this);this._sliderCloseHandler=BX.delegate(this.onSliderClose,this);this._areAvailableSchemeElementsChanged=false;this._availableSchemeElements=null;this._dragPlaceHolder=null;this._dragContainerController=null;this._dropHandler=BX.delegate(this.onDrop,this);this._dragConfig={};this.eventsNamespace="BX.UI.EntityEditor";this.pageTitleInputClassName="pagetitle-item";this._configurationFieldManager=null;this._commonConfigEditUrl=BX.prop.getString(this._settings,"commonConfigEditUrl","/configs/editor/?ENTITY_TYPE_ID=#ENTITY_TYPE_ID_VALUE#&MODULE_ID=#MODULE_ID#");this._canBeMultipleFields=true;this.moduleId=null;this._restrictions={};this.eventIds=new Set;this.needReloadStorageKey="UI.EntityEditor.needReload";this._attributeManager=null;this._validationEnabled=true};BX.UI.EntityEditor.prototype={initialize:function(t,e){this._id=BX.type.isNotEmptyString(t)?t:BX.util.getRandomString(4);this._settings=e?e:{};this._model=BX.prop.get(this._settings,"model",null);this._scheme=BX.prop.get(this._settings,"scheme",null);this._config=BX.prop.get(this._settings,"config",null);this._serviceUrl=BX.prop.getString(this._settings,"serviceUrl","");this._entityTypeName=BX.prop.getString(this._settings,"entityTypeName","");this._entityTypeTitle=BX.prop.getString(this._settings,"entityTypeTitle","");this._useFieldsSearch=BX.prop.getBoolean(this._settings,"useFieldsSearch",false);this._useForceFieldsAdd=BX.prop.getBoolean(this._settings,"useForceFieldsAdd",true);this._entityId=BX.prop.getInteger(this._settings,"entityId",0);this.moduleId=BX.prop.getString(this._settings,"moduleId","");this._isNew=this._entityId<=0&&this._model.isIdentifiable();this.additionalFieldsData=BX.prop.getObject(this._settings,"additionalFieldsData",{});this._isEmbedded=BX.prop.getBoolean(this._settings,"isEmbedded",false);this._creationFieldPageUrl=BX.prop.getBoolean(this._settings,"creationFieldPageUrl",false);var i=BX.prop.get(this._settings,"container");if(!BX.type.isElementNode(i)){i=BX(BX.prop.get(this._settings,"containerId"))||top.BX(BX.prop.get(this._settings,"containerId"))}this._container=i;this._parentContainer=BX.findParent(this._container,{className:"ui-entity-section"},false);this._buttonContainer=BX(BX.prop.get(this._settings,"buttonContainerId"));this._configIcon=BX(BX.prop.get(this._settings,"configIconId"));this._canHideField=BX.prop.getBoolean(this._settings,"canHideField",true);this._canBeMultipleFields=BX.prop.getBoolean(this._settings,"canBeMultipleFields",true);this._enableShowAlwaysFeauture=BX.prop.getBoolean(this._settings,"enableShowAlwaysFeauture",true);this._enableVisibilityPolicy=BX.prop.getBoolean(this._settings,"enableVisibilityPolicy",true);this._enablePageTitleControls=BX.prop.getBoolean(this._settings,"enablePageTitleControls",true);if(this._enablePageTitleControls){this._pageTitle=BX("pagetitle");this._buttonWrapper=BX("pagetitle_btn_wrapper");this._editPageTitleButton=BX("pagetitle_edit");this._copyPageUrlButton=BX("page_url_copy_btn")}this.adjustSize();this.adjustTitle();var n=BX.prop.getString(this._settings,"formTagName","form");this._formElement=BX.create(n,{props:{name:this._id+"_form"}});this._container.appendChild(this._formElement);this._layoutContainer=BX.create("div",{props:{className:"ui-entity-editor-column-wrapper"}});this._formElement.appendChild(this._layoutContainer);this._enableRequiredUserFieldCheck=BX.prop.getBoolean(this._settings,"enableRequiredUserFieldCheck",true);this._enableAjaxForm=BX.prop.getBoolean(this._settings,"enableAjaxForm",true);if(this._enableAjaxForm){this.initializeAjaxForm()}this._restrictions=BX.prop.getObject(this._settings,"restrictions",{});this.initializeManagers();this._context=BX.prop.getObject(this._settings,"context",{});this._contextId=BX.prop.getString(this._settings,"contextId","");this._externalContextId=BX.prop.getString(this._settings,"externalContextId","");this._readOnly=BX.prop.getBoolean(this._settings,"readOnly",false);if(this._readOnly){this._enableSectionEdit=this._enableSectionCreation=false}else{this._enableSectionEdit=BX.prop.getBoolean(this._settings,"enableSectionEdit",false);this._enableSectionCreation=BX.prop.getBoolean(this._settings,"enableSectionCreation",false)}this._controllers=[];this._controls=[];this._activeControls=[];this._modeSwitch=BX.UI.EntityEditorModeSwitch.create(this._id,{editor:this});this._htmlEditorConfigs=BX.prop.getObject(this._settings,"htmlEditorConfigs",{});var o=BX.UI.EntityEditorMode.view;if(!this._readOnly){o=BX.UI.EntityEditorMode.parse(BX.prop.getString(this._settings,"initialMode",""))}this._mode=o!==BX.UI.EntityEditorMode.intermediate?o:BX.UI.EntityEditorMode.view;this._enableModeToggle=false;if(!this._readOnly){this._enableModeToggle=BX.prop.getBoolean(this._settings,"enableModeToggle",true)}if(this._isNew&&!this._readOnly){this._mode=BX.UI.EntityEditorMode.edit}this._availableSchemeElements=this._scheme.getAvailableElements();this.initializeControllers();this.initializeControls();if(this._mode===BX.UI.EntityEditorMode.edit&&this._controls.length>0){this.initializeControlsEditMode()}this.initializeValidators();this._enableToolPanel=BX.prop.getBoolean(this._settings,"enableToolPanel",true);this._isToolPanelAlwaysVisible=BX.prop.getBoolean(this._settings,"isToolPanelAlwaysVisible",false);if(this._enableToolPanel){this.initializeToolPanel();if(this.isToolPanelAlwaysVisible()){this.showToolPanel()}}this._enableBottomPanel=BX.prop.getBoolean(this._settings,"enableBottomPanel",true);this._enableConfigControl=BX.prop.getBoolean(this._settings,"enableConfigControl",true);this._enableFieldsContextMenu=BX.prop.getBoolean(this._settings,"enableFieldsContextMenu",true);this.initializeDragDrop();this.layout();this.attachToEvents();this.initPull();var s={id:this._id,externalContext:this._externalContextId,context:this._contextId,entityTypeName:this._entityTypeName,entityId:this._entityId,model:this._model};BX.onCustomEvent(window,this.eventsNamespace+":onInit",[this,s])},initializeControllers:function(){var t,e;var i=BX.prop.getArray(this._settings,"controllers",[]);for(t=0,e=i.length;t<e;t++){var n=this.createController(i[t]);if(n){this._controllers.push(n)}}},initializeControls:function(){var t=this._scheme.getElements();var e,i,n,o;for(e=0,i=t.length;e<i;e++){n=t[e];o=this.createControl(n.getType(),n.getName(),{schemeElement:n,mode:BX.UI.EntityEditorMode.view});if(!o){continue}this._controls.push(o)}},initializeControlsEditMode:function(){var t,e;for(t=0,e=this._controls.length;t<e;t++){this._controls[t].setMode(BX.UI.EntityEditorMode.edit,{notify:false})}},initializeValidators:function(){var t,e;this._validators=[];var i=BX.prop.getArray(this._settings,"validators",[]);for(t=0,e=i.length;t<e;t++){var n=this.createValidator(i[t]);if(n){this._validators.push(n)}}},initializeToolPanel:function(){var t=BX.prop.getObject(this._settings,"toolPanelButtonsOrder",{});var e=BX.prop.getArray(this._settings,"customToolPanelButtons",[]);this._toolPanel=BX.UI.EntityEditorToolPanel.create(this._id,{container:this._isEmbedded?this._formElement:document.body,editor:this,visible:false,buttonsOrder:t,customButtons:e})},initializeDragDrop:function(){this._dragConfig={};var t={};t[BX.UI.EntityEditorMode.names.view]=t[BX.UI.EntityEditorMode.names.edit]=BX.prop.getBoolean(this._settings,"enableSectionDragDrop",true);this._dragConfig[BX.UI.EditorDragObjectType.section]={scope:BX.UI.EditorDragScope.form,modes:t};var e={};e[BX.UI.EntityEditorMode.names.view]=e[BX.UI.EntityEditorMode.names.edit]=BX.prop.getBoolean(this._settings,"enableFieldDragDrop",true);this._dragConfig[BX.UI.EditorDragObjectType.field]={scope:BX.UI.EditorDragScope.form,modes:e}},initializeManagers:function(){this._userFieldManager=BX.prop.get(this._settings,"userFieldManager",null);this._configurationFieldManager=BX.UI.EntityConfigurationManager.create(this._id,{editor:this});let t={id:this._id,editor:this,type:"editor",configurationFieldManager:this._configurationFieldManager};BX.onCustomEvent(window,"BX.UI.EntityConfigurationManager:onInitialize",[this,t]);this._configurationFieldManager=t.configurationFieldManager},initializeCustomEditors:function(){},attachToEvents:function(){BX.bind(window,"resize",this._windowResizeHandler);BX.addCustomEvent("SidePanel.Slider:onOpenComplete",this._sliderOpenHandler);BX.addCustomEvent("SidePanel.Slider:onClose",this._sliderCloseHandler)},deattachFromEvents:function(){BX.unbind(window,"resize",this._windowResizeHandler);BX.removeCustomEvent("SidePanel.Slider:onOpenComplete",this._sliderOpenHandler);BX.removeCustomEvent("SidePanel.Slider:onClose",this._sliderCloseHandler)},initPull:function(){const t=this._settings;BX.Event.ready((()=>{if(!t.pullTag||!t.pullModuleId||!t.canUsePull){return}const e=BX.PULL;if(!e){console.error("pull is not initialized");return}const i=new BX.UI.EntityPull({editor:this});e.subscribe({moduleId:t.pullModuleId,callback:e=>{if(e.command!==t.pullTag){return}const n=e.params.eventId??null;if(n&&this.eventIds.has(n)){return}if(e.params.eventName==="ITEMUPDATED"){i.onItemUpdated()}}});e.extendWatch(t.pullTag);BX.Event.bind(document,"visibilitychange",(()=>{if(document.hidden){return}const t=window.sessionStorage.getItem(this.needReloadStorageKey);if(t==="Y"){window.sessionStorage.removeItem(this.needReloadStorageKey);BX.Crm.EntityEditor.getDefault().reload()}}))}))},release:function(){for(var t=0,e=this._controls.length;t<e;t++){this._controls[t].clearLayout()}this.deattachFromEvents();this.releaseAjaxForm();this.releaseReloadAjaxForm();this._attributeManager=null;this._container=BX.remove(this._container);this._isReleased=true},onSliderOpen:function(t){this._enableCloseConfirmation=true;var e={id:this._id,externalContext:this._externalContextId,context:this._contextId,entityTypeId:this._entityTypeId,entityId:this._entityId,model:this._model};BX.onCustomEvent(window,this.eventsNamespace+":onOpen",[this,e])},onSliderClose:function(t){if(!this._enableCloseConfirmation){return}var e=top.BX.SidePanel.Instance.getSliderByWindow(window);if(e!==t.getSlider()){return}if(!e.isOpen()){return}if(!this.hasChangedControls()&&!this.hasChangedControllers()){return}t.denyAction();if(BX.UI.EditorAuxiliaryDialog.isItemOpened("close_confirmation")){return}BX.UI.EditorAuxiliaryDialog.create("close_confirmation",{title:BX.message("UI_ENTITY_EDITOR_CONFIRMATION"),content:BX.message("UI_ENTITY_EDITOR_CLOSE_CONFIRMATION"),zIndex:100,buttons:[{id:"close",type:BX.UI.DialogButtonType.accept,text:BX.message("JS_CORE_WINDOW_CLOSE"),callback:this._closeConfirmationHandler},{id:"cancel",type:BX.UI.DialogButtonType.cancel,text:BX.message("JS_CORE_WINDOW_CANCEL"),callback:this._closeConfirmationHandler}]}).open()},onCloseConfirmButtonClick:function(t){t.getDialog().close();if(t.getId()==="close"){this._enableCloseConfirmation=false;top.BX.SidePanel.Instance.getSliderByWindow(window).close()}},initializeAjaxForm:function(){if(this._ajaxForm){return}var t=BX.prop.getObject(this._settings,"ajaxData",{});var e=BX.prop.getString(t,"ACTION_NAME","");var i=BX.prop.getString(t,"COMPONENT_NAME","");var n=BX.prop.getString(t,"SIGNED_PARAMETERS","");this._ajaxForms={};this._actionTypes={};this._actionTypes[BX.UI.EntityEditorActionIds.defaultActionId]=BX.UI.EntityEditorActionTypes.save;var o=this.createAjaxForm({componentName:i,actionName:e,elementNode:this._formElement,signedParameters:n,enableRequiredUserFieldCheck:this._enableRequiredUserFieldCheck},{onSuccess:this.onSaveSuccess.bind(this),onFailure:this.onSaveFailure.bind(this)});this._ajaxForms[BX.UI.EntityEditorActionIds.defaultActionId]=o;BX.addCustomEvent(o,"onAfterSubmit",this._formSubmitHandler);if(t.ADDITIONAL_ACTIONS&&t.ADDITIONAL_ACTIONS.length>0){var s=t.ADDITIONAL_ACTIONS;for(var r=0;r<s.length;r++){var a=s[r];this._actionTypes[a.ID]=a.ACTION_TYPE;var l=this.createAjaxForm({componentName:i,actionName:a.ACTION,elementNode:this._formElement,signedParameters:n,enableRequiredUserFieldCheck:this._enableRequiredUserFieldCheck},{onSuccess:this.onSaveSuccess.bind(this),onFailure:this.onSaveFailure.bind(this)});BX.addCustomEvent(l,"onAfterSubmit",this._formSubmitHandler);this._ajaxForms[a.ID]=l}}this._ajaxForm=this._ajaxForms[BX.UI.EntityEditorActionIds.defaultActionId];this._formElement.setAttribute("onsubmit","return false;")},createAjaxForm:function(t,e){var i=BX.prop.getString(t,"componentName","");var n=BX.prop.getString(t,"actionName","");var o=BX.prop.getElementNode(t,"elementNode",null);var s=BX.prop.getObject(t,"formData",null);if(i!==""){if(n===""){n="save"}return BX.UI.ComponentAjax.create(this._id,{elementNode:o,formData:s,className:i,signedParameters:BX.prop.getString(t,"signedParameters",null),actionName:n,callbacks:{onSuccess:e?e.onSuccess:null,onFailure:e?e.onFailure:null}})}else{if(n===""){n="SAVE"}return BX.UI.AjaxForm.create(this._id,{elementNode:o,formData:s,config:{url:this._serviceUrl,method:"POST",dataType:"json",processData:true,onsuccess:e?e.onSuccess:null,data:Object.assign({ACTION:n,ENABLE_REQUIRED_USER_FIELD_CHECK:BX.prop.getBoolean(t,"enableRequiredUserFieldCheck",false)?"Y":"N"},this.getAjaxFormConfigData())}})}},getAjaxFormConfigData:function(){return{ACTION_ENTITY_TYPE:this._entityTypeName}},releaseAjaxForm:function(){if(!this._ajaxForm){return}var t=this;if(BX.Type.isObject(this._ajaxForms)){Object.keys(this._ajaxForms).forEach((function(e){BX.removeCustomEvent(t._ajaxForms[e],"onAfterSubmit",t._formSubmitHandler);t._ajaxForms[e]=null}))}BX.removeCustomEvent(this._ajaxForm,"onAfterSubmit",this._formSubmitHandler);this._ajaxForm=null},releaseReloadAjaxForm:function(){if(!this._reloadAjaxForm){return}this._reloadAjaxForm=null},getId:function(){return this._id},getEntityTypeName:function(){return this._entityTypeName},getEntityId:function(){return this._entityId},getOwnerInfo:function(){return this._model.getOwnerInfo()},getMode:function(){return this._mode},getContextId:function(){return this._contextId},getContext:function(){return this._context},getExternalContextId:function(){return this._externalContextId},getScheme:function(){return this._scheme},canHideField:function(){return this._canHideField},isVisible:function(){return this._container.offsetParent!==null},isShowAlwaysFeautureEnabled:function(){return this._enableShowAlwaysFeauture},isVisibilityPolicyEnabled:function(){return this._enableVisibilityPolicy},isToolPanelAlwaysVisible:function(){return this._isToolPanelAlwaysVisible},isBottomPanelEnabled:function(){return this._enableBottomPanel},isConfigControlEnabled:function(){return this._enableConfigControl},isSectionEditEnabled:function(){return this._enableSectionEdit},isSectionCreationEnabled:function(){return this._enableSectionCreation&&this.canChangeScheme()},isFieldsContextMenuEnabled:function(){return this._enableFieldsContextMenu},isModeToggleEnabled:function(){return this._enableModeToggle},isNew:function(){return this._isNew},isReadOnly:function(){return this._readOnly},isEmbedded:function(){return this._isEmbedded},isEditInViewEnabled:function(){return this._entityId>0},getDetailManager:function(){if(typeof BX.UI.EntityDetailManager==="undefined"){return null}return BX.UI.EntityDetailManager.get(BX.prop.getString(this._settings,"detailManagerId",""))},getConfigurationFieldManager:function(){return this._configurationFieldManager},getUserFieldManager:function(){return this._userFieldManager},setAttributeManager:function(t){if(BX.Type.isObject(t)){this._attributeManager=t}return this._attributeManager},getAttributeManager:function(){return this._attributeManager},getHtmlEditorConfig:function(t){return BX.prop.getObject(this._htmlEditorConfigs,t,null)},getAdditionalFieldsData:function(){return this.additionalFieldsData},createValidator:function(t){t["editor"]=this;return BX.UI.EntityEditorValidatorFactory.create(BX.prop.getString(t,"type",""),t)},getControlByIndex:function(t){return t>=0&&t<this._controls.length?this._controls[t]:null},getControlIndex:function(t){for(var e=0,i=this._controls.length;e<i;e++){if(this._controls[e]===t){return e}}return-1},getControls:function(){return this._controls},getControlCount:function(){return this._controls.length},createControl:function(t,e,i){i["serviceUrl"]=this._serviceUrl;i["container"]=this._layoutContainer;i["model"]=this._model;i["editor"]=this;return BX.UI.EntityEditorControlFactory.create(t,e,i)},addControlAt:function(t,e){var i={};if(e<this._controls.length){i["anchor"]=this._controls[e].getWrapper();this._controls.splice(e,0,t)}else{this._controls.push(t)}t.layout(i)},moveControl:function(t,e){var i=this._controls.length;var n=i-1;if(e<0||e>i){e=n}var o=this.getControlIndex(t);if(o<0||o===e){return false}t.clearLayout();this._controls.splice(o,1);i--;var s=e<i?this._controls[e].getWrapper():null;if(e<i){this._controls.splice(e,0,t)}else{this._controls.push(t)}if(s){t.layout({anchor:s})}else{t.layout()}this._config.moveSchemeElement(t.getSchemeElement(),e)},removeControl:function(t){var e=this.getControlIndex(t);if(e<0){return false}this.processControlRemove(t);t.clearLayout();this._controls.splice(e,1)},getControlById:function(t){for(var e=0,i=this._controls.length;e<i;e++){var n=this._controls[e];if(n.getId()===t){return n}var o=n.getChildById(t);if(o){return o}}return null},getControlByIdRecursive:function(t,e){if(!e){e=this.getControls()}for(let i=0;i<e.length;i++){if(!e[i]instanceof BX.UI.EntityEditorControl){continue}if(e[i].getId()===t){return e[i]}else if(e[i]instanceof BX.UI.EntityEditorColumn||e[i]instanceof BX.UI.EntityEditorSection){const n=this.getControlByIdRecursive(t,e[i].getChildren());if(n){return n}}}return null},quoteRegExp:function(t){return t.replace(/([\\.+*?\[^\]$(){}=!<>|:])/g,"\\$1")},getCombinedIdRegExp:function(t){return new RegExp(this.quoteRegExp(t).replace(/\\\[n?\d+\\]/gi,"\\[n?\\d+\\]"))},getControlByCombinedIdRecursive:function(t,e){if(!BX.type.isNotEmptyString(t)){return null}let i=this.getCombinedIdRegExp(t);if(!e){e=this.getControls()}for(let n=0;n<e.length;n++){if(!e[n]instanceof BX.UI.EntityEditorControl){continue}if(i.test(e[n].getId())){return e[n]}else if(e[n]instanceof BX.UI.EntityEditorColumn||e[n]instanceof BX.UI.EntityEditorSection){const i=this.getControlByCombinedIdRecursive(t,e[n].getChildren());if(i instanceof BX.UI.EntityEditorControl){return i}}}return null},getAvailableControlByCombinedId:function(t){let e=null;let i=this.getAvailableSchemeElementByCombinedName(t);if(i){e=this.createControl(i.getType(),i.getName(),{schemeElement:i,model:this._model,mode:this._mode})}return e},getAllControls:function(t){let e=[];if(!t){t=this.getControls()}for(var i=0;i<t.length;i++){if(t[i]instanceof BX.UI.EntityEditorControl){if(t[i]instanceof BX.UI.EntityEditorColumn||t[i]instanceof BX.UI.EntityEditorSection){const n=this.getAllControls(t[i].getChildren());if(n){e=e.concat(n)}}else{e.push(t[i])}}}return e},getActiveControlCount:function(){return this._activeControls.length},getActiveControlIndex:function(t){var e=this._activeControls.length;if(e===0){return-1}for(var i=0;i<e;i++){if(this._activeControls[i]===t){return i}}return-1},getActiveControlById:function(t,e){e=!!e;var i=this._activeControls.length;if(i===0){return null}for(var n=0;n<i;n++){var o=this._activeControls[n];if(o.getId()===t){return o}if(e){var s=o.getChildById(t);if(s){return s}}}return null},getActiveControlByIndex:function(t){return t>=0&&t<this._activeControls.length?this._activeControls[t]:null},registerActiveControl:function(t){var e=this.getActiveControlIndex(t);if(e>=0){return}this._activeControls.push(t);t.setActive(true);if(this._mode!==BX.UI.EntityEditorMode.edit){this._mode=BX.UI.EntityEditorMode.edit}},unregisterActiveControl:function(t){var e=this.getActiveControlIndex(t);if(e<0){return}this._activeControls.splice(e,1);t.setActive(false);if(this._activeControls.length===0&&this._mode!==BX.UI.EntityEditorMode.view){this._mode=BX.UI.EntityEditorMode.view}},releaseActiveControls:function(t){var e={id:this._id,externalContext:this._externalContextId,context:this._contextId,entityTypeName:this._entityTypeName,entityId:this._entityId,model:this._model};BX.onCustomEvent(window,this.eventsNamespace+":onRelease",[this,e]);var i=[];for(var n=0,o=this._activeControls.length;n<o;n++){var s=this._activeControls[n];if(s.isModeToggleEnabled()){s.setActive(false);s.toggleMode(false,t)}else{i.push(s)}}this._activeControls=i},hasChangedControls:function(){for(var t=0,e=this._activeControls.length;t<e;t++){if(this._activeControls[t].isChanged()){return true}}return false},hasChangedControllers:function(){for(var t=0,e=this._controllers.length;t<e;t++){if(this._controllers[t].isChanged()){return true}}return false},isWaitingForInput:function(){if(this._mode!==BX.UI.EntityEditorMode.edit){return false}for(var t=0,e=this._activeControls.length;t<e;t++){if(this._activeControls[t].isWaitingForInput()){return true}}return false},processControlModeChange:function(t,e){if(t.getMode()===BX.UI.EntityEditorMode.edit){this.registerActiveControl(t)}else{this.unregisterActiveControl(t)}if(this.getActiveControlCount()>0){this.showToolPanel()}else if(!this.isToolPanelAlwaysVisible()){this.hideToolPanel()}var i={control:t};BX.onCustomEvent(window,this.eventsNamespace+":onControlModeChange",[this,i])},processControlChange:function(t,e,i){this.showToolPanel();if(!BX.prop.getBoolean(i,"skipEvents",false)){BX.onCustomEvent(window,this.eventsNamespace+":onControlChange",[this,{control:t,params:e}])}},processControlAdd:function(t,e){this.removeAvailableSchemeElement(t.getSchemeElement());if(!BX.prop.getBoolean(e,"skipEvents",false)){BX.onCustomEvent(this,this.eventsNamespace+":onControlAdd",[this,{control:t,params:{}}])}},processControlMove:function(t,e){if(!BX.prop.getBoolean(e,"skipEvents",false)){BX.onCustomEvent(this,this.eventsNamespace+":onControlMove",[this,{control:t,params:e}])}},processControlRemove:function(t,e){if(t instanceof BX.UI.EntityEditorField){this.addAvailableSchemeElement(t.getSchemeElement())}else if(t instanceof BX.UI.EntityEditorSection){var i=t.getChildren();for(var n=0,o=i.length;n<o;n++){this.addAvailableSchemeElement(i[n].getSchemeElement())}}if(!BX.prop.getBoolean(e,"skipEvents",false)){BX.onCustomEvent(this,this.eventsNamespace+":onControlRemove",[this,{control:t,params:{}}])}},processSchemeChange:function(){for(var t=0,e=this._controls.length;t<e;t++){this._controls[t].processSchemeChange()}},getAvailableSchemeElements:function(){return this._availableSchemeElements},addAvailableSchemeElement:function(t){this._availableSchemeElements.push(t);this._areAvailableSchemeElementsChanged=true;this.notifyAvailableSchemeElementsChanged()},removeAvailableSchemeElement:function(t){var e=this.getAvailableSchemeElementIndex(t);if(e<0){return}this._availableSchemeElements.splice(e,1);this._areAvailableSchemeElementsChanged=true;this.notifyAvailableSchemeElementsChanged()},getAvailableSchemeElementIndex:function(t){var e=this._availableSchemeElements;for(var i=0,n=e.length;i<n;i++){if(e[i]===t){return i}}return-1},getAvailableSchemeElementByName:function(t){var e=this._availableSchemeElements;for(var i=0,n=e.length;i<n;i++){var o=e[i];if(o.getName()===t){return o}}return null},getAvailableSchemeElementByCombinedName:function(t){if(!BX.type.isNotEmptyString(t)){return null}let e=this.getCombinedIdRegExp(t);const i=this._availableSchemeElements;for(let t=0,n=i.length;t<n;t++){if(e.test(i[t].getName())){return i[t]}}return null},hasAvailableSchemeElements:function(){return this._availableSchemeElements.length>0},getSchemeElementByName:function(t){return this._scheme.findElementByName(t,{isRecursive:true})},notifyAvailableSchemeElementsChanged:function(){for(var t=0,e=this._controls.length;t<e;t++){this._controls[t].processAvailableSchemeElementsChange()}},hasTransferableElements:function(t){var e=0;if(BX.type.isArray(t)){e=t.length}var i=this._scheme.getElements();for(var n=0,o=i.length;n<o;n++){var s=i[n].getElements();for(var r=0,a=s.length;r<a;r++){var l=s[r];var h=false;if(e>0){var c=l.getName();for(var d=0;d<e;d++){if(t[d]===c){h=true;break}}}if(h){continue}var u=l.getElements();for(var f=0,g=u.length;f<g;f++){if(u[f].isTransferable()&&u[f].getName()!==""){return true}}}}return false},createController:function(t){return BX.UI.EntityEditorControllerFactory.create(BX.prop.getString(t,"type",""),BX.prop.getString(t,"name",""),{config:BX.prop.getObject(t,"config",{}),model:this._model,editor:this})},processControllerChange:function(t){this.showToolPanel();var e={controller:t};BX.onCustomEvent(window,this.eventsNamespace+":onControllerChange",[this,e])},getControllers:function(){return this._controllers},getContainer:function(){return this._container},prepareContextDataLayout:function(t,e){for(var i in t){if(!t.hasOwnProperty(i)){continue}var n=t[i];var o=i;if(BX.type.isNotEmptyString(e)){o=e+"["+o+"]"}if(BX.type.isPlainObject(n)){this.prepareContextDataLayout(n,o)}else{this._formElement.appendChild(BX.create("input",{props:{type:"hidden",name:o,value:n}}))}}},layout:function(){var t={cancel:false};BX.onCustomEvent(window,this.eventsNamespace+":onBeforeLayout",[this,t]);if(t["cancel"]){return}this.prepareContextDataLayout(this._context,"");if(this._toolPanel){this._toolPanel.layout()}var e={edit:BX.UI.EntityUserFieldLayoutLoader.create(this._id,{mode:BX.UI.EntityEditorMode.edit,enableBatchMode:true,owner:this}),view:BX.UI.EntityUserFieldLayoutLoader.create(this._id,{mode:BX.UI.EntityEditorMode.view,enableBatchMode:true,owner:this})};var i,n,o;for(i=0,n=this._controls.length;i<n;i++){o=this._controls[i];var s=o.getMode();var r={userFieldLoader:e[BX.UI.EntityEditorMode.getName(s)],enableFocusGain:!this._isEmbedded};o.layout(r);if(s===BX.UI.EntityEditorMode.edit){this.registerActiveControl(o)}}for(var a in e){if(e.hasOwnProperty(a)){e[a].runBatch()}}if(this.getActiveControlCount()>0){this.showToolPanel()}if(this._model.isCaptionEditable()){BX.bind(this._pageTitle,"click",BX.delegate(this.onPageTileClick,this));if(this._editPageTitleButton){BX.bind(this._editPageTitleButton,"click",BX.delegate(this.onPageTileClick,this))}}if(this._buttonContainer&&this.isBottomPanelEnabled()){if(this.isSectionCreationEnabled()){this._createSectionButton=BX.create("span",{props:{className:"ui-entity-add-widget-link"},text:BX.message("UI_ENTITY_EDITOR_CREATE_SECTION"),events:{click:BX.delegate(this.onCreateSectionButtonClick,this)}});this._buttonContainer.appendChild(this._createSectionButton)}if(this.isConfigControlEnabled()){var l=this._config.getScope();var h=BX.UI.EntityConfigScope.getCaption(l);this._buttonContainer.appendChild(BX.create("span",{props:{className:l===BX.UI.EntityConfigScope.common?"ui-entity-card-common":"ui-entity-card-private",title:h}}));this._configMenuButton=BX.create("span",{props:{className:"ui-entity-settings-link"},text:h,events:{click:BX.delegate(this.onConfigMenuButtonClick,this)}});this._buttonContainer.appendChild(this._configMenuButton)}}this.adjustButtons()},refreshLayout:function(t){var e={edit:BX.UI.EntityUserFieldLayoutLoader.create(this._id,{mode:BX.UI.EntityEditorMode.edit,enableBatchMode:true,owner:this}),view:BX.UI.EntityUserFieldLayoutLoader.create(this._id,{mode:BX.UI.EntityEditorMode.view,enableBatchMode:true,owner:this})};if(!BX.type.isPlainObject(t)){t={}}for(var i=0,n=this._controls.length;i<n;i++){var o=this._controls[i];var s=o.getMode();var r=BX.mergeEx(t,{userFieldLoader:e[BX.UI.EntityEditorMode.getName(s)],enableFocusGain:!this._isEmbedded});o.refreshLayout(r)}for(var a in e){if(e.hasOwnProperty(a)){e[a].runBatch()}}this.adjustButtons();BX.onCustomEvent(window,this.eventsNamespace+":onRefreshLayout",[this])},refreshViewModeLayout:function(t){var e=BX.UI.EntityUserFieldLayoutLoader.create(this._id,{mode:BX.UI.EntityEditorMode.view,enableBatchMode:true,owner:this});if(!BX.type.isPlainObject(t)){t={}}for(var i=0,n=this._controls.length;i<n;i++){var o=this._controls[i];var s=BX.mergeEx(t,{userFieldLoader:e,enableFocusGain:false,isRefreshViewModeLayout:true});o.refreshViewModeLayout(s)}e.runBatch();BX.onCustomEvent(window,this.eventsNamespace+":onRefreshViewModeLayout",[this])},switchControlMode:function(t,e,i){if(!this.isModeToggleEnabled()){return}if(e===BX.UI.EntityEditorMode.view){if(t.checkModeOption(BX.UI.EntityEditorModeOptions.saveOnExit)){this._modeSwitch.getQueue().add(t,BX.UI.EntityEditorMode.view);this._modeSwitch.run()}else{t.setMode(e,{options:i,notify:true});t.refreshLayout()}}else{if(!BX.UI.EntityEditorModeOptions.check(i,BX.UI.EntityEditorModeOptions.exclusive)){t.setMode(BX.UI.EntityEditorMode.edit,{options:i,notify:true});t.refreshLayout()}else{var n=0;for(var o=0,s=this._activeControls.length;o<s;o++){var r=this._activeControls[o];if(r.checkModeOption(BX.UI.EntityEditorModeOptions.saveOnExit)){this._modeSwitch.getQueue().add(r,BX.UI.EntityEditorMode.view,i);n++}}if(n>0){this._modeSwitch.getQueue().add(t,BX.UI.EntityEditorMode.edit,i);this._modeSwitch.run()}else{t.setMode(BX.UI.EntityEditorMode.edit,{options:i,notify:true});t.refreshLayout()}}}},switchToViewMode:function(t){this.releaseActiveControls(t);if(this.getActiveControlCount()>0){return}if(!this.isToolPanelAlwaysVisible()){this.hideToolPanel()}var e={options:t};BX.onCustomEvent(window,this.eventsNamespace+":onSwitchToViewMode",[this,e])},switchTitleMode:function(t){if(t===BX.UI.EntityEditorMode.edit){this._pageTitle.style.display="none";document.body.classList.add("--edit__title-input");if(this._buttonWrapper){this._buttonWrapper.style.display="none"}this._pageTitleInput=BX.create("input",{props:{type:"text",className:this.pageTitleInputClassName,value:this._model.getCaption()}});this._pageTitle.parentNode.insertBefore(this._pageTitleInput,this._pageTitle);this._pageTitleInput.focus();window.setTimeout(BX.delegate((function(){BX.bind(document,"mousedown",this._pageTitleExternalClickHandler);BX.bind(this._pageTitleInput,"keyup",this._pageTitleKeyPressHandler)}),this),300)}else{if(this._pageTitleInput){this._pageTitleInput=BX.remove(this._pageTitleInput)}this._pageTitle.innerHTML=BX.util.htmlspecialchars(this._model.getCaption());this._pageTitle.style.display="";if(this._buttonWrapper){this._buttonWrapper.style.display=""}BX.unbind(document,"mousedown",this._pageTitleExternalClickHandler);BX.unbind(this._pageTitleInput,"keyup",this._pageTitleKeyPressHandler);this.adjustTitle()}},adjustTitle:function(){if(!this._enablePageTitleControls||!this._buttonWrapper){return}var t=this._model.getCaption().trim();var e="";var i=t.match(/\s+\S+\s*$/);if(i){e=t.substr(i["index"]);t=t.substr(0,i["index"])}else{e=t;t=""}BX.cleanNode(this._buttonWrapper);if(e!==""){this._buttonWrapper.appendChild(document.createTextNode(e))}if(this._editPageTitleButton){this._buttonWrapper.appendChild(this._editPageTitleButton)}if(this._copyPageUrlButton){this._buttonWrapper.appendChild(this._copyPageUrlButton)}this._pageTitle.innerHTML=BX.util.htmlspecialchars(t)},adjustSize:function(){if(!this._enablePageTitleControls||!this._pageTitle){return}var t=this._pageTitle.parentNode?this._pageTitle.parentNode:this._pageTitle;var e=t.offsetWidth<=480&&this._model.getCaption().length>=40;if(e&&!BX.hasClass(t,"pagetitle-narrow")){BX.addClass(t,"pagetitle-narrow")}else if(!e&&BX.hasClass(t,"pagetitle-narrow")){BX.removeClass(t,"pagetitle-narrow")}},adjustButtons:function(){if(this._config.isScopeToggleEnabled()&&!this._enableBottomPanel&&this._controls.length>0){var t=this._controls[this._controls.length-1];if(t instanceof BX.UI.EntityEditorColumn){if(t._sections.length>0){t=t._sections[t._sections.length-1]}else{return}}t.addButtonElement(BX.create("span",{props:{className:this._config.getScope()===BX.UI.EntityConfigScope.common?"ui-entity-card-common":"ui-entity-card-private"},events:{click:BX.delegate(this.onConfigMenuButtonClick,this)}}),{position:"right"})}},showToolPanel:function(){if(!this._toolPanel||this._toolPanel.isVisible()){return}this._toolPanel.setVisible(true);if(this._parentContainer){this._parentContainer.style.paddingBottom="50px";document.body.style.paddingBottom="60px";document.body.style.height="auto"}},hideToolPanel:function(){if(!this._toolPanel||!this._toolPanel.isVisible()){return}this._toolPanel.setVisible(false);if(this._parentContainer){this._parentContainer.style.paddingBottom="";document.body.style.paddingBottom="";document.body.style.height=""}},showMessageDialog:function(t,e,i){var n=BX.UI.EditorAuxiliaryDialog.create(t,{title:e,content:i,buttons:[{id:"continue",type:BX.UI.DialogButtonType.accept,text:BX.message("UI_ENTITY_EDITOR_CONTINUE"),callback:function(t){t.getDialog().close()}}]});n.open()},getMessage:function(t){var e=BX.UI.EntityEditor.messages;return e.hasOwnProperty(t)?e[t]:t},getGlobalEventName:function(t){return t},getFormElement:function(){return this._formElement},isChanged:function(){return this._isNew||this.hasChangedControls()||this.hasChangedControllers()},getEntityTypeForAction:function(){return this._entityTypeName},prepareControllersData:function(t){if(!BX.type.isPlainObject(t)){t={}}for(var e=0,i=this._controllers.length;e<i;e++){if(BX.Type.isFunction(this._controllers[e].onBeforesSaveControl)){t=this._controllers[e].onBeforesSaveControl(t)}}return t},savePageTitle:function(){if(!this._pageTitleInput){return}var t=BX.util.trim(this._pageTitleInput.value);if(t===""){return}this._model.setCaption(t);var e={ACTION:"SAVE",ACTION_ENTITY_ID:this._entityId,ACTION_ENTITY_TYPE:this.getEntityTypeForAction(),PARAMS:BX.prop.getObject(this._context,"PARAMS",{})};this._model.prepareCaptionData(e);e=BX.mergeEx(e,this.prepareControllersData(e));BX.ajax({url:this._serviceUrl,method:"POST",dataType:"json",data:e,onsuccess:BX.delegate(this.onSaveSuccess,this)})},performAction:function(t){if(!this._actionTypes){return}if(this._actionTypes[t]===BX.UI.EntityEditorActionTypes.save){this.performSaveChangedAction(t)}else if(this._actionTypes[t]===BX.UI.EntityEditorActionTypes.direct){this.performDirectAction(t)}},performDirectAction:function(t){if(this._toolPanel){this._toolPanel.setLocked(true)}var e=this.getActionEventArguments();e.actionId=t;BX.onCustomEvent(window,this.eventsNamespace+":onDirectAction",[this,e]);if(e["cancel"]){return}this._ajaxForms[t].submit()},saveChanged:function(){this.performSaveChangedAction(BX.UI.EntityEditorActionIds.defaultActionId)},performSaveChangedAction:function(t){if(!this._isNew&&!this.hasChangedControls()&&!this.hasChangedControllers()&&!this.isWaitingForInput()){this._modeSwitch.reset();this.releaseActiveControls();this.refreshLayout({reset:true});if(!this.isToolPanelAlwaysVisible()){this.hideToolPanel()}BX.onCustomEvent(window,this.eventsNamespace+":onNothingChanged",[this])}else{this._modeSwitch.reset();this._modeSwitch.getQueue().addBatch(this._activeControls,BX.UI.EntityEditorMode.view);this._modeSwitch.setRunAction(t);this._modeSwitch.run()}},saveDelayed:function(t){this.performSaveDelayedAction(BX.UI.EntityEditorActionIds.defaultActionId,t)},performSaveDelayedAction:function(t,e){if(typeof e==="undefined"){e=0}if(this._delayedSaveHandle>0){window.clearTimeout(this._delayedSaveHandle)}this._delayedSaveHandle=window.setTimeout(BX.delegate((function(){this.performSaveAction(t)}),this),e)},save:function(){this.performSaveAction(BX.UI.EntityEditorActionIds.defaultActionId)},performSaveAction:function(t){if(this._toolPanel){this._toolPanel.setLocked(true)}this.registerSaveAnalyticsEvent("attempt");var e=BX.UI.EntityValidationResult.create();this.validate(e).then(BX.delegate((function(){if(this._bizprocManager){return this._bizprocManager.onBeforeSave(e)}var t=new BX.Promise;window.setTimeout((function(){t.fulfill()}),0);return t}),this)).then(BX.delegate((function(){if(e.getStatus()){if(this.performInnerSaveAction(t)!==false){if(this._bizprocManager){this._bizprocManager.onAfterSave()}}else{if(this._toolPanel){this._toolPanel.setLocked(false)}this.registerSaveAnalyticsEvent("error")}}else{if(this.isVisible()){var i=e.getTopmostField();if(i){i.focus();var n=130;window.scroll(window.pageXOffset,window.pageYOffset+n)}}if(this._toolPanel){this._toolPanel.setLocked(false)}this.registerSaveAnalyticsEvent("error");BX.onCustomEvent(window,this.eventsNamespace+":onFailedValidation",[this,e])}}),this));if(this._delayedSaveHandle>0){this._delayedSaveHandle=0}},saveControl:function(t){if(this._entityId<=0&&this._model.isIdentifiable()){return}var e=BX.UI.EntityValidationResult.create();t.validate(e);if(!e.getStatus()){return}var i={ACTION:"SAVE",ACTION_ENTITY_ID:this._entityId,ACTION_ENTITY_TYPE:this.getEntityTypeForAction()};i=BX.mergeEx(i,this._context);t.save();t.prepareSaveData(i);i=BX.mergeEx(i,this.prepareControllersData(i));BX.ajax({method:"POST",dataType:"json",url:this._serviceUrl,data:i,onsuccess:function(t){this.onSaveSuccess(t,{switchMode:false})}.bind(this)})},saveData:function(t){if(this._entityId<=0&&this._model.isIdentifiable()){return}t=BX.mergeEx(t,this._context);t=BX.mergeEx(t,{ACTION:"SAVE",ACTION_ENTITY_ID:this._entityId,ACTION_ENTITY_TYPE:this.getEntityTypeForAction()});BX.ajax({method:"POST",dataType:"json",url:this._serviceUrl,data:t,onsuccess:BX.delegate(this.onSaveSuccess,this)})},reload:function(){if(this._isRequestRunning){return}if(this._entityId<=0&&this._model.isIdentifiable()){return}var t=this.getActionEventArguments();BX.onCustomEvent(window,this.eventsNamespace+":onEntityStartReload",[this,t]);if(t["cancel"]){return}var e=BX.prop.getObject(this._settings,"ajaxData",{});var i=BX.prop.getString(e,"COMPONENT_NAME","");var n=BX.prop.getString(e,"SIGNED_PARAMETERS","");var o=BX.prop.getObject(e,"RELOAD_FORM_DATA",{});var s=BX.prop.getString(e,"RELOAD_ACTION_NAME","");if(s===""){console.warn("Can't reload entity editor because RELOAD_ACTION_NAME is not defined");return}this._reloadAjaxForm=this.createAjaxForm({componentName:i,actionName:s,signedParameters:n,formData:o,enableRequiredUserFieldCheck:false},{onSuccess:this.onReloadSuccess.bind(this)});if(this._reloadAjaxForm){this._reloadAjaxForm.submit()}},setValidationEnabled:function(t){t=!!t;this._validationEnabled=t;if(this._userFieldManager){this._userFieldManager.setValidationEnabled(t)}},validate:function(t){const e=new BX.Promise;if(this._validationEnabled){for(let e=0,i=this._activeControls.length;e<i;e++){this._activeControls[e].validate(t)}if(this._userFieldManager){this._userFieldManager.validate(t).then(BX.delegate((function(){e.fulfill()}),this))}else{e.fulfill()}}else{e.fulfill()}return e},isRequestRunning:function(){return this._isRequestRunning},getActionEventArguments:function(){return{id:this._id,externalContext:this._externalContextId,context:this._contextId,entityTypeName:this._entityTypeName,entityId:this._entityId,model:this._model,cancel:false}},innerSave:function(){this.performInnerSaveAction(BX.UI.EntityEditorActionIds.defaultActionId)},performInnerSaveAction:function(t){if(this._isRequestRunning){return true}var e,i;for(e=0,i=this._controllers.length;e<i;e++){this._controllers[e].onBeforeSubmit()}for(e=0,i=this._activeControls.length;e<i;e++){var n=this._activeControls[e];n.save();n.onBeforeSubmit();if(n.isSchemeChanged()){this._config.updateSchemeElement(n.getSchemeElement())}}if(this._areAvailableSchemeElementsChanged){this._scheme.setAvailableElements(this._availableSchemeElements);this._areAvailableSchemeElementsChanged=false}if(this._config&&this._config.isChanged()){this._config.save(false)}var o=this.getActionEventArguments();o.actionId=t;BX.onCustomEvent(window,this.eventsNamespace+":onSave",[this,o]);if(o["cancel"]){return false}var s=BX.prop.getBoolean(o,"enableCloseConfirmation",null);if(BX.type.isBoolean(s)){this._enableCloseConfirmation=s}var r=null;if(this._ajaxForms&&this._ajaxForms[t]){r=this._ajaxForms[t]}else{r=this._ajaxForm}if(r){const t=BX.Text.getRandom();this.eventIds.add(t);return r.submit({data:{EVENT_ID:t}})}return true},cancel:function(){var t=this.getActionEventArguments();BX.onCustomEvent(window,this.eventsNamespace+":onCancel",[this,t]);if(t["cancel"]){return}var e=BX.prop.getBoolean(t,"enableCloseConfirmation",null);if(BX.type.isBoolean(e)){this._enableCloseConfirmation=e}if(this.hasChangedControls()||this.hasChangedControllers()){window.setTimeout(BX.delegate(this.openCancellationConfirmationDialog,this),250);return}this.innerCancel()},innerCancel:function(){var t,e;for(t=0,e=this._controllers.length;t<e;t++){this._controllers[t].innerCancel()}this.rollback();if(this._isNew){this.refreshLayout();if(typeof top.BX.SidePanel!=="undefined"){window.setTimeout((function(){var t=top.BX.SidePanel.Instance.getSliderByWindow(window);if(t&&t.isOpen()){t.close(false)}}),250)}}else{this.switchToViewMode({refreshLayout:false});this.refreshLayout()}},openCancellationConfirmationDialog:function(){if(this._confirmationCancelDialog){return}this._confirmationCancelDialog=BX.UI.EditorAuxiliaryDialog.create("cancel_confirmation",{title:BX.message("UI_ENTITY_EDITOR_CONFIRMATION"),content:BX.message("UI_ENTITY_EDITOR_CANCEL_CONFIRMATION"),buttons:[{id:"yes",type:BX.UI.DialogButtonType.accept,text:BX.message("UI_ENTITY_EDITOR_YES"),callback:this._cancelConfirmationHandler},{id:"no",type:BX.UI.DialogButtonType.cancel,text:BX.message("UI_ENTITY_EDITOR_NO"),callback:this._cancelConfirmationHandler}]});this._confirmationCancelDialog.open()},onCancelConfirmButtonClick:function(t){t.getDialog().close();this._confirmationCancelDialog=null;if(t.getId()==="yes"){this.innerCancel()}},rollback:function(){this._model.rollback();var t,e;for(t=0,e=this._controllers.length;t<e;t++){this._controllers[t].rollback()}for(t=0,e=this._activeControls.length;t<e;t++){this._activeControls[t].rollback()}if(this._areAvailableSchemeElementsChanged){this._availableSchemeElements=this._scheme.getAvailableElements();this._areAvailableSchemeElementsChanged=false}},addSchemeElementAt:function(t,e){if(this._config){this._config.addSchemeElementAt(t,e)}},updateSchemeElement:function(t){if(this._config){this._config.updateSchemeElement(t)}},removeSchemeElement:function(t){if(this._config){this._config.removeSchemeElement(t)}},canChangeScheme:function(){return this._config&&this._config.isChangeable()},isSchemeChanged:function(){return this._config&&this._config.isChanged()},saveScheme:function(){if(!this._config){return false}var t=this._config.save(false);if(t){this._areAvailableSchemeElementsChanged=false;this.processSchemeChange();BX.onCustomEvent(this,this.eventsNamespace+":onSchemeSave",[this,{params:{}}])}return t},saveSchemeChanges:function(){this.commitSchemeChanges();return this.saveScheme()},commitSchemeChanges:function(){for(var t=0,e=this._controls.length;t<e;t++){this._controls[t].commitSchemeChanges()}if(this._areAvailableSchemeElementsChanged){this._scheme.setAvailableElements(this._availableSchemeElements);this._areAvailableSchemeElementsChanged=false}},canChangeCommonConfiguration:function(){return this._config.isCanChangeCommonConfiguration()},registerSaveAnalyticsEvent:function(t){const e=BX.prop.getObject(this._settings,"analyticsConfig",{});let i=BX.prop.getObject(e,"data",null);if(!BX.Type.isPlainObject(i)){return}i.status=t;if(BX.prop.getBoolean(e,"appendParamsFromCurrentUrl",false)){const t=new BX.Uri(decodeURI(window.location.href));i=Object.assign(t.getQueryParam("st")||{},i)}BX.UI.Analytics.sendData(i)},onSaveSuccess:function(result,params){this._isRequestRunning=false;if(this._toolPanel){this._toolPanel.setLocked(false);this._toolPanel.clearErrors()}if(result.ADDITIONAL_FIELDS_DATA){this.additionalFieldsData=BX.prop.getObject(result,"ADDITIONAL_FIELDS_DATA",{})}const eventParams=this.prepareEventParams(result);var checkErrors=BX.prop.getObject(result,"CHECK_ERRORS",null);var error=BX.prop.getString(result,"ERROR","");var hasRestriction=BX.prop.getBoolean(result,"RESTRICTION",false);if(checkErrors||error!==""||hasRestriction){this.registerSaveAnalyticsEvent("error");if(checkErrors){var firstField=null;var errorMessages=[];for(var fieldId in checkErrors){if(!checkErrors.hasOwnProperty(fieldId)){return}var field=this.getActiveControlById(fieldId,true);if(field){field.showError(checkErrors[fieldId]);if(!firstField){firstField=field}}else{errorMessages.push(checkErrors[fieldId])}}if(firstField){firstField.scrollAnimate()}error=errorMessages.join("<br/>")}var restrictionAction=BX.prop.getString(result,"RESTRICTION_ACTION","");if(hasRestriction&&restrictionAction.length){eval(restrictionAction);BX.onCustomEvent(window,this.eventsNamespace+":onRestrictionAction",[])}else{if(error!==""&&this._toolPanel){this._toolPanel.addError(error)}eventParams["checkErrors"]=checkErrors;eventParams["error"]=error;if(this._isNew){BX.onCustomEvent(window,this.getGlobalEventName("onEntityCreateError"),[eventParams])}else{eventParams["entityId"]=this._entityId;BX.onCustomEvent(window,this.getGlobalEventName("onEntityUpdateError"),[eventParams])}}this.releaseAjaxForm();this.initializeAjaxForm();return}var entityData=BX.prop.getObject(result,"ENTITY_DATA",null);eventParams["entityData"]=entityData;if(!this._model.isIdentifiable()){eventParams["sender"]=this;BX.onCustomEvent(window,this.getGlobalEventName("onEntityUpdate"),[eventParams])}else{if(this._isNew){this._entityId=BX.prop.getInteger(result,"ENTITY_ID",0);if(this._entityId<=0){if(this._toolPanel){let t=this.getMessage("couldNotFindEntityIdError");if(t==="couldNotFindEntityIdError"){t=BX.message("UI_ENTITY_EDITOR_COULD_NOT_FIND_ENTITY_ID")}this._toolPanel.addError(t)}this.registerSaveAnalyticsEvent("error");return}eventParams["sender"]=this;eventParams["entityId"]=this._entityId;BX.onCustomEvent(window,this.getGlobalEventName("onEntityCreate"),[eventParams]);if(BX.prop.getBoolean(eventParams,"isCancelled",true)){this.registerSaveAnalyticsEvent("success");this._entityId=0;this.rollback();this.releaseAjaxForm();this.initializeAjaxForm();return}this._isNew=false}else{eventParams["sender"]=this;eventParams["entityId"]=this._entityId;BX.onCustomEvent(window,this.getGlobalEventName("onEntityUpdate"),[eventParams]);if(BX.prop.getBoolean(eventParams,"isCancelled",true)){this.registerSaveAnalyticsEvent("success");this.rollback();this.releaseAjaxForm();this.initializeAjaxForm();return}}}const redirectUrl=BX.prop.getString(result,"REDIRECT_URL","");const isOpenInNewSlide=BX.prop.getBoolean(result,"OPEN_IN_NEW_SLIDE",false);const additionalEventParams=BX.prop.getObject(result,"EVENT_PARAMS",null);if(additionalEventParams){const t=BX.prop.getString(additionalEventParams,"name","");const e=BX.prop.getObject(additionalEventParams,"args",null);if(BX.Type.isStringFilled(t)&&e!==null){if(BX.Type.isStringFilled(redirectUrl)){e.redirectUrl=redirectUrl}BX.localStorage.set(t,e,10)}}this.registerSaveAnalyticsEvent("success");if(this._isReleased){return}if(BX.Type.isStringFilled(redirectUrl)){setTimeout((()=>{eventParams.redirectUrl=redirectUrl;BX.onCustomEvent(window,this.getGlobalEventName("beforeEntityRedirect"),[eventParams]);const t=BX.util.add_url_param(redirectUrl,{IFRAME:"Y",IFRAME_TYPE:"SIDE_SLIDER"});const e=window.top.BX.SidePanel?window.top.BX.SidePanel.Instance:null;if(isOpenInNewSlide&&e&&e.isOpen()){e.close(false,(()=>e.open(t)))}else{window.location.replace(t)}}))}else{if(BX.prop.getBoolean(params,"switchMode",true)){if(BX.type.isPlainObject(entityData)){this._model.setData(entityData,{enableNotification:false})}this.adjustTitle();this.adjustSize();this.releaseAjaxForm();this.initializeAjaxForm();for(var i=0,length=this._controllers.length;i<length;i++){this._controllers[i].onAfterSave()}if(this._modeSwitch.isRunning()){this._modeSwitch.complete()}else{this.switchToViewMode({refreshLayout:false})}this.refreshLayout({reset:true});if(!this.isToolPanelAlwaysVisible()){this.hideToolPanel()}}else if(BX.type.isPlainObject(entityData)){var previousModel=Object.create(this._model);previousModel.setData(BX.clone(this._model.getData()),{enableNotification:false});this._model.setData(entityData,{enableNotification:false});this.adjustTitle();this.adjustSize();for(var i=0,length=this._controllers.length;i<length;i++){this._controllers[i].onReload()}this.refreshViewModeLayout({previousModel:previousModel,reset:true})}}},prepareEventParams:function(t){var e=BX.prop.getObject(t,"EVENT_PARAMS",{});e["entityTypeName"]=this._entityTypeName;e["isCancelled"]=false;if(typeof window.top.BX.Bitrix24!=="undefined"){var i=window.top.BX.Bitrix24.Slider.getTopSlider();if(i){e["sliderUrl"]=i.getUrl()}}return e},onSaveFailure:function(t){this._isRequestRunning=false;this.registerSaveAnalyticsEvent("error");if(this._toolPanel){this._toolPanel.setLocked(false);this._toolPanel.clearErrors()}var e=BX.prop.getArray(t,"ERRORS",[]);if(this._toolPanel){for(var i=0,n=e.length;i<n;i++){this._toolPanel.addError(e[i])}}var o={errors:e};o["sender"]=this;o["entityTypeName"]=this._entityTypeName;o["entityId"]=this._entityId;BX.onCustomEvent(window,this.eventsNamespace+":onEntitySaveFailure",[o])},onReloadSuccess:function(t){var e=BX.prop.getObject(t,"EVENT_PARAMS",{});e["entityId"]=this._entityId;e["entityTypeName"]=this._entityTypeName;var i=BX.prop.getObject(t,"CHECK_ERRORS",null);var n=BX.prop.getString(t,"ERROR","");if(i||n!==""){e["checkErrors"]=i;e["error"]=n;BX.onCustomEvent(window,this.eventsNamespace+":onEntityReloadError",[e]);return}var o=BX.prop.getObject(t,"ENTITY_DATA",null);if(t.ADDITIONAL_FIELDS_DATA){this.additionalFieldsData=BX.prop.getObject(t,"ADDITIONAL_FIELDS_DATA",{})}e["entityData"]=o;e["sender"]=this;e["entityId"]=this._entityId;BX.onCustomEvent(window,this.eventsNamespace+":onEntityReload",[e]);if(BX.type.isPlainObject(o)){var s=Object.create(this._model);s.setData(BX.clone(this._model.getData()),{enableNotification:false});this._model.setData(o,{enableNotification:false});this.adjustTitle();this.adjustSize();for(var r=0,a=this._controllers.length;r<a;r++){this._controllers[r].onReload()}this.refreshViewModeLayout({previousModel:s,reset:true})}},formatMoney:function(t,e,i){BX.ajax({url:BX.prop.getString(this._settings,"serviceUrl",""),method:"POST",dataType:"json",data:{ACTION:"GET_FORMATTED_SUM",CURRENCY_ID:e,SUM:t},onsuccess:i})},findOption:function(t,e){for(var i=0,n=e.length;i<n;i++){if(t===e[i].VALUE){return e[i].NAME}}return t},prepareConfigMenuItems:function(){var t=[];var e=BX.delegate(this.onMenuItemClick,this);if(this._config.isScopeToggleEnabled()){var i=this._config.getScope();t.push({id:"switchToPersonalConfig",text:BX.message("UI_ENTITY_EDITOR_SWITCH_TO_PERSONAL_CONFIG_MSGVER_1"),onclick:e,className:i===BX.UI.EntityConfigScope.personal?"menu-popup-item-accept":"menu-popup-item-none"});t.push({id:"switchToCommonConfig",text:BX.message("UI_ENTITY_EDITOR_SWITCH_TO_COMMON_CONFIG_MSGVER_1"),onclick:e,className:i===BX.UI.EntityConfigScope.common?"menu-popup-item-accept":"menu-popup-item-none"})}if(this._config._userScopes){for(var n in this._config._userScopes){t.push({text:BX.message("UI_ENTITY_EDITOR_CHECK_SCOPE").replace("#SCOPE_NAME#",this._config._userScopes[n]["NAME"]),onclick:e,attributes:{"data-id":n},className:this._config.getScope()===BX.UI.EntityConfigScope.custom&&this._config._userScopeId===n?"menu-popup-item-accept":"menu-popup-item-none"})}}if(this.canChangeScheme()){if(this._config.isScopeToggleEnabled()){t.push({delimiter:true})}t.push({id:"resetConfig",text:BX.message("UI_ENTITY_EDITOR_RESET_CONFIG_MSGVER_1"),onclick:e,className:"menu-popup-item-none"});if(BX.prop.getBoolean(this._settings,"enableSettingsForAll",false)){t.push({id:"forceCommonConfigForAllUsers",text:BX.message("UI_ENTITY_EDITOR_FORCE_COMMON_CONFIG_FOR_ALL_MSGVER_1"),onclick:e,className:"menu-popup-item-none"})}if(this.moduleId&&this.canChangeCommonConfiguration()){t.push({delimiter:true});t.push({id:"createConfigForCheckedUsers",text:BX.message("UI_ENTITY_EDITOR_CREATE_SCOPE"),onclick:e,className:"menu-popup-item-none"});t.push({id:"editCommonConfig",text:BX.message("UI_ENTITY_EDITOR_UPDATE_SCOPE"),onclick:e,className:"menu-popup-item-none"})}}BX.onCustomEvent(window,this.eventsNamespace+":onPrepareConfigMenuItems",[this,t]);return t},getServiceUrl:function(){return this._serviceUrl},loadCustomHtml:function(t,e,i){e["ACTION"]=t;e["ACTION_ENTITY_ID"]=this._entityId;BX.ajax({url:this._serviceUrl,method:"POST",dataType:"html",data:e,onsuccess:i})},onFormSubmit:function(t,e){this._isRequestRunning=true;if(this._toolPanel){this._toolPanel.setLocked(true)}},onResize:function(t){this.adjustSize()},onPageTileClick:function(t){if(this._readOnly){return}if(this.isChanged()){this.showMessageDialog("titleEditDenied",BX.message("UI_ENTITY_EDITOR_TITLE_EDIT"),BX.message("UI_ENTITY_EDITOR_TITLE_EDIT_UNSAVED_CHANGES"));return}this.switchTitleMode(BX.UI.EntityEditorMode.edit)},onCreateSectionButtonClick:function(t){if(!this.isSectionCreationEnabled()){return}var e=this.getControlCount();var i="user_"+BX.util.getRandomString(8).toLowerCase();var n=BX.UI.EntitySchemeElement.create({type:"section",name:i,title:BX.message("UI_ENTITY_EDITOR_NEW_SECTION_TITLE")});var o={schemeElement:n,model:this._model};var s=this.getControlByIndex(0);if(!s){this.addSchemeElementAt(n,e);o.container=this._formElement}var r=this.createControl("section",i,o);if(s){s.addChild(r,{enableSaving:false})}else{this.addControlAt(r,0);this.saveScheme()}r.setMode(BX.UI.EntityEditorMode.edit,{notify:false});r.refreshLayout();r.setTitleMode(BX.UI.EntityEditorMode.edit);this.registerActiveControl(r)},onConfigMenuButtonClick:function(t){if(this._isConfigMenuShown){return}var e=this.prepareConfigMenuItems();if(e.length>0){BX.PopupMenu.show(this._id+"_config_menu",BX.getEventTarget(t),e,{angle:false,autoHide:true,closeByEsc:true,events:{onPopupShow:function(){this._isConfigMenuShown=true}.bind(this),onPopupClose:function(){BX.PopupMenu.destroy(this._id+"_config_menu")}.bind(this),onPopupDestroy:function(){this._isConfigMenuShown=false}.bind(this)}})}},onPageTitleExternalClick:function(t){var e=BX.getEventTarget(t);if(e!==this._pageTitleInput){this.savePageTitle();this.switchTitleMode(BX.UI.EntityEditorMode.view)}},onPageTitleKeyPress:function(t){var e=t.keyCode;if(e===13){this.savePageTitle();this.switchTitleMode(BX.UI.EntityEditorMode.view)}else if(e===27){this.switchTitleMode(BX.UI.EntityEditorMode.view)}},onInterfaceToolbarMenuBuild:function(t,e){var i=BX.prop.getArray(e,"items",null);if(!i){return}var n=this.prepareConfigMenuItems();if(n.length>0){if(i.length>0){i.push({delimiter:true})}for(var o=0,s=n.length;o<s;o++){i.push(n[o])}}},getCommonConfigEditUrl:function(t,e){return this._commonConfigEditUrl.replace(/#ENTITY_TYPE_ID_VALUE#/gi,t).replace(/#MODULE_ID#/gi,e)},onMenuItemClick:function(t,e){var i=BX.prop.getString(e,"id","");switch(i){case"resetConfig":this.resetConfig();break;case"switchToPersonalConfig":this.setConfigScope(BX.UI.EntityConfigScope.personal);break;case"switchToCommonConfig":this.setConfigScope(BX.UI.EntityConfigScope.common);break;case"forceCommonConfigForAllUsers":this.forceCommonConfigScopeForAll();break;case"createConfigForCheckedUsers":this.createConfigScopeForCheckedUsers();break;case"editCommonConfig":BX.SidePanel.Instance.open(this.getCommonConfigEditUrl(this._config._id,this.moduleId),{width:980});break;default:var n=BX.prop.getObject(e,"attributes","");if(n["data-id"]!==undefined){this.setConfigScope(BX.UI.EntityConfigScope.custom,n["data-id"])}}if(e.menuWindow){e.menuWindow.close()}},setConfigScope:function(t,e){if(t===this._config.getScope()&&this._config.getScope()!==BX.UI.EntityConfigScope.custom||t===BX.UI.EntityConfigScope.custom&&(e===undefined||e===this._config._userScopeId)){return}this._config.setScope(t,e,this.moduleId).then(function(){var i={id:this._id,moduleId:this.moduleId,scope:t,userScopeId:e,enableReload:true};BX.onCustomEvent(window,this.eventsNamespace+":onConfigScopeChange",[this,i]);if(i["enableReload"]&&!this._isEmbedded){window.location.reload(true)}}.bind(this))},createConfigScopeForCheckedUsers:function(){var t=BX.UI.EntityEditorScopeConfig.create(this._id+"_config",{editor:this,config:this._config.toJSON(),entityTypeId:this._config._id,isCommonConfig:true,moduleId:this.moduleId});t.open()},forceCommonConfigScopeForAll:function(){this._config.forceCommonScopeForAll().then(function(){var t=this._config.getScope();var e={id:this._id,scope:t,enableReload:true};BX.onCustomEvent(window,this.eventsNamespace+":onForceCommonConfigScopeForAll",[this,e]);if(e["enableReload"]&&!this._isEmbedded&&t!==BX.UI.EntityConfigScope.common){window.location.reload(true)}}.bind(this))},resetConfig:function(){this._config.reset(false).then(function(){var t=this._config.getScope();var e={id:this._id,scope:t,enableReload:true};BX.onCustomEvent(window,this.eventsNamespace+":onConfigReset",[this,e]);if(e["enableReload"]&&!this._isEmbedded){window.location.reload(true)}}.bind(this))},getConfigOption:function(t,e){return this._config.getOption(t,e)},setConfigOption:function(t,e){return this._config.setOption(t,e)},getOption:function(t,e){return BX.prop.getString(this._settings["options"],t,e)},setOption:function(t,e){if(typeof e==="undefined"||e===null){return}if(BX.prop.getString(this._settings["options"],t,null)===e){return}this._settings["options"][t]=e},getDragConfig:function(t){return BX.prop.getObject(this._dragConfig,t,{})},hasPlaceHolder:function(){return!!this._dragPlaceHolder},createPlaceHolder:function(t){var e=this.getControlCount();if(t<0||t>e){t=e>0?e:0}if(this._dragPlaceHolder){if(this._dragPlaceHolder.getIndex()===t){return this._dragPlaceHolder}this._dragPlaceHolder.clearLayout();this._dragPlaceHolder=null}this._dragPlaceHolder=BX.UI.EditorDragSectionPlaceholder.create({container:this._formElement,anchor:t<e?this._controls[t].getWrapper():null,index:t});this._dragPlaceHolder.layout();return this._dragPlaceHolder},getPlaceHolder:function(){return this._dragPlaceHolder},removePlaceHolder:function(){if(this._dragPlaceHolder){this._dragPlaceHolder.clearLayout();this._dragPlaceHolder=null}},processDraggedItemDrop:function(t,e){var i=t.getCharge();if(!(i instanceof BX.UI.EditorSectionDragContainer&&i.getEditor()===this)){return}var n=e.getContextData();var o=BX.type.isNotEmptyString(n["contextId"])?n["contextId"]:"";if(o!==BX.UI.EditorSectionDragItem.contextId){return}var s=typeof n["charge"]!=="undefined"?n["charge"]:null;if(!(s instanceof BX.UI.EditorSectionDragItem)){return}var r=s.getControl();if(!r){return}var a=this.getControlIndex(r);if(a<0){return}var l=this.getPlaceHolder();var h=l?l.getIndex():-1;if(h<0){return}var c=h<=a?h:h-1;if(c!==a){this.moveControl(r,c);this.saveScheme()}},onDrop:function(t){this.processDraggedItemDrop(t.data["dropContainer"],t.data["draggedItem"])},getConfigScope:function(){return this._config.getScope()},prepareFieldLayoutOptions:function(t){var e=t.hasContentToDisplay();var i={isNeedToDisplay:e||this._showEmptyFields};if(this.isExternalLayoutResolversEnabled()){var n={id:this._id,field:t,hasContent:e,showEmptyFields:this._showEmptyFields,layoutOptions:i};BX.onCustomEvent(window,this.eventsNamespace+":onResolveFieldLayoutOptions",[this,n])}return i},isExternalLayoutResolversEnabled:function(){return!!this._enableExternalLayoutResolvers},getRestriction:function(t){return BX.prop.getObject(this._restrictions,t,null)}};BX.UI.EntityEditor.defaultInstance=null;BX.UI.EntityEditor.items={};BX.UI.EntityEditor.get=function(t){return this.items.hasOwnProperty(t)?this.items[t]:null};if(typeof BX.UI.EntityEditor.messages==="undefined"){BX.UI.EntityEditor.messages={}}BX.UI.EntityEditor.setDefault=function(t){BX.UI.EntityEditor.defaultInstance=t};BX.UI.EntityEditor.getDefault=function(){return BX.UI.EntityEditor.defaultInstance};BX.UI.EntityEditor.create=function(t,e){var i=new BX.UI.EntityEditor;i.initialize(t,e);this.items[i.getId()]=i;return i}}if(typeof BX.UI.EntityEditorModeQueue==="undefined"){BX.UI.EntityEditorModeQueue=function(){this._id="";this._settings={};this._items=[]};BX.UI.EntityEditorModeQueue.prototype={initialize:function(t,e){this._id=BX.type.isNotEmptyString(t)?t:BX.util.getRandomString(4);this._settings=e?e:{}},findIndex:function(t){for(var e=0,i=this._items.length;e<i;e++){if(this._items[e]["control"]===t){return e}}return-1},getLength:function(){return this._items.length},add:function(t,e,i){if(typeof i==="undefined"){i=BX.UI.EntityEditorModeOptions.none}var n=this.findIndex(t);if(n>=0){this._items[n]={control:t,mode:e,options:i}}else{this._items.push({control:t,mode:e,options:i})}},addBatch:function(t,e,i){for(var n=0,o=t.length;n<o;n++){this.add(t[n],e,i)}},remove:function(t){var e=this.findIndex(t);if(e>=0){this._items.splice(e,1)}},clear:function(){this._items=[]},process:function(){var t=this._items.length;if(t===0){return 0}for(var e=0;e<t;e++){var i=this._items[e];i["control"].setMode(i["mode"],{options:i["options"],notify:true})}return t}};BX.UI.EntityEditorModeQueue.create=function(t,e){var i=new BX.UI.EntityEditorModeQueue;i.initialize(t,e);return i}}if(typeof BX.UI.EntityEditorModeSwitch==="undefined"){BX.UI.EntityEditorModeSwitch=function(){this._id="";this._settings={};this._queue=null;this._isRunning=false;this._runHandle=0;this._runAction=""};BX.UI.EntityEditorModeSwitch.prototype={initialize:function(t,e){this._id=BX.type.isNotEmptyString(t)?t:BX.util.getRandomString(4);this._settings=e?e:{};this._editor=BX.prop.get(this._settings,"editor");this._queue=BX.UI.EntityEditorModeQueue.create(this._id,{})},getQueue:function(){return this._queue},reset:function(){this._queue.clear();this._isRunning=false},isRunning:function(){return this._isRunning},setRunAction:function(t){this._runAction=t},run:function(){if(this._isRunning){return}if(this._runHandle>0){window.clearTimeout(this._runHandle)}this._runHandle=window.setTimeout(BX.delegate(this.doRun,this),50)},doRun:function(){this._editor.performSaveDelayedAction(this._runAction);this._isRunning=true;this._runHandle=0},complete:function(){this._queue.process();this.reset()}};BX.UI.EntityEditorModeSwitch.create=function(t,e){var i=new BX.UI.EntityEditorModeSwitch;i.initialize(t,e);return i}}if(typeof BX.UI.EntityEditorScopeConfig==="undefined"){BX.UI.EntityEditorScopeConfig=function(){this._id="";this._settings={};this._editor={};this._config={};this._isCommonConfig=false;this._popup=null;this._selector=null;this._name="";this._items=[];this._nameInput={};this._usersInput={};this._usersInputTagSelector={};this._forceSetInput={};this._nameInputError=null;this._usersInputError=null;this._entityId="";this._entityTypeId="";this._isOpened=false;this._closeNotifier=null;this.moduleId=null;this._onSquareClick=BX.delegate(this.onSquareClick,this)};BX.UI.EntityEditorScopeConfig.prototype={initialize:function(t,e){this._id=BX.type.isNotEmptyString(t)?t:BX.util.getRandomString(4);this._settings=e?e:{};this._editor=this.getSetting("editor",{});this._config=this.getSetting("config",{});this._isCommonConfig=this.getSetting("isCommonConfig",false);this._name=this.getSetting("name","");this._items=this.getSetting("items",[]);this._entityId=this.getSetting("entityId",null);this._entityTypeId=this.getSetting("entityTypeId",null);this.moduleId=this.getSetting("moduleId",null)},getId:function(){return this._id},getSetting:function(t,e){return this._settings.hasOwnProperty(t)?this._settings[t]:e},isOpened:function(){return this._isOpened},open:function(){if(this._isOpened){return}this._popup=this.createPopup();this._popup.show()},createPopup:function(){return this._popup||new BX.PopupWindow(this._id,null,{className:"ui-entity-editor-content-user-scope-popup",titleBar:BX.message("UI_ENTITY_EDITOR_CREATE_SCOPE"),closeIcon:true,autoHide:false,closeByEsc:true,padding:0,contentPadding:0,contentBackground:"none",draggable:true,minWidth:550,maxWidth:550,content:this.prepareContent(),buttons:this.prepareButtons(),events:{onPopupShow:BX.delegate(this.onPopupShow,this),onPopupClose:BX.delegate(this.onPopupClose,this),onPopupDestroy:BX.delegate(this.onPopupDestroy,this)}})},prepareContent:function(){var t=BX.create("div",{style:{padding:"0 20px"}});t.appendChild(this.prepareNameControl());t.appendChild(this.prepareUserSelectControl());t.appendChild(this.prepareForceSetToUsersControl());return t},prepareNameControl:function(){var t=BX.create("div",{style:{paddingBottom:"25px",marginBottom:"20px",borderBottom:"1px solid #f2f2f4"}});t.appendChild(BX.create("div",{props:{className:"ui-ctl-label-text"},text:BX.message("UI_ENTITY_EDITOR_CONFIG_SCOPE_NAME")}));var e=BX.create("div",{props:{className:"ui-ctl ui-ctl-textbox ui-ctl-w100"}});this._nameInput=BX.create("input",{props:{className:"ui-ctl-element",value:this.getName(),type:"text",placeholder:BX.message("UI_ENTITY_EDITOR_CONFIG_SCOPE_NAME_PLACEHOLDER")}});e.appendChild(this._nameInput);t.appendChild(e);return t},prepareUserSelectControl:function(){var t=BX.create("div",{style:{paddingBottom:"25px",marginBottom:"10px",borderBottom:"1px solid #f2f2f4"}});t.appendChild(BX.create("div",{props:{className:"ui-ctl-label-text"},text:BX.message("UI_ENTITY_EDITOR_CONFIG_SCOPE_MEMBERS")}));var e=BX.create("div",{props:{className:"ui-ctl ui-ctl-textbox ui-ctl-w100"}});this._usersInput=BX.create("div",{style:{width:"100%"},attrs:{id:"user-selector-item"}});e.appendChild(this._usersInput);t.appendChild(e);this._usersInputTagSelector=new BX.UI.EntitySelector.TagSelector({dialogOptions:{context:"UI_ENTITY_EDITOR_SCOPE",entities:[{id:"user"},{id:"project"},{id:"department",options:{selectMode:"usersAndDepartments"}}]}});this._usersInputTagSelector.renderTo(this._usersInput);return t},prepareForceSetToUsersControl:function(){var t=BX.create("div",{style:{paddingBottom:"10px",borderBottom:"1px solid #f2f2f4"}});var e=BX.create("div",{props:{className:"ui-ctl ui-ctl-checkbox ui-ctl-w100"}});this._forceSetInput=BX.create("input",{props:{className:"ui-ctl-element",type:"checkbox",checked:true}});e.appendChild(this._forceSetInput);e.appendChild(BX.create("div",{props:{className:"ui-ctl-label-text"},text:BX.message("UI_ENTITY_EDITOR_CONFIG_SCOPE_FORCE_INSTALL_TO_USERS")}));t.appendChild(e);return t},prepareButtons:function(){return[new BX.UI.Button({text:BX.message("UI_ENTITY_EDITOR_CONFIG_SCOPE_SAVE"),tag:BX.UI.Button.Tag.LINK,color:BX.UI.Button.Color.PRIMARY,events:{click:function(t,e){e.preventDefault();this.processSave()}.bind(this)}}),new BX.UI.Button({text:BX.message("UI_ENTITY_EDITOR_CONFIG_SCOPE_CANCEL"),tag:BX.UI.Button.Tag.LINK,color:BX.UI.Button.Color.LINK,events:{click:function(t,e){e.preventDefault();this.processCancel()}.bind(this)}})]},close:function(){if(this._popup){this._popup.close()}},addCloseListener:function(t){this._closeNotifier.addListener(t)},removeCloseListener:function(t){this._closeNotifier.removeListener(t)},createUserInfo:function(t){return{ID:t.id,FORMATTED_NAME:BX.util.htmlspecialcharsback(BX.prop.getString(t,"name",""))}},isCustomized:function(){var t=BX.prop.getObject(this._config,"accessCodes",[]);return!!Object.keys(t).length},getName:function(){return this._name},setName:function(t){this._name=t},processSave:function(){this.clearErrors();this.setName(this._nameInput.value);BX.ajax.runComponentAction("bitrix:ui.form.config","save",{data:{moduleId:this.moduleId,entityTypeId:this._entityTypeId,name:this.getName(),accessCodes:this.getSelectedItems(),config:this._config,params:{forceSetToUsers:this._forceSetInput.checked,categoryName:this._editor._config.categoryName,common:"Y"}}}).then(function(t){this.close();BX.UI.EntityEditorScopeConfig.prototype.notifyShow(t);var e=parseInt(t.data,10);this._editor.setConfigScope(BX.UI.EntityConfigScope.custom,e)}.bind(this)).catch(function(t){this.fillErrors(t.data)}.bind(this))},getSelectedItems:function(){var t=this._usersInputTagSelector.getTags();return t.map((function(t){return{id:t.id,entityId:t.entityId}}))},fillErrors:function(t){if(t.name){this._nameInputError=this.createErrorElement(this._nameInput,t.name.message)}if(t.accessCodes){this._usersInputError=this.createErrorElement(this._usersInput,t.accessCodes.message)}},createErrorElement:function(t,e){var i=BX.create("div",{props:{className:"ui-entity-section-control-error-text"}});i.innerHTML=e;t.parentNode.parentNode.appendChild(i);return i},clearErrors:function(){if(this._nameInputError){this._nameInputError.remove()}if(this._usersInputError){this._usersInputError.remove()}},notifyShow:function(t){window.top.BX.UI.Notification.Center.notify({content:BX.message("UI_ENTITY_EDITOR_CONFIG_SCOPE_SAVED"),width:"auto"})},processCancel:function(){this.close()},onPopupShow:function(){this._isOpened=true},onPopupClose:function(){if(this._popup){this._popup.destroy()}},onPopupDestroy:function(){this._isOpened=false;this._popup=null}};if(BX.UI.EntityEditorScopeConfig.messages===undefined){BX.UI.EntityEditorScopeConfig.messages={}}BX.UI.EntityEditorScopeConfig.create=function(t,e){var i=new BX.UI.EntityEditorScopeConfig;i.initialize(t,e);return i}} //# sourceMappingURL=editor.map.js