| Current Path : /var/www/homesaver/www/bitrix/components/bitrix/main.mail.form/templates/.default/ |
| Current File : /var/www/homesaver/www/bitrix/components/bitrix/main.mail.form/templates/.default/script.min.js |
(function(){if(window.BXMainMailForm)return;var e=function(t,i,o,a,r,n){if(e.__forms[t])return e.__forms[t];this.id=t;this.fields=i;this.selectedRecipients=r;this.replyTo=o;this.replyCC=a;this.options=n;this.fieldsData={};this.lastSearchText="";this.helpDeskCalendarCode=17198666;this.helpDeskCRMCalendarCode=17502612;e.__forms[this.id]=this};e.__forms={};e.getForm=function(t){return e.__forms[t]};e.prototype.getField=function(e){for(var t=this.fields.length;t-- >0;){if(this.fields[t].params.name==e)return this.fields[t]}return false};e.prototype.cleanFields=function(){var e=this.getFieldsData();for(var t in e){if(e.hasOwnProperty(t)){var i=e[t];if(BX.type.isFunction(i.tagSelector.removeTags)){i.tagSelector.removeTags()}}}};e.prototype.addTagsToField=function(e,t){for(var i in t){var o=t[i];var a=e.addItem(o);if(a){a.select()}}};e.prototype.addItemsToField=function(e,t){var i=false;t.forEach((function(t){if(Object.keys(t).length!==0){t.sort=1;t.tabs.push(e.getRecentTab().getId());e.removeItem(t);var o=e.addItem(t);if(o){o.select();i=true}}}));if(i){e.clearSearch()}};e.prototype.fillFieldsForReply=function(){this.cleanFields();var e=this.getFieldsData();for(var t in e){if(e.hasOwnProperty(t)){var i=e[t];if(t.toUpperCase()==="DATA[TO]"){this.addTagsToField(i.dialog,this.selectedRecipients)}}}};e.prototype.fillFieldsForReplyAll=function(){this.cleanFields();var e=this.getFieldsData();for(var t in e){if(e.hasOwnProperty(t)){var i=e[t];if(t.toUpperCase()==="DATA[TO]"){this.addTagsToField(i.dialog,this.replyTo)}else if(t.toUpperCase()==="DATA[CC]"){this.addTagsToField(i.dialog,this.replyCC)}}}};e.prototype.getFieldsData=function(){return this.fieldsData};e.prototype.setFieldData=function(e,t,i,o,a){if(BX.type.isUndefined(o)&&!BX.type.isUndefined(this.fieldsData[e])){o=this.fieldsData[e]["nodeForRender"]}this.fieldsData[e]={dialog:t,key:e,items:i,nodeForRender:o,tagSelector:a};if(!BX.type.isUndefined(o)){var r=o.querySelector("div");r.innerHTML="";for(var n=0;n<i.length;n++){var s=i[n];var l=i[n];s.forEach((function(e,t){l[t]=e}));r.appendChild(BX.create("INPUT",{props:{type:"hidden",name:e+"[]",value:JSON.stringify(l)}}))}}};e.prototype.onSubmit=function(e){var t=this;var i=BX.findChildByClassName(this.formWrapper,"main-mail-form-footer",false)||this.footerNode;var o=BX.findChildByClassName(i,"main-mail-form-submit-button",true);if(o.disabled)return BX.PreventDefault();this.fillFieldsFromDialogs();this.editor.OnSubmit();var a=i.cloneNode(true);Array.prototype.forEach.call(a.querySelectorAll("[id]"),(function(e){e.removeAttribute("id")}));BX(this.formId+"_dummy_footer").appendChild(a);e=e||window.event;BX.onCustomEvent(this,"MailForm:submit",[this,e]);if(!e.defaultPrevented&&e.returnValue!==false){BX.addClass(o,"ui-btn-wait");o.disabled=true;o.offsetHeight;if(this.options.submitAjax){BX.ajax.submitAjax(this.htmlForm,{url:this.htmlForm.getAttribute("action"),method:"POST",dataType:"json",onsuccess:function(e){o.disabled=false;BX.removeClass(o,"ui-btn-wait");BX.onCustomEvent(t,"MailForm:submit:ajaxSuccess",[t,e])},onfailure:function(e){o.disabled=false;BX.removeClass(o,"ui-btn-wait");BX.onCustomEvent(t,"MailForm:submit:ajaxFailure",[t,e])}});return BX.PreventDefault(e)}}};e.prototype.showError=function(e){var t=BX.findChildByClassName(this.formWrapper,"main-mail-form-error",true);var i=new BX.UI.Alert({text:e,inline:true,closeBtn:true,animate:true,color:BX.UI.Alert.Color.DANGER});t.innerHTML="";t.append(i.getContainer());this.initScrollable();if(this.__scrollable){var o=BX.pos(this.__scrollable);var a=BX.pos(this.formWrapper);var r=BX.pos(t);if(o.top>r.top-10-this.__scrollable.scrollTop)this.__scrollable.scrollTop=r.top-10;else if(o.bottom<a.bottom-10-this.__scrollable.scrollTop)this.__scrollable.scrollTop=a.bottom-10-o.bottom}};e.prototype.fillFieldsFromDialogs=function(){var e=this.getFieldsData();for(var t in e){if(e.hasOwnProperty(t)){var i=e[t];var o=i.dialog;if(o===null){return}if(BX.type.isFunction(o.getSelectedItems)){var a=o.getSelectedItems();var r=[];for(var n=0;n<a.length;n++){var s=a[n];if(BX.type.isFunction(s.getCustomData)){r.push(s.getCustomData())}}this.setFieldData(t,o,r,i.nodeForRender,i.tagSelector)}}}};e.prototype.addSearchInput=function(e){this.lastSearchText=e};e.prototype.unbindToAddressBookEvents=function(){top.BX.Event.EventEmitter.unsubscribe("BX.DialogEditContact:onSaveContact",e.prototype.onSaveContactToAddressBook)};e.prototype.onSaveContactToAddressBook=function(e,t,i){if(Object.keys(i.data)&&i.data.prefixId===t&&Array.isArray(i.data.items)){this.addItemsToField(e,i.data.items);this.unbindToAddressBookEvents()}};e.prototype.bindToAddressBookEvents=function(t,i,o="new"){var a=function(){this.unbindToAddressBookEvents();t.unsubscribe("onDestroy",a)}.bind(this);t.subscribe("onDestroy",a);var r=function(e){if(e.getSlider().getUrl()==="dialogEditContact_"+o+"_"+i){top.BX.removeCustomEvent("SidePanel.Slider:onCloseComplete",r);this.unbindToAddressBookEvents();t.getTagSelector().unlock()}}.bind(this);top.BX.addCustomEvent("SidePanel.Slider:onCloseComplete",r);top.BX.Event.EventEmitter.subscribe("BX.DialogEditContact:onSaveContact",e.prototype.onSaveContactToAddressBook.bind(this,t,i))};e.prototype.openEditContact=function(e,t,i,o){const a=this.generatePrefixSliderId();top.BX.Runtime.loadExtension("mail.dialogeditcontact").then((()=>{top.BX.Mail.AddressBook.DialogEditContact.openEditDialog({contactID:t,prefixId:a,contactData:{email:i,name:o}})}));this.bindToAddressBookEvents(e,a,t)};e.prototype.generatePrefixSliderId=function(){return Math.floor(Math.random()*1e3)};e.prototype.addContactToAddressBook=function(e,t=null){if(t!==null){this.lastSearchText=t}var i=function(t,i=false,o){const a=this.generatePrefixSliderId();var r;var n;if(t.includes("@")){r=t;n=""}else{r="";n=t;i=false}const s=top.BX.Mail.AddressBook.DialogEditContact.openCreateDialog({prefixId:a,showEmailError:i,responseError:o,contactData:{email:r,name:n}});this.bindToAddressBookEvents(e,a,s)}.bind(this);return new Promise(function(t,o){top.BX.Runtime.loadExtension("mail.dialogeditcontact").then(function(){if(BX.Validation.isEmail(this.lastSearchText)){top.BX.Mail.AddressBook.DialogEditContact.saveContact(this.lastSearchText,this.lastSearchText,"new").then(function(i){this.addItemsToField(e,i.data);t()}.bind(this)).catch(function(e){i(this.lastSearchText,false,e);o()}.bind(this))}else{i(this.lastSearchText,true);o()}}.bind(this))}.bind(this))};e.prototype.renderField=function(e,t,i,o,a,r,n,s,l,d){let c;var f=i+"_"+t;var u=[];var m={};var p={};var h={};var _={};var g={};const B=this.options.oldRecipientsMode;if(d==="MAIL"){u.push({id:"address_book",dynamicLoad:true},{id:"contact",dynamicLoad:true,dynamicSearch:true,filters:[{id:"mail.mailCrmRecipientAppearanceFilter"}],options:{onlyWithEmail:true}},{id:"company",dynamicLoad:true,dynamicSearch:true,filters:[{id:"mail.mailCrmRecipientAppearanceFilter"}],options:{onlyWithEmail:true}},{id:"lead",dynamicLoad:true,dynamicSearch:true,filters:[{id:"mail.mailCrmRecipientAppearanceFilter"}],options:{onlyWithEmail:true}},{id:"mail_crm_recipient",dynamicLoad:true});c=24146582}else{u.push({options:{ownerId:o,ownerType:a},id:"mail_recipient",dynamicLoad:true});if(B){u.push({id:"address_book",dynamicLoad:true})}c=24196378}if(d==="MAIL"||B){var I;p={tagClickable:true};function v(){I.show();BX.Dom.addClass(E,"hide-before")}function y(){I.hide();BX.Dom.removeClass(E,"hide-before")}var C;var E=BX.Dom.create("span",{props:{className:"ui-selector-footer-link ui-selector-footer-link-add"},text:BX.Loc.getMessage("MAIN_MAIL_FORM_ADDRESS_BOOK_FOOTER_ADD_BUTTON_MSGVER_1"),events:{click:function(){if(!I.isShown()){v();this.addContactToAddressBook(C).then(function(){y()}.bind(this)).catch(function(){y()}.bind(this))}}.bind(this)}});I=new BX.Loader({color:"#3bc8f5",offset:{left:"calc(-50% - 19px)",top:"-2px"},size:29,target:E});m={searchTabOptions:{stub:true,stubOptions:{title:BX.Loc.getMessage("MAIN_MAIL_FORM_ADDRESS_BOOK_EMPTY_SEARCH_TITLE_MSGVER_1"),subtitle:BX.Loc.getMessage("MAIN_MAIL_FORM_ADDRESS_BOOK_EMPTY_SEARCH_SUBTITLE_MSGVER_1")+"<br>"+`<a style="cursor: pointer;" onclick="top.BX.Helper.show('redirect=detail&code=${c}');">`+BX.Loc.getMessage("MAIN_MAIL_FORM_CRM_EMPTY_SEARCH_SUBTITLE_2")+"</a>",icon:"/bitrix/images/mail/entity_provider_icons/addressbook.svg",iconOpacity:85,arrow:true}},footer:[E]};g={allowCreateItem:true,footerOptions:{label:BX.Loc.getMessage("MAIN_MAIL_FORM_ADDRESS_BOOK_FOOTER_ADD_BUTTON_ALLOW_CREATE_ITEM_MSGVER_1")}};h={onInput:function(e){const t=e.getTarget();const i=t.getTextBoxValue();this.addSearchInput(i)}.bind(this),onBlur:function(){this.lastSearchText=""}.bind(this),"TagItem:onClick":e=>{const t=e.getData().item;if(t&&t.entityId==="address_book"){const e=C.getItem([t.getEntityId(),t.getId()]);const i=e.getCustomData();let o=Number(i.get("entityId"));const a=i.get("email");const r=i.get("name");if(C.getTagSelector().isLocked()){return}C.getTagSelector().lock();if(!BX.type.isNumber(o)||o===0){BX.ajax.runAction("mail.addressbook.getContactIdByEmail",{data:{email:a}}).then((e=>{o=e.data;if(BX.type.isNumber(o)&&o>0){this.openEditContact(C,o,a,r)}}))}else{this.openEditContact(C,o,a,r)}}}};_={"Search:onItemCreateAsync":function(e){return new Promise(function(t,i){const o=e.getData().searchQuery.getQuery();this.addContactToAddressBook(C,o).then(function(){t()}.bind(this)).catch(function(){i()}.bind(this))}.bind(this))}.bind(this)}}else{let A=BX.Loc.getMessage("MAIN_MAIL_FORM_CRM_EMPTY_SEARCH_TITLE");let X=BX.Loc.getMessage("MAIN_MAIL_FORM_CRM_EMPTY_SEARCH_SUBTITLE");switch(a){case"DEAL":A=BX.Loc.getMessage("MAIN_MAIL_FORM_CRM_EMPTY_SEARCH_TITLE_DEAL");X=BX.Loc.getMessage("MAIN_MAIL_FORM_CRM_EMPTY_SEARCH_SUBTITLE_DEAL");break;case"COMPANY":A=BX.Loc.getMessage("MAIN_MAIL_FORM_CRM_EMPTY_SEARCH_TITLE_COMPANY");X=BX.Loc.getMessage("MAIN_MAIL_FORM_CRM_EMPTY_SEARCH_SUBTITLE_COMPANY");break;case"LEAD":A=BX.Loc.getMessage("MAIN_MAIL_FORM_CRM_EMPTY_SEARCH_TITLE_LEAD");X=BX.Loc.getMessage("MAIN_MAIL_FORM_CRM_EMPTY_SEARCH_SUBTITLE_LEAD");break;case"CONTACT":A=BX.Loc.getMessage("MAIN_MAIL_FORM_CRM_EMPTY_SEARCH_TITLE_CONTACT");X=BX.Loc.getMessage("MAIN_MAIL_FORM_CRM_EMPTY_SEARCH_SUBTITLE_CONTACT");break;case"SMART_INVOICE":A=BX.Loc.getMessage("MAIN_MAIL_FORM_CRM_EMPTY_SEARCH_TITLE_SMART_INVOICE");X=BX.Loc.getMessage("MAIN_MAIL_FORM_CRM_EMPTY_SEARCH_SUBTITLE_SMART_INVOICE");break;case"QUOTE":A=BX.Loc.getMessage("MAIN_MAIL_FORM_CRM_EMPTY_SEARCH_TITLE_QUOTE");X=BX.Loc.getMessage("MAIN_MAIL_FORM_CRM_EMPTY_SEARCH_SUBTITLE_QUOTE");break}m={searchTabOptions:{stub:true,stubOptions:{title:A,subtitle:X+"<br>"+`<a style="cursor: pointer;" onclick="top.BX.Helper.show('redirect=detail&code=${c}');">`+BX.Loc.getMessage("MAIN_MAIL_FORM_CRM_EMPTY_SEARCH_SUBTITLE_2")+"</a>"}}}}var M=[];switch(t.toUpperCase()){case"DATA[TO]":if(l===true){M=n}else{M=r}break;case"DATA[CC]":if(l===true){M=s}break}if((d==="MAIL"||B)&&["DATA[TO]","DATA[CC]","DATA[BCC]"].includes(t.toUpperCase())||["DATA[CC]","DATA[BCC]"].includes(t.toUpperCase())){u.push({id:"user",filters:[{id:"mail.mailUserRecipientAppearanceFilter"}],options:{showInvitationFooter:false,onlyWithEmail:true}})}const S=new BX.UI.EntitySelector.TagSelector({textBoxWidth:220,tagMaxWidth:400,...p,dialogOptions:Object.assign({events:_,searchOptions:g,context:"MAIN_MAIL_FROM",id:f,entities:u,selectedItems:M},m),events:h});C=S.getDialog();this.setFieldData(t,C,[],e,S);S.renderTo(e)};e.prototype.init=function(t){t=t||{};var i=this;var o=t.isReplyAll??false;var a=this.selectedRecipients??[];var r=this.replyTo??[];var n=this.replyCC??[];var s=this.options.ownerId??null;var l=this.options.ownerType??null;var d=this.options.contextName??null;var c=Boolean(t.hideEmptyContactError);if(this.__inited){return false}this.formId="main_mail_form_"+this.id;var f=document.querySelectorAll('[data-field-form-id="'+this.formId+'"]');var u=Array.prototype.slice.call(f);u.forEach(function(e){var t=e.dataset.fieldFormId;var i=e.dataset.formFieldType;this.renderField(e,i,t,s,l,a,r,n,o,d)}.bind(this));this.configureMenuItemId="signature-configure";this.formWrapper=BX(this.formId);this.htmlForm=BX.findParent(this.formWrapper,{tag:"form"});if(d!=="MAIL"&&a.length===0&&!c){let e=BX.Loc.getMessage("MAIN_MAIL_FORM_MESSAGE_SEND_WARNING_EMPTY_RECIPIENT_DESCRIPTION");switch(l){case"DEAL":e=BX.Loc.getMessage("MAIN_MAIL_FORM_MESSAGE_SEND_WARNING_EMPTY_RECIPIENT_DESCRIPTION_DEAL");break;case"COMPANY":e=BX.Loc.getMessage("MAIN_MAIL_FORM_MESSAGE_SEND_WARNING_EMPTY_RECIPIENT_DESCRIPTION_COMPANY");break;case"LEAD":e=BX.Loc.getMessage("MAIN_MAIL_FORM_MESSAGE_SEND_WARNING_EMPTY_RECIPIENT_DESCRIPTION_LEAD");break;case"CONTACT":e=BX.Loc.getMessage("MAIN_MAIL_FORM_MESSAGE_SEND_WARNING_EMPTY_RECIPIENT_DESCRIPTION_CONTACT");break;case"SMART_INVOICE":e=BX.Loc.getMessage("MAIN_MAIL_FORM_MESSAGE_SEND_WARNING_EMPTY_RECIPIENT_DESCRIPTION_SMART_INVOICE");break;case"QUOTE":e=BX.Loc.getMessage("MAIN_MAIL_FORM_MESSAGE_SEND_WARNING_EMPTY_RECIPIENT_DESCRIPTION_QUOTE");break}const t=new BX.UI.Alert({text:e,color:BX.UI.Alert.Color.WARNING});t.renderTo(BX("main-mail-form-message-send-warning-empty"))}this.postForm=LHEPostForm.getHandler(this.formId+"_editor");this.editor=BXHtmlEditor.Get(this.formId+"_editor");this.editorInited=false;this.timestamp=(new Date).getTime();this.quoteNodeId=this.formId+"_quote_"+this.timestamp.toString(16);this.signatureNodeId=this.formId+"_signature_"+this.timestamp.toString(16);this.sharingLinkClassPrefix="_sharing_calendar_link";this.sharingLinkNodeClass=this.formId+this.sharingLinkClassPrefix;BX.addCustomEvent(this,"MailForm::from::change",BX.proxy((function(e,t){if(!BX.type.isString(t)){t="";var o=i.getSenderSignatures(e);var a=o[0];if(BX.type.isNotEmptyObject(a)&&BX.type.isNotEmptyString(a.full)){t=a.full}}this.rebuildSignatureMenu(o,e.params);this.insertSignature(t);this.appendCalendarLinkButton(e.params)}),this));this.initFields();this.initFooter();BX.bind(this.htmlForm,"submit",this.onSubmit.bind(this));this.__inited=true;BX.onCustomEvent(e,"MailForm:init:"+this.id,[this]);BX.addCustomEvent(this,"MailForm::editor::init",(()=>{this.showCalendarSharingInitialTour();BX(this.editor.GetIframeDoc()).onmouseup=()=>{this.userSelection=this.editor.GetIframeDoc().body};this.userSelection=this.editor.GetIframeDoc().body}));document.addEventListener("selectionchange",(()=>{this.userSelection=document.getSelection()}));this.hideAiImageGeneratorButton();return true};e.prototype.initScrollable=function(){if(!this.__scrollable){if(document.scrollingElement)this.__scrollable=document.scrollingElement}if(!this.__scrollable){if(document.documentElement.scrollTop>0||document.documentElement.scrollLeft>0)this.__scrollable=document.documentElement;else if(document.body.scrollTop>0||document.body.scrollLeft>0)this.__scrollable=document.body}if(!this.__scrollable){window.scrollBy(1,1);if(document.documentElement.scrollTop>0||document.documentElement.scrollLeft>0)this.__scrollable=document.documentElement;else if(document.body.scrollTop>0||document.body.scrollLeft>0)this.__scrollable=document.body;window.scrollBy(-1,-1)}};e.prototype.initFields=function(){for(var e=0,i;e<this.fields.length;e++){this.fields[e]=new t(this,this.fields[e]);i=this.fields[e].fieldId;this.fields[i]=this.fields[e]}var o=BX(this.formId+"_fields_footer");var a=BX(this.formId+"_fields_ext_footer");var r=[].concat(BX.findChildrenByClassName(o,"main-mail-form-field-button",true)||[]).concat(BX.findChildrenByClassName(a,"main-mail-form-field-button",true)||[]);for(var e=0,i;e<r.length;e++){i=r[e].getAttribute("data-target");if(typeof this.fields[i]!="undefined"){this.fields[i].__switch=r[e];BX.bind(r[e],"click",this.fields[i].unfold.bind(this.fields[i]))}}};e.prototype.initFooter=function(){var e=this;var t=BX.findChildByClassName(this.formWrapper,"main-mail-form-footer-wrapper",true);var i=BX.findChildByClassName(t,"main-mail-form-footer",false);this.footerNode=i;var o=BX.findChildrenByClassName(i,"main-mail-form-footer-button",true);for(var a in o){(function(t){BX.bind(t,"click",(function(){BX.onCustomEvent(e,"MailForm:footer:buttonClick",[e,t]);if(BX.hasClass(t,"main-mail-form-submit-button"))BX.submit(e.htmlForm)}))})(o[a])}var r=function(){if(BX.hasClass(i,"main-mail-form-footer-fixed")){BX.removeClass(i,"main-mail-form-footer-fixed-hidden");BX.removeClass(i,"main-mail-form-footer-fixed");i.style.left="";i.style.width="";t.style.height="";t.appendChild(i)}};var n=function(){e.initScrollable();if(e.formWrapper.offsetHeight>0&&e.__scrollable){var o=BX.pos(e.__scrollable);var a=BX.pos(e.formWrapper);if(o.bottom<a.bottom-10-e.__scrollable.scrollTop){i.style.left=a.left-o.left-e.__scrollable.scrollLeft+"px";i.style.width=e.formWrapper.offsetWidth+"px";if(!BX.hasClass(i,"main-mail-form-footer-fixed")){if(o.bottom<BX.pos(t).top-e.__scrollable.scrollTop)BX.addClass(i,"main-mail-form-footer-fixed-hidden");t.style.height=t.offsetHeight+"px";BX.addClass(i,"main-mail-form-footer-fixed");document.body.appendChild(i)}var n=BX.findChildByClassName(e.formWrapper,"main-mail-form-editor-wrapper",true);if(o.bottom<BX.pos(n).top+i.offsetHeight-e.__scrollable.scrollTop)BX.addClass(i,"main-mail-form-footer-fixed-hidden");else BX.removeClass(i,"main-mail-form-footer-fixed-hidden");return}}r()};var s=new MutationObserver((function(){e.initScrollable();if(e.__scrollable){var t=[e.__scrollable.scrollHeight,e.__scrollable.scrollTop].join(":");if(e.__scrollable.__lastState!=t){e.__scrollable.__lastState=t;n()}}}));var l=function(){setTimeout((function(){if(!e.__footerMonitoring){e.__footerMonitoring=true;s.observe(document.body,{attributes:true,childList:true,subtree:true});BX.bind(window,"resize",n);BX.bind(window,"scroll",n);BX.addCustomEvent(window,"AutoResizeFinished",n);n()}}),400)};var d=function(){e.__footerMonitoring=false;s.disconnect();BX.unbind(window,"resize",n);BX.unbind(window,"scroll",n);BX.removeCustomEvent(window,"AutoResizeFinished",n);r()};BX.addCustomEvent(this,"MailForm:show",l);BX.addCustomEvent(this,"MailForm:hide",d);if(this.formWrapper.offsetHeight>0)l()};e.prototype.insertSignature=function(e){if(this.editorInited){this.editor.synchro.Sync();var t=this.editor.GetIframeDoc().getElementById(this.signatureNodeId);if(!BX.type.isNotEmptyString(e)){if(t){BX.remove(t)}const e=this.editor.GetIframeDoc().getElementById(this.quoteNodeId);if(e&&!e.previousSibling){BX.Dom.insertBefore(BX.Tag.render`<br>`,e)}return}var i="--<br />"+e;if(t){t.innerHTML=i}else{t=BX.create("div",{attrs:{id:this.signatureNodeId},html:i});var o=this.editor.GetIframeDoc().getElementById(this.quoteNodeId);if(o){o.parentNode.insertBefore(t,o)}else{BX.append(t,this.editor.GetIframeDoc().body)}t.parentNode.insertBefore(document.createElement("BR"),t)}this.editor.synchro.FullSyncFromIframe()}else{BX.addCustomEvent(this,"MailForm::editor::init",BX.proxy((function(){this.insertSignature(e)}),this))}};var t=function(e,t){this.form=e;this.params=t;this.fieldId=this.form.formId+"_"+this.params.id;this.init()};t.prototype.init=function(){this.params.__row=BX(this.fieldId);if(t.__types[this.params.type]&&t.__types[this.params.type].init)t.__types[this.params.type].init(this);if(this.params.menu){var e=this;var i=BX.findChildByClassName(this.params.__row,"main-mail-form-field-value-menu-ext-button",true);BX.addCustomEvent(this.form,"MailForm::editor:click",(function(){var t=BX.PopupMenu.getMenuById(e.fieldId+"-menu-ext");if(t)t.close()}));BX.addCustomEvent("onSubMenuShow",(function(){var t=this.menuWindow;while(t.parentMenuWindow)t=t.parentMenuWindow;if(e.fieldId+"-menu-ext"==t.id)BX.addClass(this.subMenuWindow.popupWindow.popupContainer,"main-mail-form-field-value-menu-ext-content")}));BX.bind(i,"click",(function(){BX.onCustomEvent(e.form,"MailForm:field:setMenuExt",[e.form,e]);const t=[];e.__menuExt.forEach((e=>{if(e.value===null||!BX.type.isString(e.text)||e.text.length===0){return}if(e.items.length===0){t.push({id:e.value,entityId:e.text,title:e.text,customData:{field:e.value},tabs:["recents"]});return}const i=[];e.items.forEach((t=>{if(t.value!==undefined&&t.text!==undefined&&t.value.length>0&&t.text.length>0){i.push({supertitle:e.text,id:t.value,entityId:t.text,title:t.text,customData:{field:t.value},tabs:["recents"]})}}));t.push({id:e.value,entityId:e.text,title:e.text,tabs:["recents"],children:i})}));const i=new BX.UI.EntitySelector.Dialog({targetNode:this,width:500,height:300,multiple:false,dropdownMode:true,showAvatars:false,compactView:true,enableSearch:true,items:t,events:{"Item:onBeforeSelect":t=>{t.preventDefault();e.insert(t.getData().item.id)}}});i.show()}))}};t.prototype.setMenuExt=function(e){this.__menuExt=e};t.prototype.insert=function(e){if(t.__types[this.params.type]&&t.__types[this.params.type].insert)t.__types[this.params.type].insert(this,e)};t.prototype.setValue=function(e,i){if(t.__types[this.params.type]&&t.__types[this.params.type].setValue)t.__types[this.params.type].setValue(this,e,i)};t.prototype.show=function(){this.params.hidden=false;BX.addClass(this.fieldId,"main-mail-form-drop-animation");BX(this.fieldId).style.display=this.params.folded?"none":"";this.__switch.style.display=this.params.folded?"":"none"};t.prototype.hide=function(){this.params.hidden=true;BX(this.fieldId).style.display="none";this.__switch.style.display="none";BX.removeClass(this.fieldId,"main-mail-form-drop-animation")};t.prototype.fold=function(){this.params.folded=true;if(!this.params.hidden)this.__switch.style.display="";BX(this.fieldId).style.display="none";BX.removeClass(this.fieldId,"main-mail-form-drop-animation")};t.prototype.unfold=function(){this.params.folded=false;if(!this.params.hidden){BX.addClass(this.fieldId,"main-mail-form-drop-animation");BX(this.fieldId).style.display=""}this.__switch.style.display="none"};t.__types={list:{},text:{},from:{},rcpt:{},editor:{},files:{}};t.__types["list"].init=function(e){BX.addCustomEvent(e.form,"MailForm::editor:click",(function(){var t=BX.PopupMenu.getMenuById(e.fieldId+"-menu");if(t)t.close()}));var t=BX.findChildByClassName(e.params.__row,"main-mail-form-field-value-menu",true);BX.bind(t,"click",(function(){var i=BX(e.fieldId+"_value");var o=function(e,o){i.value=e;BX.adjust(t,{html:o})};var a=function(e,t){o(t.options.value,t.text);t.menuWindow.close()};var r=[];if(!e.params.required){r.push({text:BX.util.htmlspecialchars(e.params.placeholder),title:e.params.placeholder,value:"",onclick:a});r.push({delimiter:true})}for(var n in e.params.list){r.push({text:BX.util.htmlspecialchars(e.params.list[n]),title:e.params.list[n],value:n,onclick:a})}BX.PopupMenu.show(e.fieldId+"-menu",t,r,{className:"main-mail-form-field-value-menu-content",offsetLeft:40,angle:true,closeByEsc:true})}))};t.__types["from"].init=function(e){BX.addCustomEvent(e.form,"MailForm::editor:click",(function(){var t=BX.PopupMenu.getMenuById(e.fieldId+"-menu");if(t)t.close()}));BX.onCustomEvent(e.form,"MailForm::from::change",[e]);const t=BX(`${e.fieldId}_value`);let i=null;if(t){i=t.parentNode.querySelector(".sender-selector-button-text")}if(BX.UI.Mail?.SenderSelector&&i){const t=new MutationObserver((()=>{BX.onCustomEvent(e.form,"MailForm::from::change",[e])}));t.observe(i,{childList:true,subtree:true});return}var o=BX.findChildByClassName(e.params.__row,"main-mail-form-field-value-menu",true);BX.bind(o,"click",(function(){var t=BX(e.fieldId+"_value");BXMainMailConfirm.showList(e.fieldId,o,{required:e.params.required,placeholder:e.params.placeholder,selected:t.value,callback:function(i,a){t.value=i;BX.adjust(o,{html:BX.util.strip_tags(a)});BX.onCustomEvent(e.form,"MailForm::from::change",[e])}})}))};t.__types["rcpt"].init=function(e){var t=BX.findChildByClassName(e.params.__row,"main-mail-form-field-rcpt-item-more",true);var i=BX.findChildByClassName(e.params.__row,"main-mail-form-field-value-wrapper",true);var o=BX.findChildByClassName(e.params.__row,"main-mail-form-field-rcpt-add-link",true);var a=BX(e.fieldId+"_fvalue");e.selector=e.fieldId+"-selector";var r=function(r,n,s,l,d,c){if(!e.params.multiple){var f=BX.SocNetLogDestination.getSelected(e.selector);for(var u in f){if(u!=r.id||f[u]!=n)BX.SocNetLogDestination.deleteItem(u,f[u],e.selector)}}var m=document.createElement("SPAN");m.setAttribute("data-id",r.id);BX.addClass(m,"main-mail-form-field-rcpt-item");i.insertBefore(m,t.parentNode);m.appendChild(BX.create("INPUT",{props:{type:"hidden",name:e.params.name+"[]",value:JSON.stringify(r)}}));r.showEmail="N";if(e.params.email&&r.email&&r.email.length>0&&r.email!=r.name){r=BX.clone(r);r.name=r.name+" <"+r.email+">"}BX.SocNetLogDestination.BXfpSelectCallback({item:r,type:n,varName:"dummy_"+e.params.name,bUndeleted:false,containerInput:m,valueInput:a,formName:d,tagInputName:o,tagLink1:e.params.placeholder,tagLink2:e.params.placeholder});if("init"==c){var p=9;var h=BX.findChildrenByClassName(i,"main-mail-form-field-rcpt-item",false);if(h.length>p+1){for(var u=p;u<h.length;u++)h[u].style.display="none";t.setAttribute("title",t.getAttribute("title").replace(/-?\d+/,h.length-p));t.parentNode.style.display=""}}};var n=function(r,n,s,l){var d=BX.findChild(i,{attribute:{"data-id":r.id}},false);BX.SocNetLogDestination.BXfpUnSelectCallback.apply({formName:l,inputContainerName:d,inputName:a,tagInputName:o,tagLink1:e.params.placeholder,tagLink2:e.params.placeholder},[r]);if(d&&d.parentNode==i){if(!BX.findChildByClassName(d,"feed-add-post-destination"))i.removeChild(d)}var c=9;var f=0;var u=BX.findChildrenByClassName(i,"main-mail-form-field-rcpt-item",false);for(var m=0;m<u.length;m++){if(u[m].offsetHeight>0)f++}if(f<u.length&&(f<c||u.length<=c+1)){for(var m=0;m<u.length;m++){if(u[m].offsetHeight>0)continue;u[m].style.display="";f++;if(f>=Math.min(c,u.length)&&u.length>c+1)break}t.setAttribute("title",t.getAttribute("title").replace(/-?\d+/,u.length-c));if(f>=u.length)t.parentNode.style.display="none"}};if(e.form.options.version<2){var s={name:e.selector,searchInput:a,bindMainPopup:{node:i,offsetTop:"5px",offsetLeft:"15px"},bindSearchPopup:{node:i,offsetTop:"5px",offsetLeft:"15px"},callback:{select:r,unSelect:n,openDialog:BX.delegate(BX.SocNetLogDestination.BXfpOpenDialogCallback,{inputBoxName:a.parentNode,inputName:a,tagInputName:o}),closeDialog:function(){BX.onCustomEvent(e.form,"MailForm:field:rcptSelectorClose",[e.form,e]);BX.SocNetLogDestination.BXfpCloseDialogCallback.apply({inputBoxName:a.parentNode,inputName:a,tagInputName:o})},openSearch:BX.delegate(BX.SocNetLogDestination.BXfpOpenDialogCallback,{inputBoxName:a.parentNode,inputName:a,tagInputName:o})},items:{},itemsLast:{},itemsSelected:{},destSort:{}};if(e.params.selector){for(var l in e.params.selector)s[l]=e.params.selector[l]}BX.SocNetLogDestination.init(s);BX.bind(a,"keydown",BX.delegate(BX.SocNetLogDestination.BXfpSearchBefore,{formName:e.selector,inputName:a}));BX.bind(a,"keyup",BX.delegate(BX.SocNetLogDestination.BXfpSearch,{formName:e.selector,inputName:a,tagInputName:o}));BX.bind(a,"paste",BX.defer(BX.SocNetLogDestination.BXfpSearch,{formName:e.selector,inputName:a,tagInputName:o,onPasteEvent:true}));BX.bind(a,"blur",BX.delegate(BX.SocNetLogDestination.BXfpBlurInput,{inputBoxName:a.parentNode,tagInputName:o}));BX.bind(i,"click",(function(t){BX.SocNetLogDestination.openDialog(e.selector);BX.PreventDefault(t)}))}BX.bind(t,"click",(function(e){var t=BX.findChildrenByClassName(i,"main-mail-form-field-rcpt-item",false);for(var o=0;o<t.length;o++)t[o].style.display="";this.parentNode.style.display="none";BX.PreventDefault(e)}))};t.__types["editor"].init=function(e){var t=e.form.postForm;var o=e.form.editor;e.quoteNode=document.createElement("div");if(e.form.options.foldQuote||e.params.value){if(e.form.formId.includes("_crm_mail_template_edit_form_")&&e.params.value){e.quoteNode.innerHTML=e.params.value}else{const t=document.createElement("div");t.setAttribute("id",e.form.quoteNodeId);if(e.params.value){t.innerHTML=e.params.value}else{t.innerHTML="<br>"}BX.Dom.append(t,e.quoteNode)}}e.quoteNode.__folded=e.form.options.foldQuote??false;BX.onCustomEvent(t.eventNode,"OnShowLHE",["justShow"]);BX.addClass(o.dom.cont,"main-mail-form-editor");o.dom.toolbarCont.style.opacity="inherit";BX.addCustomEvent(o,"OnIframeClick",(function(){if(e.form.options.version<2){BX.SocNetLogDestination.abortSearchRequest();BX.SocNetLogDestination.closeSearch();BX.SocNetLogDestination.closeDialog()}BX.onCustomEvent(e.form,"MailForm::editor:click",[])}));var a=BX.findChildByClassName(e.form.htmlForm,"main-mail-form-quote-button",true);var r=function(){if(e.quoteNode.__folded){e.quoteNode.__folded=false;e.setValue(o.GetContent(),{quote:true,signature:false});o.Focus(false);BX.hide(a.parentNode.parentNode||a.parentNode);const t=o.iframeView?.copilot;if(!t||BX.Type.isFunction(t?.copilot?.setContextParameters)){return}const i=t.copilotParams?.contextParameters??{};i.isAddedQuote=true;t.copilot.setContextParameters(i)}};BX.bind(a,"click",r);var n=function(){if(o.GetViewMode()!="wysiwyg"){BX.removeCustomEvent(o,"OnSetViewAfter",n);r()}};BX.addCustomEvent(o,"OnSetViewAfter",n);if(t.parser){t.parser.disk_file.regexp=/(bxacid):(n?\d+)/gi}o.phpParser.AddBxNode("diskfile0",{Parse:function(t,i){var a=o.GetIframeDoc().getElementById(i)||BX.findChild(e.quoteNode,{attr:{id:i}},true);var t=o.GetBxTag(i);if(a&&t){var r=document.createElement("DIV");a=a.cloneNode(true);r.appendChild(a);if(a.tagName.toUpperCase()=="IMG"){var n="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==";a.setAttribute("data-bx-orig-src",a.getAttribute("src"));a.setAttribute("src",n);return r.innerHTML.replace(n,"bxacid:"+t.fileId)}return r.innerHTML}return"[ "+t.value+" ]"}});BX.addCustomEvent(t.eventNode,"OnFileUploadRemove",(function(t){o.synchro.Sync();for(i in o.bxTags){if(o.bxTags[i].fileId&&o.bxTags[i].fileId==t){var a=o.GetIframeDoc().getElementById(o.bxTags[i].id);if(a&&a.parentNode)a.parentNode.removeChild(a);var a=BX.findChild(e.quoteNode,{attr:{id:o.bxTags[i].id}},true);if(a&&a.parentNode)a.parentNode.removeChild(a);delete o.bxTags[i]}}o.synchro.FullSyncFromIframe()}));BX.addCustomEvent(o,"OnCreateIframeAfter",(function(){e.setValue("",{quote:true,signature:true});e.form.editorInited=true;BX.onCustomEvent(e.form,"MailForm::editor::init",[e])}));BX.addCustomEvent(e.form,"MailForm:show",(function(){e.form.editor.CheckAndReInit();e.form.editor.ResizeSceleton()}));BX.addCustomEvent(e.form,"MailForm:hide",(function(){e.form.editor.SaveContent()}));BX.addCustomEvent(e.form,"MailForm:submit",(function(){var t=o.GetContent();if(e.quoteNode.__folded)t+=o.Parse(e.quoteNode.innerHTML,true,false);BX(e.fieldId+"_value").value=t}))};t.__types["from"].setValue=function(e,t){var i=BX(e.fieldId+"_value");let o=BX.findChildByClassName(e.params.__row,"sender-selector-button-text",true);if(!o){o=BX.findChildByClassName(e.params.__row,"main-mail-form-field-value-menu",true)}if(!o){return}if(!t.trim()){if(!e.params.required){i.value="";BX.adjust(o,{html:""})}BX.onCustomEvent(e.form,"MailForm::from::change",[e,""]);return}if(e.params.mailboxes&&e.params.mailboxes.length>0){var a=new RegExp("[-/\\^$*+?.()|[]{}]","g");for(var r in e.params.mailboxes){var n=new RegExp("(^|<)"+e.params.mailboxes[r].email.replace(a,"\\$&")+"(>|$)","i");if(t.trim().match(n)){i.value=t;BX.adjust(o,{html:BX.util.htmlspecialchars(t)});BX.onCustomEvent(e.form,"MailForm::from::change",[e]);break}}}};t.__types["rcpt"].setValue=function(e,t){if(e.form.options.version<2){var i=BX.SocNetLogDestination.getSelected(e.selector);for(var o in i)BX.SocNetLogDestination.deleteItem(o,i[o],e.selector)}if(t&&BX.type.isPlainObject(t)){if(e.form.options.version<2){for(var o in t){if(t.hasOwnProperty(o)){BX.SocNetLogDestination.obItemsSelected[e.selector][o]=t[o];BX.SocNetLogDestination.runSelectCallback(o,t[o],e.selector,false,"init")}}}BX.onCustomEvent("BX.Main.SelectorV2:reInitDialog",[{selectorId:e.params.id,selectedItems:BX.clone(t)}])}};t.__types["text"].insert=function(e,t){var i=BX(e.fieldId+"_value");if(typeof i.selectionStart!="undefined"){var o={start:i.selectionStart,end:i.selectionEnd};i.value=i.value.substr(0,o.start)+t+i.value.substr(o.end);i.selectionStart=i.selectionEnd=o.start+t.length}else{i.value=i.value+t}i.focus()};t.__types["text"].setValue=function(e,t){var i=BX(e.fieldId+"_value");i.value=t};t.__types["editor"].insert=function(e,t){var i=e.form.editor;if(i.synchro.IsFocusedOnTextarea()){i.textareaView.WrapWith("","",t);if(i.textareaView.element&&typeof i.textareaView.element.selectionStart!="undefined")i.textareaView.element.selectionStart=i.textareaView.element.selectionEnd}else{i.selection.GetRange().deleteContents();i.InsertHtml(t)}i.Focus()};t.__types["editor"].setValue=function(e,t,i){const o=i.filesInfo;if(Array.isArray(o)){const e=new Map(i.filesInfo.map((e=>[e.serverFileId,e.serverPreviewUrl])));if(t.length>0&&e.size>0){for(let[i,o]of e){t=t.replace("bxacid:"+i,o+"&__bxacid="+i)}}}const a=e.form.editor;if(i&&i.signature){a.synchro.Sync();var r=a.GetIframeDoc().getElementById(e.form.signatureNodeId);if(r){var n=document.createElement("div");n.appendChild(r.cloneNode(true));t+=n.innerHTML}}if(i&&i.quote&&!e.quoteNode.__folded)t+=e.quoteNode.innerHTML;a.SetContent(t,true);var s=/[&?]__bxacid=(n?\d+)/;var l={IMG:"src",A:"href"};for(var d in l){var c=a.GetIframeDoc().getElementsByTagName(d);for(var f=0;f<c.length;f++){var u=c[f].getAttribute(l[d])?c[f].getAttribute(l[d]).match(s):false;if(u){c[f].removeAttribute("id");c[f].setAttribute(l[d],c[f].getAttribute(l[d]).replace(s,""));a.SetBxTag(c[f],{tag:"diskfile0",fileId:u[1]})}}}a.synchro.FullSyncFromIframe()};t.__types["files"].setValue=function(e,t){var i=e.form.postForm;i.controllerInit("show");for(var o in i.controllers){if(!i.controllers.hasOwnProperty(o))continue;var a=i.controllers[o];if(a.storage!="disk")continue;if(!a.handler)break;t=BX.clone(t);if(a.values){for(var r=0;r<t.length;r++){if(a.values[t[r].id])t.splice(r--,1)}}if(a.handler.removeFiles){a.handler.removeFiles(i.currentTemplateFiles)}a.handler.selectFile({},{},t);i.currentTemplateFiles=t.map((e=>e.serverFileId));break}};e.prototype.rebuildSignatureMenu=function(e,t){if(BX.type.isNotEmptyObject(t)&&BX.type.isNotEmptyString(t.signatureSelectTitle)&&BX.type.isNotEmptyString(t.signatureConfigureTitle)&&BX.type.isNotEmptyString(t.pathToMailSignatures)){if(!this.signatureSelectButton){this.appendSignatureSelectButton(t.signatureSelectTitle)}if(this.signatureSelectButton){this.initSignatureMenu(t.signatureConfigureTitle,t.pathToMailSignatures);this.removeSignaturesFromMenu();this.appendSignaturesToMenu(e)}}};e.prototype.appendSignatureSelectButton=function(e){var t="signature-select";this.postForm.getToolbar().insertAfter({BODY:"<i></i>"+e,ID:t});this.signatureSelectButton=this.getSelectButton(t)};e.prototype.getSelectButton=function(e){var t=this.postForm.getToolbar().getItems();for(var i in t){if(t.hasOwnProperty(i)&&t[i].attributes&&t[i].attributes.getNamedItem("data-id")&&t[i].attributes.getNamedItem("data-id").value===e){return t[i]}}return null};e.prototype.initSignatureMenu=function(e,t){if(!this.signatureSelectMenu){var i=this;this.signatureSelectMenu=new BX.PopupMenuWindow({maxWidth:300,maxHeight:300,bindElement:this.signatureSelectButton,items:[{id:this.configureMenuItemId,text:e,onclick:function(e,o){o.getMenuWindow().close();BX.SidePanel.Instance.open(t,{cacheable:false,events:{onCloseComplete:function(){i.ajaxRefreshSignatures()}}})}}]});var o=this.signatureSelectMenu;this.signatureSelectButton.addEventListener("click",(function(){if(o.getMenuItems().length>1){o.show()}else{BX.SidePanel.Instance.open(t,{cacheable:false,events:{onCloseComplete:function(){i.ajaxRefreshSignatures()}}})}}))}};e.prototype.ajaxRefreshSignatures=function(){var e=this;BX.ajax.runComponentAction("bitrix:main.mail.form","signatures",{mode:"class"}).then((function(t){if(BX.type.isNotEmptyObject(t)&&BX.type.isNotEmptyObject(t.data)&&t.data.hasOwnProperty("signatures")){for(var i in e.fields){if(e.fields.hasOwnProperty(i)&&BX.type.isNotEmptyObject(e.fields[i])&&BX.type.isNotEmptyObject(e.fields[i].params)&&e.fields[i].params.hasOwnProperty("allUserSignatures")){var o=e.fields[i];o.params.allUserSignatures=t.data.signatures;var a=e.getSenderSignatures(o);e.rebuildSignatureMenu(a,o.params);break}}}}))};e.prototype.getSenderSignatures=function(e){var t;var i=BX(e.fieldId+"_value");var o=[];if(i){t=i.value}if(t&&e.params&&BX.type.isArray(e.params.mailboxes)&&BX.type.isNotEmptyObject(e.params.allUserSignatures)){for(var a in e.params.mailboxes){if(e.params.mailboxes.hasOwnProperty(a)){if(e.params.mailboxes[a].formated===t){var r=e.params.mailboxes[a];var n=e.params.allUserSignatures;if(BX.type.isArrayFilled(n[r.formated])){o.push.apply(o,n[r.formated])}if(BX.type.isArrayFilled(n[r.email])){o.push.apply(o,n[r.email])}if(BX.type.isArrayFilled(n[""])){o.push.apply(o,n[""])}break}}}}return o};e.prototype.removeSignaturesFromMenu=function(){var e=this.signatureSelectMenu.getMenuItems().map((function(e){return e.getId()}));for(var t in e){if(e.hasOwnProperty(t)&&e[t]!==this.configureMenuItemId){this.signatureSelectMenu.removeMenuItem(e[t])}}};e.prototype.appendSignaturesToMenu=function(e){var t=this.getSignatureSelectItemsMenu(e);for(var i in t){if(t.hasOwnProperty(i)){this.signatureSelectMenu.addMenuItem(t[i],this.configureMenuItemId)}}};e.prototype.getSignatureSelectItemsMenu=function(e){var t=[];if(BX.type.isArrayFilled(e)){var i=this;for(var o in e){if(e.hasOwnProperty(o)&&BX.type.isNotEmptyObject(e[o])&&BX.type.isNotEmptyString(e[o].list)&&BX.type.isNotEmptyString(e[o].full)){t.push({id:"signature-"+o,text:e[o].list,title:e[o].list,fullSignature:e[o].full,onclick:function(e,t){t.getMenuWindow().close();i.insertSignature(t.fullSignature)}})}}if(t.length){t.push({id:"after-signatures-delimiter",delimiter:true})}}return t};e.prototype.appendCalendarLinkButton=function(e){if(BX.type.isNotEmptyObject(e)&&BX.type.isBoolean(e.showCalendarSharingButton)&&!this.calendarSharingLinkButton){const t="calendar-sharing-link";const i=this.options.ownerType??null;const o=e.sharingFeatureLimitEnable||e.crmSharingFeatureLimitEnable&&i==="DEAL";if(o){this.postForm.getToolbar().insertAfter({BODY:`<i></i>${BX.Loc.getMessage("MAIN_MAIL_FORM_EDITOR_CALENDAR_SHARING_SELECT")}`,ID:t})}else{this.postForm.getToolbar().insertAfter({BODY:`<div class="--locked"><i></i>${BX.Loc.getMessage("MAIN_MAIL_FORM_EDITOR_CALENDAR_SHARING_SELECT")}</div>`,ID:t})}this.calendarSharingLinkButton=this.getSelectButton(t);if(o){BX.Event.bind(this.calendarSharingLinkButton,"click",this.insertCalendarSharingLink.bind(this));this.calendarSharingLoader=new BX.Loader({target:this.calendarSharingLinkButton,size:20,mode:"inline",offset:{left:"4%",top:"-2%"}});this.initPopupOpenCalendar()}else{BX.Event.bind(this.calendarSharingLinkButton,"click",(()=>{this.showCalendarSharingLimit(i)}))}}};e.prototype.insertCalendarSharingLink=function(){const e=this.options.ownerId??null;const t=this.options.ownerType??null;this.calendarSharingLoader.show();BX.ajax.runComponentAction("bitrix:main.mail.form","getCalendarSharingLink",{mode:"class",data:{entityId:e,entityType:t}}).then((e=>{if(BX.type.isNotEmptyObject(e)&&BX.type.isNotEmptyObject(e.data)&&Object.hasOwn(e.data,"isSharingFeatureEnabled")){if(e.data.isSharingFeatureEnabled===true){const t=BX.Text.encode(e.data.sharingUrl);const i=this.getCalendarSharingText(t);this.insertCalendarSharingMessage(i);const o=this.editor.selection.GetRange();o.setStartAfter(i);o.setEndAfter(i);this.editor.selection.SetSelection(o)}else{this.popupOpenCalendar.show()}}this.calendarSharingLoader.hide()}))};e.prototype.showCalendarSharingLimit=function(e){if(e==="DEAL"){BX.UI.InfoHelper.show("limit_crm_calendar_free_slots")}else{BX.Runtime.loadExtension("ui.info-helper").then((({FeaturePromotersRegistry:e})=>{if(e){e.getPromoter({featureId:"calendar_sharing"}).show()}})).catch((e=>{}))}};e.prototype.insertCalendarSharingMessage=function(e){const t=this.editor.selection.GetRange();if(this.userSelection===this.editor.GetIframeDoc().body){const i=["DIV","HTML","BODY"];const o=t.endContainer.parentElement.tagName;if(i.includes(o)){this.editor.selection.InsertNode(e,t);return}t.endContainer.parentElement.after(e);return}const i=this.editor.GetIframeDoc().getElementById(this.signatureNodeId);if(i){i.before(e);return}const o=this.editor.GetIframeDoc().getElementById(this.quoteNodeId);if(o){o.before(e);return}t.setStartAfter(this.editor.GetIframeDoc().body.lastChild);t.setEndAfter(this.editor.GetIframeDoc().body.lastChild);this.editor.selection.SetSelection(t);this.editor.selection.InsertNode(e,t)};e.prototype.getCalendarSharingText=function(e){return BX.Tag.render`
<span>
${BX.Loc.getMessage("MAIN_MAIL_FORM_EDITOR_CALENDAR_SHARING_TEXT_MSGVER_1",{"[sharing_link]":`<a class="${this.sharingLinkNodeClass}" href="${e}">`,"[/sharing_link]":"</a>","#SHARING_LINK#":e})}
</span>
`};e.prototype.initPopupOpenCalendar=function(){this.popupOpenCalendar=BX.Main.PopupManager.create({id:"popup-calendar-sharing-link",titleBar:BX.Loc.getMessage("MAIN_MAIL_FORM_EDITOR_CALENDAR_SHARING_POPUP_CALENDAR_TITLE"),content:BX.Loc.getMessage("MAIN_MAIL_FORM_EDITOR_CALENDAR_SHARING_POPUP_CALENDAR_TEXT"),width:400,angle:true,overlay:true,bindElement:this.calendarSharingLinkButton,offsetLeft:40,buttons:[new BX.UI.CloseButton({text:BX.Loc.getMessage("MAIN_MAIL_FORM_EDITOR_CALENDAR_SHARING_POPUP_CALENDAR_OPEN_BUTTON"),color:BX.UI.ButtonColor.PRIMARY,events:{click:()=>{BX.SidePanel.Instance.open(this.options.userCalendarPath);this.popupOpenCalendar.close()}}}),new BX.UI.CancelButton({events:{click:()=>{this.popupOpenCalendar.close()}}})]})};e.prototype.needShowCalendarTour=function(){const e=function e(t){return BX.type.isNotEmptyObject(t)&&Object.hasOwn(t.params,"showCalendarSharingTour")};return this.fields.find((t=>e(t)))?.params?.showCalendarSharingTour??false};e.prototype.showCalendarSharingInitialTour=function(){if(!this.needShowCalendarTour()){return}const e=this.options.calendarSharingTourId;const t=this.options.ownerType;BX.ajax.runComponentAction("bitrix:main.mail.form","getCalendarSharingLink",{mode:"class"}).then((i=>{if(BX.type.isNotEmptyObject(i)&&BX.type.isNotEmptyObject(i.data)&&Object.hasOwn(i.data,"isSharingFeatureEnabled")){let o=BX.Loc.getMessage("MAIN_MAIL_FORM_EDITOR_CALENDAR_SHARING_TOUR_TITLE");let a="";let r=this.helpDeskCalendarCode;if(t==="DEAL"&&i.data.sharingLink!==""){o=BX.Loc.getMessage("MAIN_MAIL_FORM_EDITOR_CALENDAR_SHARING_TOUR_DEAL_TITLE");a=BX.Loc.getMessage("MAIN_MAIL_FORM_EDITOR_CALENDAR_SHARING_TOUR_DEAL_TEXT");r=this.helpDeskCRMCalendarCode}else if(i.data.isSharingFeatureEnabled===true){a=BX.Loc.getMessage("MAIN_MAIL_FORM_EDITOR_CALENDAR_SHARING_TOUR_SETTING_IS_ACTIVATE_TEXT")}else{a=BX.Loc.getMessage("MAIN_MAIL_FORM_EDITOR_CALENDAR_SHARING_TOUR_SETTING_IS_DEACTIVATE_TEXT")}const n=new BX.UI.Tour.Guide({id:e,autoSave:true,simpleMode:true,steps:[{position:"top",title:o,text:a,article:r}]});const s=n.getPopup();s.setWidth(400);setTimeout((()=>{const e=n.getCurrentStep();if(e){n.scrollToTarget(this.calendarSharingLinkButton);e.setTarget(this.calendarSharingLinkButton);n.start()}}),1500)}}))};e.prototype.updateSharingLinkNode=function(e,t=null){const i=(new DOMParser).parseFromString(e,"text/html");const o=i.getElementsByClassName(this.sharingLinkNodeClass);for(const e of o){if(t){e.innerText=t;e.href=t}else{e.remove()}}return i.documentElement.innerHTML};e.prototype.hideAiImageGeneratorButton=function(){if(this.editorInited){this.editor.toolbar.HideControl("ai-image-generator")}else{BX.addCustomEvent(this,"MailForm::editor::init",(()=>{this.editor.toolbar.HideControl("ai-image-generator")}))}};window.BXMainMailForm=e})();
//# sourceMappingURL=script.map.js