text: (function(){BX.namespace("BX.Mail.Client.Message.List.UserInterfaceManager");BX.Mail.Client.Message.List.UserInterfaceManager=function(e){this.gridId=e.gridId;this.mailboxId=e.mailboxId;this.userHasCrmActivityPermission=e.userHasCrmActivityPermission;this.spamDir=e.spamDir;this.outcomeDir=e.outcomeDir;this.trashDir=e.trashDir;this.taskViewUrlTemplate=e.taskViewUrlTemplate;this.taskViewUrlIdForReplacement=e.taskViewUrlIdForReplacement;this.ENTITY_TYPE_NO_BIND=e.ENTITY_TYPE_NO_BIND;this.ENTITY_TYPE_CRM_ACTIVITY=e.ENTITY_TYPE_CRM_ACTIVITY;this.ENTITY_TYPE_TASKS_TASK=e.ENTITY_TYPE_TASKS_TASK;this.mailboxMenu=e.mailboxMenu;this.settingsMenu=e.settingsMenu;this.unreadCounterSelector='[data-role="unreadCounter"]';this.emptyCountersTitleSelector='[data-role="emptyCountersTitle"]';this.readActionBtnRole="read-action";this.spamActionBtnRole="spam-action";this.crmActionBtnRole="crm-action";this.hideClassName="main-ui-hide";this.countersBlock=document.querySelector("#mail-msg-counter-title");this.mailboxMenuToggle=document.querySelector('[data-role="mailbox-current-title"]');this.settingsToggle=document.querySelector('[data-role="mail-list-settings-menu-popup-toggle"]');this.totalUnseen=document.querySelector('[data-role="unseen-total"]');this.mailboxesUnseen={};for(var t=0;t<this.mailboxMenu.length;t++){if(!(this.mailboxMenu[t]&&this.mailboxMenu[t].dataset)){continue}this.mailboxesUnseen[this.mailboxMenu[t].dataset.mailboxId]=this.mailboxMenu[t].dataset.unseen}this.UNREAD_COUNTER_TYPE="unread";this.isCurrentFolderSpam=false;this.isCurrentFolderTrash=false;this.isCurrentFolderOutcome=false;this.setCurrentFolderFlags(this.getFilterInstance());this.addEventHandlers();this.updateLeftMenuCounter();this.setDefaultBtnTitles()};BX.Mail.Client.Message.List.UserInterfaceManager.prototype={addEventHandlers:function(){if(this.mailboxMenuToggle){BX.bind(this.mailboxMenuToggle,"click",BX.delegate(this.onMailboxMenuClick,this))}if(this.settingsToggle){BX.bind(this.settingsToggle,"click",BX.delegate(this.onSettingsToggleClick,this))}BX.addCustomEvent("BX.Main.Filter:apply",this.onApplyFilter.bind(this));BX.addCustomEvent("BX.UI.ActionPanel:hidePanel",this.setDefaultBtnTitles.bind(this));BX.addCustomEvent("Grid::updated",this.setDefaultBtnTitles.bind(this));BX.addCustomEvent("Grid::thereSelectedRows",this.handleGridSelectItem.bind(this));BX.addCustomEvent("Grid::allRowsSelected",this.handleGridSelectItem.bind(this));BX.addCustomEvent("SidePanel.Slider:onMessage",function(e){if(e.getEventId()==="mail-message-view"){var t=BX.findParent(document.querySelector(".mail-msg-list-cell-"+e.getData().id),{tagName:"tr"});if(t&&t.dataset.id&&t.getElementsByClassName("mail-msg-list-cell-unseen").length!==0){this.updateUnreadCounters(-1);this.onMessagesRead([t.dataset.id],{action:"markAsSeen"})}}else if(e.getEventId()==="Mail.Client.MessageCreatedSuccess"){if(this.isCurrentFolderOutcome){this.reloadGrid({})}this.resetGridSelection()}}.bind(this));BX.addCustomEvent("onPullEvent-mail",this.onBindingCreated.bind(this));this.trackActionPanelStyleChange();BX.addCustomEvent(window,"onPopupShow",function(e){if(!(e.uniquePopupId.indexOf("menu-popup-main-grid-actions-menu-")==0&&e.getPopupContainer()&&e.bindElement&&e.bindElement.parentElement)){return}this.updateRowMenuSeenBtn(e);this.updateRowMenuSpamBtn(e);this.updateRowMenuCrmBtn(e)}.bind(this))},onCrmBindingDeleted:function(e){var t=document.querySelector(".js-bind-"+e);if(!t){return}var i=this.ENTITY_TYPE_CRM_ACTIVITY;var n=t.querySelector('[data-type="'+i+'"]');if(!n){return}n.parentNode.removeChild(n);var s=t.firstChild;var a=t.lastChild;if(s&&s.dataset&&s.dataset.role==="comma-separator"){s.parentNode.removeChild(s)}if(a&&a.dataset&&a.dataset.role==="comma-separator"){a.parentNode.removeChild(a)}if(t.childElementCount===0){this.updateGridByUnbindFilter()}},onBindingCreated:function(e,t){if("messageBindingCreated"===e&&this.mailboxId==t.mailboxId){this.resetGridSelection();var i=document.querySelector(".js-bind-"+t.messageId);if(i){var n=false;var s=i.querySelectorAll("[data-type]");if(s&&s.length>0){for(var a=0;a<s.length;a++){if(s[a].dataset.type===t.entityType){n=true;break}}}if(!n){var r;switch(t.entityType){case this.ENTITY_TYPE_TASKS_TASK:r=BX.create("a",{attrs:{href:this.taskViewUrlTemplate.replace(new RegExp(this.taskViewUrlIdForReplacement,"g"),t.entityId)},children:[BX.create("span",{dataset:{type:t.entityType},text:BX.message("MAIL_MESSAGE_LIST_COLUMN_BIND_TASKS_TASK")})]});break;case this.ENTITY_TYPE_CRM_ACTIVITY:if(this.userHasCrmActivityPermission){r=BX.create("span",{dataset:{role:"crm-binding-link",entityId:t.entityId,type:t.entityType},children:[BX.create("a",{attrs:{href:t.bindingEntityLink?t.bindingEntityLink:"#"},text:BX.message("MAIL_MESSAGE_LIST_COLUMN_BIND_CRM_ACTIVITY")})]});break}r=BX.create("span",{dataset:{type:t.entityType},text:BX.message("MAIL_MESSAGE_LIST_COLUMN_BIND_CRM_ACTIVITY")});break;default:break}if(r){if(s.length>0){i.appendChild(document.createTextNode(", "))}i.appendChild(r);this.updateGridByUnbindFilter()}}}}},trackActionPanelStyleChange:function(){var e=document.querySelector(".ui-action-panel");if(!e){return}var t=this.getGridHeaderCheckbox();if(!t){return}var i=BX.Main.gridManager.getById(this.gridId).instance;var n=t.cloneNode(true);var s=BX.findChildByClassName(n,"main-grid-check-all",true);s.removeAttribute("id");BX.bind(s,"change",i._clickOnCheckAll.bind(i));var a=function(e,t){if(t===i){s.checked=t.getRows().getBodyChild().length>0&&t.getRows().isAllSelected()}};BX.addCustomEvent("Grid::selectRow",a);BX.addCustomEvent("Grid::unselectRow",a);BX.addCustomEvent("BX.UI.ActionPanel:hidePanel",function(){setTimeout(a.bind(null,null,i),0)});BX.addCustomEvent("Grid::disabled",function(e){if(e===i){s.checked=false;s.disabled=true}});BX.addCustomEvent("Grid::enabled",function(e){if(e===i){s.disabled=false}});e.insertBefore(n,e.firstChild)},getGridHeaderCheckbox:function(){if(this.gridHeaderCheckbox===undefined){this.gridHeaderCheckbox=document.querySelector("#"+this.gridId+"_table .main-grid-cell-head.main-grid-cell-checkbox")}return this.gridHeaderCheckbox},showElement:function(e,t){if(e&&t){e.style.display="block"}else if(e){e.classList.remove(this.hideClassName)}},hideElement:function(e,t){if(e&&t){e.style.display="none"}else if(e){e.classList.add(this.hideClassName)}},updateRowMenuSpamBtn:function(e){var t=BX.findParent(e.getPopupContainer().querySelector('[data-role^="not-spam"]'),{className:"menu-popup-item"});var i=BX.findParent(e.getPopupContainer().querySelector('[data-role^="spam"]'),{className:"menu-popup-item"});if(this.isCurrentFolderSpam){this.showElement(t,true);this.hideElement(i,true)}else{this.showElement(i,true);this.hideElement(t,true)}},updateRowMenuCrmBtn:function(e){var t=BX.findParent(e.bindElement.parentElement,{className:"main-grid-row"});if(t&&t.dataset&&t.dataset.id){var i=this.getGridInstance().getRows().getById(t.dataset.id);if(i){i.getActionsMenu()}var n=BX.findParent(e.getPopupContainer().querySelector('[data-role^="crm"]'),{className:"menu-popup-item"});var s=BX.findParent(e.getPopupContainer().querySelector('[data-role^="not-crm"]'),{className:"menu-popup-item"});var a=this.isAddToCrmActionAvailable(i.node);if(a){this.showElement(n,true);this.hideElement(s,true)}else{this.showElement(s,true);this.hideElement(n,true)}}},isAddToCrmActionAvailable:function(e){if(e){var t=e.querySelector('[class^="js-bind"]');if(t){var i=t.querySelectorAll('[data-role="crm-binding-link"]');if(i&&i.length>0){return false}}}return true},updateRowMenuSeenBtn:function(e){var t=BX.findParent(e.bindElement.parentElement,{className:"main-grid-row"});if(t&&t.dataset&&t.dataset.id){var i=this.getGridInstance().getRows().getById(t.dataset.id);if(i){i.getActionsMenu()}var n=BX.findParent(e.getPopupContainer().querySelector('[data-role^="not-read"]'),{className:"menu-popup-item"});var s=BX.findParent(e.getPopupContainer().querySelector('[data-role^="read"]'),{className:"menu-popup-item"});var a=this.isSelectedRowsHaveClass("mail-msg-list-cell-unseen",t.dataset.id)?"markAsSeen":"markAsUnseen";if(a==="markAsSeen"){this.showElement(s,true);this.hideElement(n,true)}else{this.showElement(n,true);this.hideElement(s,true)}}},onMessagesRead:function(e,t){this.changeMessageRead(e,t);this.updateGridByUnseenFilter()},updateGridByUnseenFilter:function(){var e=this.getFilterInstance();if(e.getFilterFieldsValues()&&e.getFilterFieldsValues()["IS_SEEN"]!==""){this.reloadGrid({})}},updateGridByUnbindFilter:function(){var e=this.getFilterInstance();if(e.getFilterFieldsValues()&&e.getFilterFieldsValues()["BIND"]!==""){this.reloadGrid({})}},onPopupMenuFirstShow:function(e){BX.bind(e.contentContainer,"click",function(){e.close()})},onSettingsToggleClick:function(){var e=BX.PopupMenu.create("mail-msg-list-settings-menu",this.settingsToggle,this.settingsMenu,{events:{onPopupFirstShow:this.onPopupMenuFirstShow}});e.popupWindow.isShown()?e.close():e.show()},onMailboxMenuClick:function(){var e=BX.PopupMenu.create("mail-msg-list-mailbox-menu",this.mailboxMenuToggle,this.mailboxMenu,{events:{onPopupFirstShow:this.onPopupMenuFirstShow}});e.popupWindow.isShown()?e.close():e.show()},updateUnreadCounters:function(e){this.updateCounter(this.UNREAD_COUNTER_TYPE,e);this.updateMailboxUnseenCounter(e);this.updateTotalUnseenCounter(e);this.updateLeftMenuCounter()},updateLeftMenuCounter:function(){var e=this.getTotalUnseen();if(typeof top.B24==="object"&&typeof top.B24.updateCounters==="function"&&e>0){top.B24.updateCounters({mail_unseen:e})}if(typeof top.BXIM==="object"&&typeof top.BXIM.notify==="object"){if(typeof top.BXIM.notify.counters==="object"){top.BXIM.notify.counters.mail_unseen=e}if(typeof top.BXIM.notify.updateNotifyMailCount==="function"){top.BXIM.notify.updateNotifyMailCount(e)}}},updateTotalUnseenCounter:function(e){this.totalUnseen.textContent=parseInt(this.totalUnseen.textContent)+e;if(this.totalUnseen.textContent>0){this.showElement(this.totalUnseen)}else{this.hideElement(this.totalUnseen)}},updateMailboxUnseenCounter:function(e){var t=document.querySelector('[data-role="mailbox-current-title"]');if(t&&t.dataset&&t.dataset.mailboxId){var i=this.mailboxesUnseen[t.dataset.mailboxId];this.mailboxesUnseen[t.dataset.mailboxId]=parseInt(i)+parseInt(e);for(var n=0;n<this.mailboxMenu.length;n++){if(this.mailboxMenu[n]&&this.mailboxMenu[n].text&&this.mailboxMenu[n].dataset&&this.mailboxMenu[n].dataset.mailboxId==t.dataset.mailboxId){this.mailboxMenu[n].text=this.mailboxMenu[n].text.replace(/[0-9]+<\/span>/g,this.mailboxesUnseen[t.dataset.mailboxId].toString()+"</span>");if(this.mailboxesUnseen[t.dataset.mailboxId]>0){this.mailboxMenu[n].text=this.mailboxMenu[n].text.replace(/main-ui-hide/g,"js-unseen-mailbox")}else{this.mailboxMenu[n].text=this.mailboxMenu[n].text.replace(/js-unseen-mailbox/g,this.hideClassName)}break}}}},getTotalUnseen:function(){var e=this.totalUnseen;if(e){return e.textContent}return 0},updateCounter:function(e,t){var i=null,n;if(e===this.UNREAD_COUNTER_TYPE){i='[data-role="unread-counter-number"]';n=this.unreadCounterSelector}var s=document.querySelector(i);if(s){var a=s.textContent;var r=parseInt(a)+parseInt(t);if(r>0){s.textContent=r.toString();this.showElement(document.querySelector(n))}else{s.textContent="0";this.hideElement(document.querySelector(n))}this.updateCountersBlock()}},updateCountersBlock:function(){var e=document.querySelector(this.unreadCounterSelector);if(this.isVisible(e)){this.hideElement(document.querySelector(this.emptyCountersTitleSelector))}else{this.showElement(document.querySelector(this.emptyCountersTitleSelector))}},changeMessageRead:function(e,t){if(t.action==="markAsSeen"){for(var i=0;i<e.length;i++){var n=this.getGridInstance().getRows().getById(e[i]);if(n&&n.node){var s=n.node.getElementsByClassName("mail-msg-list-cell-unseen");for(var a=s.length-1;a>=0;a--){s[a].classList.remove("mail-msg-list-cell-unseen")}}}}else if(t.action==="markAsUnseen"){for(var i=0;i<e.length;i++){var n=this.getGridInstance().getRows().getById(e[i]);if(n&&n.node){n.node.cells[2].classList.add("mail-msg-list-cell-unseen");n.node.cells[3].classList.add("mail-msg-list-cell-unseen")}}}},handleGridSelectItem:function(){this.updateSeenBtn();this.updateCrmBtn();this.updateSpamBtn();var e=document.createEvent("Event");e.initEvent("resize",true,true);window.dispatchEvent(e)},disActivateBtn:function(e){this.activateBtn(e,false)},activateBtn:function(e,t){var i=document.querySelectorAll('[data-role^="'+e+'"]');Array.prototype.slice.call(i,0).forEach(function(e){var i=BX.findParent(e,{className:"ui-action-panel-item"});i=i?i:BX.findParent(e,{className:"main-grid-row"});t===undefined||t===true?this.showElement(i):this.hideElement(i)}.bind(this));var n=document.querySelectorAll('[data-role^="not-'+e+'"]');Array.prototype.slice.call(n,0).forEach(function(e){var i=BX.findParent(e,{className:"ui-action-panel-item"});i=i?i:BX.findParent(e,{className:"main-grid-row"});t===undefined||t===true?this.hideElement(i):this.showElement(i)}.bind(this))},updateCrmBtn:function(){var e=this.getGridInstance().getRows().getSelectedIds();if(e.length!==1){this.activateBtn(this.crmActionBtnRole);return}var t=this.getGridInstance().getRows().getById(e[0]);if(!(t&&t.node)){return}var i=this.isAddToCrmActionAvailable(t.node);if(i){this.activateBtn(this.crmActionBtnRole)}else{this.disActivateBtn(this.crmActionBtnRole)}},updateSpamBtn:function(){if(this.isCurrentFolderSpam){this.disActivateBtn(this.spamActionBtnRole)}else{this.activateBtn(this.spamActionBtnRole)}},updateSeenBtn:function(){var e=this.isSelectedRowsHaveClass("mail-msg-list-cell-unseen")?"markAsSeen":"markAsUnseen";if(e==="markAsSeen"){this.activateBtn(this.readActionBtnRole)}else{this.disActivateBtn(this.readActionBtnRole)}},setDefaultBtnTitles:function(){this.activateBtn(this.readActionBtnRole);this.activateBtn(this.crmActionBtnRole);this.updateSpamBtn();var e=document.createEvent("Event");e.initEvent("resize",true,true);window.dispatchEvent(e)},getRowMenu:function(){var e=this.getGridInstance().getRows().getSelectedIds();id=e.length?e[0]:null;var t=id?this.getGridInstance().getRows().getById(id):null;if(t){return t.getActionsMenu()}return null},onUnreadCounterClick:function(){var e=this.getFilterInstance();var t=e.getApi();t.setFields({DIR:e.getFilterFieldsValues()["DIR"],IS_SEEN:"N"});t.apply()},getFilterInstance:function(){return BX.Main.filterManager.getById(this.gridId)},onApplyFilter:function(e,t,i,n,s){if(e!==this.gridId){return}this.setCurrentFolderFlags(i);this.setDefaultBtnTitles()},setCurrentFolderFlags:function(e){var t=e.getPreset().getCurrentPresetId();this.isCurrentFolderTrash=this.trashDir!==""&&(t==="trash"||e.getFilterFieldsValues()&&e.getFilterFieldsValues()["DIR"]===this.trashDir);this.isCurrentFolderSpam=this.spamDir!==""&&(t==="spam"||e.getFilterFieldsValues()&&e.getFilterFieldsValues()["DIR"]===this.spamDir);this.isCurrentFolderOutcome=this.outcomeDir!==""&&(t==="outcome"||e.getFilterFieldsValues()&&e.getFilterFieldsValues()["DIR"]===this.outcomeDir)},isVisible:function(e){return e&&!e.classList.contains(this.hideClassName)}}})();
  //# sourceMappingURL=user-interface-manager.map.js