text: BX.namespace("BX.Bitrix24.Configs.Vm");BX.Bitrix24.Configs.Vm={init:function(t){t=typeof t==="object"?t:{};this.ajaxPath=t.ajaxPath||null;this.siteNameConf=t.siteNameConf||"";if(BX.type.isDomNode(BX("smtp_use_auth"))){BX.bind(BX("smtp_use_auth"),"change",BX.proxy(function(){this.showHideSmtpAuth()},this))}BX.bind(BX("certificate_lets_encrypt"),"click",BX.proxy(function(){this.showCertificatePopup("le")},this));BX.bind(BX("certificate_self"),"click",BX.proxy(function(){this.showCertificatePopup("self")},this));BX.bind(BX("certificate_self_key_path_file"),"change",BX.proxy(function(){this.uploadFile("certificate_self_key_path_file","certificate_self_key_path")},this));BX.bind(BX("certificate_self_path_file"),"change",BX.proxy(function(){this.uploadFile("certificate_self_path_file","certificate_self_path")},this));BX.bind(BX("certificate_self_path_chain_file"),"change",BX.proxy(function(){this.uploadFile("certificate_self_path_chain_file","certificate_self_path_chain")},this))},showHideSmtpAuth:function(){var t=BX("configPostForm").querySelectorAll("[data-role='smtp-auth']");if(t){for(var e=0,i=t.length;e<i;e++){t[e].style.display=BX("smtp_use_auth").checked?"":"none"}}},submitForm:function(t){if(BX.type.isDomNode(BX("smtp-pass-block"))){if(BX("smtp-pass-block").style.display=="none"){BX.remove(BX("smtp-pass-block"))}}BX.addClass(t,"webform-button-wait webform-button-active");BX.submit(BX("configPostForm"))},showCertificatePopup:function(t){BX.PopupWindowManager.create("certificate-popup-"+t,null,{closeIcon:true,contentNoPaddings:false,content:t=="self"?BX("self_certificate_popup_content"):BX("lets_encrypt_popup_content"),titleBar:BX.message("CONFIG_VM_CERTIFICATE_TITLE"),width:470,buttons:[button=new BX.PopupWindowButton({text:BX.message("CONFIG_VM_START"),className:"popup-window-button-create",events:{click:BX.proxy(function(){BX.addClass(button.buttonNode,"popup-window-button-wait");if(t=="self"){var e={keyPath:BX("certificate_self_key_path").value,path:BX("certificate_self_path").value,chainPath:BX("certificate_self_path_chain").value,siteNameConf:this.siteNameConf};BX("self_certificate_popup_content").innerHTML=BX.message("CONFIG_VM_CERTIFICATE_PROCESS")}else{e={email:BX("certificate_lets_email").value,dns:BX("certificate_lets_dns").value,siteNameConf:this.siteNameConf};BX("lets_encrypt_popup_content").innerHTML=BX.message("CONFIG_VM_CERTIFICATE_PROCESS")}BX.ajax({method:"POST",dataType:"json",url:this.ajaxPath,data:{sessid:BX.bitrix_sessid(),action:"set_certificate",type:t,certificateData:e},onsuccess:BX.proxy(function(t){if(t.hasOwnProperty("error")){alert(t.error)}else{this.interval=setInterval(BX.proxy(function(){this.checkCertitficateState()},this),15e3)}},this),onfailure:function(){}})},this)}}),new BX.PopupWindowButton({text:BX.message("MENU_CANCEL"),className:"popup-window-button-link popup-window-button-link-cancel",events:{click:function(){this.popupWindow.close()}}})]}).show()},checkCertitficateState:function(){BX.ajax({method:"POST",dataType:"json",url:this.ajaxPath,data:{sessid:BX.bitrix_sessid(),action:"check_state"},onsuccess:BX.proxy(function(t){if(t.hasOwnProperty("success")){document.location.reload()}else if(t.hasOwnProperty("error")){alert(t.error)}},this),onfailure:function(){}})},uploadFile:function(t,e){var i=BX("self_certificate_form");if(BX.type.isDomNode(BX(t))){BX.addClass(BX.previousSibling(BX(t)),"webform-button-wait")}var a=new BX.ajax.FormData;if(a.isSupported()){a.append("sessid",BX.bitrix_sessid());a.append("action","upload_files");for(var s=0;s<i.elements.length;s++){if(i[s].name==t)a.append(i[s].name,i[s].files[0])}a.send(this.ajaxPath,function(i){if(i){BX(e).value=decodeURIComponent(i);BX.removeClass(BX.previousSibling(BX(t)),"webform-button-wait")}})}}};