YetiForceCompany/YetiForceCRM

View on GitHub
public_html/layouts/basic/modules/OSSMail/resources/checkmails.min.js

Summary

Maintainability
A
0 mins
Test Coverage
'use strict';

/* {[The file is published on the basis of YetiForce Public License 6.5 that can be found in the following directory: licenses/LicenseEN.txt or yetiforce.com]} */"use strict";jQuery(function(){$(".js-header__btn--mail").data("numberunreademails")!=null&&(window.stopScanMails=!1,"Popup"!=getUrlVars().view&&startCheckMails()),0<$(".js-header__btn--mail select").length&&registerUserList();});function registerUserList(){var selectUsers=$(".js-header__btn--mail select");selectUsers.data("select2")?selectUsers.select2("destroy"):selectUsers.on("change",handleChangeUserEvent),App.Fields.Picklist.showSelect2ElementView(selectUsers,{templateResult:function templateResult(data){var main=document.createElement("span");if(data.id){var element=$(data.element),mail=document.createElement("span");if(mail.innerText=data.text,main.appendChild(mail),element.data("nomail")){var badge=document.createElement("span");badge.className="badge badge-danger ml-1",badge.innerText=element.data("nomail"),main.appendChild(badge);}}else main.innerText=data.text;return main},templateSelection:function templateSelection(data){var element=$(data.element),main=document.createElement("span"),mail=document.createElement("span");if(mail.innerText=data.text,main.appendChild(mail),element.data("nomail")){var badge=document.createElement("span");badge.className="badge badge-danger ml-1",badge.innerText=element.data("nomail"),main.appendChild(badge);}return main},closeOnSelect:!0});var select2Instance=selectUsers.data("select2");select2Instance.$dropdown.on("mouseup","li",function(e){"true"==jQuery(e.currentTarget).attr("aria-selected")&&selectUsers.trigger("change");}),select2Instance.$container.find(".select2-selection__rendered").on("mousedown",function(e){e.stopPropagation(),selectUsers.trigger("change");}),$(".js-mail-list").on("click",".js-mail-link",handleChangeUserEvent);}function handleChangeUserEvent(){AppConnector.request({module:"OSSMail",action:"SetUser",user:$(this).val()}).done(function(){window.location.href="OSSMail"==app.getModuleName()?window.location.href:"index.php?module=OSSMail&view=Index";});}function startCheckMails(){var users=[],timeCheckingMails=$(".js-header__btn--mail").data("interval");if($(".js-header__btn--mail .noMails").each(function(){users.push($(this).data("id"));}),0<users.length){checkMails(users,!0);var refreshIntervalId=setInterval(function(){!1==window.stopScanMails?checkMails(users):clearInterval(refreshIntervalId);},1e3*timeCheckingMails);}}function checkMails(users){var initial=!!(1<arguments.length&&arguments[1]!==void 0)&&arguments[1],reloadSelect=!1;AppConnector.request({module:"OSSMail",action:"CheckMails",users:users}).done(function(response){if(response.success&&!0!=response.success.error&&!0!=response.result.error){var result=response.result;$(".js-header__btn--mail .noMails").each(function(){var element=jQuery(this),id=element.data("id");if(jQuery.inArray(id,result)){var num=result[id];if(element.is("option"))element.data("nomail",num),reloadSelect=!0;else {var prevVal=element.data("nomail");element.data("nomail",num);var text="";0<num&&(text=" <span class=\"badge badge-danger mr-1\">"+num+"</span>"),element.html(text),!1===initial&&("SPAN"===this.tagName||this.selected)&&(prevVal<num&&0<=prevVal||!prevVal&&0<num)&&(element.parent().effect("pulsate",1500),app.playSound("MAILS"));}}}),reloadSelect&&registerUserList();}else window.stopScanMails=!0;}).fail(function(){window.stopScanMails=!0;});}function getUrlVars(){var vars={};return window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi,function(m,key,value){vars[key]=value;}),vars}
//# sourceMappingURL=checkmails.min.js.map