/*Data loading start here*/ import {getCookie, isAuthenticated} from "./cookiehelper.js"; import {getData, getDataObj} from "./base.js"; import {_serverUrl} from "./setting.js"; export var connection; export function dateTimeFormat(dateTime) { var date = moment.utc(dateTime).local(); var difmonths = moment().diff(date, "months"); if (difmonths == 0) { return moment(dateTime).fromNow(); } return date.format("DD MMM, YYYY HH:mm"); } function createLoad(data) { let html = ""; if (data.length != 0) { for (var i = 0; i < data.length; i++) { html += `
  • ${data[i].AppTitle}
  • `; } } else { html += `
  • Apps are Not Installed
  • `; } $("#crte-btn-lst").html(html); $(".create-form-btn").on("click", function () { const date = new Date(); let number = date.getTime(); let serverUrl = _serverUrl(); let appName = $(this).text(); let formId = $(this).attr("data-formid"); let installedAppId = $(this).attr("data-installedappid"); let appConfigurationId = $(this).attr("data-appconfigurationid"); let pk_id = 0; const cookie = getCookie("_idty"); let fomrhtml = ""; let width = iFrmeWdth(); if (cookie) { const {unibaseId, tenantId, userId} = JSON.parse(cookie); fomrhtml = `
    • ${appName}
    `; } $("#list-page").parent("body").append(fomrhtml); window.window.postMessage("ld-frm-ifrme", "*"); hdrCrtnClckEvnt(number); }); } function hdrCrtnClckEvnt(number) { $(`.frm-ifre-${number} .minimize`).on("click", function () { let id = $(this).attr("data-unid"); let isPopUpState = $(this).attr("data-ispopup"); let height = $(`.frm-ifre-${id}`).find(".frm-hdr").height(); $(".list-page").css({filter: "unset", opacity: 1}); $(`.frm-ifre-${id} .frm-bdy`).toggleClass("d-none"); if (isPopUpState == "true") { // popup large $(this).attr("data-ispopup", "false"); $(this).parents('.frm-hdr').removeClass('d-none').attr('data-frm_hdr', 'false'); $(`.frm-ifre-${id} .maximum`).addClass("d-none"); $(`.frm-ifre-${id} .minimize`).attr("data-ispopup", "false"); $(`.frm-ifre-${id}`).parent().removeClass("wrap-iframe"); $(`.frm-ifre-${id}`).attr("data-ispop_up", "false"); $(`.frm-ifre-${id}`).css({ width: "20%", height: height, bottom: "0px", }); } else { // popup small $(this).attr("data-ispopup", "true"); $(this).parents('.frm-hdr').addClass('d-none').attr('data-frm_hdr', 'true'); $(`.frm-ifre-${id} .maximum`).removeClass("d-none"); $(`.frm-ifre-${id} .minimize`).attr("data-ispopup", "true"); $(`.frm-ifre-${id}`).attr("data-ispop_up", "true"); $(`.frm-ifre-${id}`).css({ width: "", height: "", bottom: "", }); if($(this).parents('.frm-hdr').attr("data-saveform") == 'true'){ $(this).parents('.frm-hdr').removeClass('d-none') } } resetwidth(); }); $(`.frm-ifre-${number} .maximum`).on("click", function () { let id = $(this).attr("data-unid"); $(this).addClass("d-none"); $(this).siblings(".compress").removeClass("d-none"); $(`.frm-ifre-${id}`).find(".ld-frm-src").attr("data-ispopup", "true"); $(`.frm-ifre-${id}`).parent().addClass("wrap-iframe"); $(`.frm-ifre-${id}`).css({width: "75%", position: "unset"}); $(`.frm-ifre-${id} .ld-frm-src`).css({width: "100%"}); $(`.frm-ifre-${id} .frm-bdy`).removeClass("d-none"); $("#list-page").css({filter: "blur(2px)", opacity: "0.5"}); $(`.frm-ifre-${id}`).find(".minimize").toggleClass("d-none"); }); $(`.frm-ifre-${number} .compress`).on("click", function () { let id = $(this).attr("data-unid"); $(this).addClass("d-none"); $(this).siblings(".maximum").removeClass("d-none"); $(`.frm-ifre-${id}`).parent().removeClass("wrap-iframe"); $(`.frm-ifre-${id}`).css({width: "", position: ""}); $(`.frm-ifre-${id} .ld-frm-src`).css({width: ""}); $("#list-page").css({filter: "", opacity: ""}); $(`.frm-ifre-${id}`).find(".minimize").toggleClass("d-none"); }); $(`.frm-ifre-${number} .close`).on("click", function () { let id = $(this).attr("data-unid"); $("#list-page").css({filter: "unset", opacity: "1"}); $(`.frm-ifre-${id}`).parent().remove(); resetwidth(); }); } function loadData(ApiPath, isSentBy) { $(".bdy-ul").empty().removeClass("d-none"); $(".hdr-ul").removeClass("d-none"); getData(ApiPath).then(function (result) { let response = JSON.parse(result.result), html = ""; const cookie = getCookie("_idty"); if (response.length != 0) { response.forEach(function (Item, index) { let isSent = false; if (Item.FromUserName == JSON.parse(cookie).name) { isSent = true; } if (Item.FromUserName == null) { Item.FromUserName = 'Please check it Notification Team'; } //if(window.innerWidth >1024){ // Desktop Width html += `
  • `; html += `
    `; if (Item.ReminderTypeId == 1) { html += ``; } else { html += ``; } html += `
    `; // check-box html += `
    `; html += `
    ${Item.FromUserName}
    `; html += `
    ${Item.Subject}
    -
    `; // Subject html += `
    ${Item.Message}
    `; // Message html += `
    `; html += `
    ${dateTimeFormat( Item.ReminderDate )}
    `; html += `
    `; html += "
  • "; /* }else{ // Mobile Width card view html += `
  • ` html += `
    S
    ${Item.FromUserName} ${dateTimeFormat( Item.ReminderDate )}
    ${Item.Subject}
    ${Item.Message}`; if (Item.ReminderTypeId == 1) { html += ``; } else { html += ``; } html += `
    ` html +=`
  • ` }*/ }); $(".ctr-lst-pge .bdy-ul").html(html); if (isSentBy) { $(".pdng.lst-Notifi").addClass("d-none"); $(".pdng.lst-Notifi[data-issentby='true']").removeClass("d-none"); } detailClick(); //stagesLoad(); } }); getData("apis/v4/unibase/reminders/platform/getunreadreminderscount").then( function (response) { let result = JSON.parse(response.result); let count = Number(result.NotificationCount) + Number(result.TasksCount); $('[data-buttontype="inbox"] .length.rounded-pill').remove(); $('[data-buttontype="inbox"]').append( `${count}` ); $('[data-notification="count"]').text(count); if (count > 40) { $('[data-paggtn="true"]').text(`1-40`); } else { $(".li-pgn").empty(); } } ); if(window.innerWidth() < 1024){ $('.ctr-lst-pge').on('click', function(){ $('.mnNvIcn').click() }) } } function iFrmeWdth() { let width = 0, erwdth = 15; $(".frm-ifre").each(function (i, e) { if ($(this).length == 0) { erwdth = 0; } if (window.innerWidth > width) { width = width + $(this).width() + erwdth; } }); return width; } function resetwidth() { let width = 0, erwdth = 15; $(".frm-ifre").each(function (i, e) { if (i == 0) { $(this).css("right", width + "px"); } if (i != 0) { $(this).css("right", width + "px"); } if (window.innerWidth > width) { width = width + $(this).width() + erwdth; } }); } export function detailClick() { // Details Popup Abihram popup page $(".wi-sbjt-msge").on("click", function (e) { e.stopPropagation(); detailsPage(this, true, "Details-page"); }); // Details Page Loading $(".detailBtn[data-urltype='Details']").click(function (e) { e.stopPropagation(); detailsPage(this, false, "Details-page"); }); //Form Page Loading $(".formBtn[data-urltype='Form']").on("click", function (e) { e.stopPropagation(); detailsPage(this, true, "Form-page"); }); //List Page Loading $("[data-urltype='List']").on("click", function (e) { e.stopPropagation(); detailsPage(this, true, "List-page"); }); // get stages } export function detailsPage(e, ifrmPopup, isPage) { let serverUrl = _serverUrl(); $(".bdy-ul").addClass("d-none"); $(".hdr-ul").addClass("d-none"); let installedAppId = $(e) .parents(".pdng.lst-Notifi") .attr("data-instlledappid"); let recordId = $(e).parents(".pdng.lst-Notifi").attr("data-refid"); let reminderid = $(e).parents(".pdng.lst-Notifi").attr("data-reminderid"); let remindertype = $(e) .parents(".pdng.lst-Notifi") .attr("data-remindertypeid"); // Unibase.Themes.Compact.Components.Notification.Instance().loadReminderDetails(105013010001972,105010260000090,'Details','null',6,0,null) const cookie = getCookie("_idty"); if (cookie) { const {unibaseId, tenantId, userId} = JSON.parse(cookie); if (isPage == "Details-page") { $("#detailIframe").html( `` ); } else if (isPage == "Form-page") { getData( `apis/v4/unibase/platform/apps/listappconfigurations/installedappid/${installedAppId}` ).then(function (result) { let _data = JSON.parse(result.result); let data = _data.filter((x) => x.SettingUrlType == 1); $("#detailIframe").html( `` ); }); } else if (isPage == "List-page") { $("#detailIframe").html( `` ); } } } export function signaRInit() { var huburl = _serverUrl() + "notificationhub"; connection = new window["signalR"].HubConnectionBuilder() .withUrl(huburl) .build(); register(); } export async function register() { connection.on("sendnotification", (obj) => { $(".ctr-lst-pge .bdy-ul").empty(); loadData( "apis/v4/unibase/reminders/platform/getuserreminders/PageSize/0", false ); }); const cookie = getCookie("_idty"); const {unibaseId, tenantId, userId, sessionId, name} = JSON.parse(cookie); let packet = { UserId: Number(userId), UserName: name, UnibaseId: unibaseId, TenantId: Number(tenantId), SessionId: sessionId, }; try { const stringConnection = await connection.start(); await connection.invoke("Connect", packet); } catch (error) { console.log(error); } } export function resetClckEvnt() { $(".ChtAppIfrme").remove(); $(".lft-nav-bar .lft-nav-bar-2").removeClass("d-none"); $(".ctr-lst-pge, .rtr-nav-bar").removeClass("d-none"); $(".lft-nav-bar").css("width", ""); } export function initListIndex() { let userInfo = JSON.parse(getCookie("_idty")); let sessionId = userInfo.sessionId; signaRInit(); let usrinfoHTML = `
  • ${userInfo.name}
  • Help
  • Logoff
  • `; $(".icn-circle").text(userInfo?.name?.charAt(0)?.toUpperCase()); $(".uindtls").html(usrinfoHTML); $('[data-btn="logoff"]').on("click", function () { document.cookie = "_idty=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"; window.location = "../login"; }); // List Page loading /*Data loading start here*/ $(".nav-lft-item").on("click", function () { $(".nav-lft-item").removeClass("active"); $(this).addClass("active"); if ($(this).attr("data-application") != "Chat Application") { resetClckEvnt(); } }); $(".nav-lft-item[data-application='Chat Application']").on( "click", function () { const serverUrl = _serverUrl(); const cookie = getCookie("_idty"); const {unibaseId, tenantId, userId} = JSON.parse(cookie); $(".lft-nav-bar .lft-nav-bar-2").addClass("d-none"); $(".ctr-lst-pge, .rtr-nav-bar").addClass("d-none"); $(".lft-nav-bar").css("width", "var(--rtrWidth)"); $(".btm-bar .ChtAppIfrme").remove(); $(".btm-bar").append(`
    `); } ); $(".mnNvIcn").click(function () { $(".lft-nav-bar").toggleClass("lft-nav-bar-Wrap"); $(".ctr-lst-pge").toggleClass("lft-nav-bar-Wrap"); if ($(".apps-loading:visible").length != 0) { $(".ctr-lst-pge").css("width", ""); $(".ctr-lst-pge").toggleClass("apps-loaded"); $(".ctr-lst-pge").toggleClass("apps-loaded-tr"); } if(window.innerWidth < 1025){ $(".ctr-lst-pge").toggleClass('d-block'); $(".lft-nav-bar").toggleClass("lft-nav-bar-Wrap d-flex w-100").css('background-color','rgb(0 0 0 / 50%)'); } }); $(".mre-drp a.sub-nav-item.more").on("click", function () { $(".sub-nav-item").removeClass("active"); if ($(this)[0].className.includes("active")) { $(this).find("i").css("transform", "rotate(0deg)"); $(this).removeClass("active"); } else { $(this).find("i").css("transform", "rotate(180deg)"); $(this).addClass("active"); } $(this).siblings(".ul-drpdown").toggleClass("d-none"); }); $("a.sub-nav-item") .not(".more.active") .on("click", function () { $(".sub-nav-item").not(".more.active").removeClass("active"); $(this).addClass("active"); }); $('[data-buttontype="inbox"], [data-application="Mail Application"]').on( "click", function () { $("#detailIframe").empty(); loadData( "apis/v4/unibase/reminders/platform/getuserreminders/PageSize/0", false ); } ); window.addEventListener("message", function (e) { if (e.data != undefined) { if(e.data == "Edit-form"){ $('.frm-hdr').addClass('d-none') } if (e.data == "closeForm") { $("#detailIframe").empty(); $(".hdr-ul, .bdy-ul").removeClass("d-none"); $('.frm-bdy [class="close"]')[0].click(); } if (e.data == "clickToBack") { $("#detailIframe").empty(); loadData( "apis/v4/unibase/reminders/platform/getuserreminders/PageSize/0", false ); } if (e.data.includes("save-form")) { let spilt = e.data.split("/"); $(`.frm-ifre[data-formid="${spilt[1]}"] .frm-hdr`).removeClass( "d-none" ).attr('data-frm_hdr','false'); } if (e.data == "close apps") { $("body").removeClass("d-flex flex-row"); $("#detailIframe").empty(); $(".hdr-ul, .bdy-ul").removeClass("d-none"); $(".apps-loading").remove(); $("#list-page").css("width", "100%"); $(".lft-nav-bar").removeClass(".lft-nav-bar-Wrap"); $(".ctr-lst-pge").removeClass("apps-loaded"); $(".ctr-lst-pge").removeClass("apps-loaded-tr"); } if (e.data.includes("/")) { let spilt = e.data.split("/"); $( `.frm-ifre[data-formid="${spilt[1]}"] .frm-hdr .ctrl .${spilt[0]}` ).click(); if(spilt[0].includes('success')){ $(`.frm-ifre[data-formid="${spilt[1]}"] .frm-hdr`).removeClass("d-none").attr({'data-frm_hdr': 'false', 'data-saveform':'true'}); } if(!spilt[0].includes('maximum') && !spilt[0].includes('compress')){ $(`.frm-ifre[data-formid="${spilt[1]}"] .frm-hdr`).removeClass("d-none").attr({'data-frm_hdr': 'false'}); } } if (e.data == "closeForm_detailIframe") { $("#detailIframe").empty(); $(".hdr-ul, .bdy-ul").removeClass("d-none"); } } }); $('[class="refrsh"]').on("click", function () { loadData( "apis/v4/unibase/reminders/platform/getuserreminders/PageSize/0", false ); }); getData("apis/v4/unibase/platform/apps/myapps").then(function (response) { if(response.message.includes("User Authentication Failed")){ window.location = "../login"; }else{ let result = JSON.parse(response.result); let html = "
  • "; $("#apps-list").html(html); $(".appsBind").on("click", function () { let width = "330px"; if(window.innerWidth> 1024){ $("#list-page").css("width", `calc(100% - ${width})`); } if( $('.lft-nav-bar-2:visible').length !=0 ){ $(".ctr-lst-pge").addClass("apps-loaded-tr"); }else{ $(".ctr-lst-pge").addClass("apps-loaded lft-nav-bar-Wrap") } let installedAppId = $(this).attr("data-myappid"); const cookie = getCookie("_idty"); if (cookie) { let serverUrl = _serverUrl(); const {unibaseId, tenantId, userId} = JSON.parse(cookie); $("body").addClass("d-flex flex-row"); $(".apps-loading").remove(); $("#list-page").after( `
    ` ); } }); } }); $(".btn.dropdown-toggle.create").on("click", function () { let appName = []; getData("apis/v4/unibase/platform/apps/myapps").then(async function (res) { let response = await JSON.parse(res.result); jQuery.each(response, async function (index, item) { let installedAppId = Number(item.MyAppId); await getData( `apis/v4/unibase/platform/apps/listappconfigurations/installedappid/${installedAppId}` ).then(function (result) { if ( result.result != null && result.result != "" && result.result != "[]" ) { let _data = JSON.parse(result.result); let data = _data.filter((x) => x.SettingUrlType == 1); if (data.length != 0) { appName.push({ SettingUrlType: data[0].SettingUrlType, AppTitle: data[0].AppTitle, FormId: data[0].FormId, InstalledAppId: data[0].InstalledAppId, RoleSettingAppId: data[0].RoleSettingAppId, InstalledAppGuid: data[0].InstalledAppGuid, AppConfigurationId: data[0].AppConfigurationId, AppPermissionId: data[0].AppPermissionId, AppConfigType: data[0].AppConfigType, }); } } }); await appName.sort(function (a, b) { var a1 = a.AppTitle.toLowerCase().trim(), b1 = b.AppTitle.toLowerCase().trim(); if (a1 == b1) return 0; return a1 > b1 ? 1 : -1; }); await createLoad(appName); }); }); }); $('[data-buttontype="Starred"]').on("click", function () { let count = 20; if ( $('[data-buttontype="inbox"] .length').attr("data-taskscount") != undefined ) { count = $('[data-buttontype="inbox"] .length').attr("data-taskscount"); } loadData( `apis/v4/unibase/reminders/platform/getunreadreminders/ReminderType/1/PageSize/${count}`, false ); }); $('[data-buttontype="unstarred"]').on("click", function () { let count = 20; if ( $('[data-buttontype="inbox"] .length').attr("data-notificount") != undefined ) { count = $('[data-buttontype="inbox"] .length').attr("data-notificount"); } loadData( `apis/v4/unibase/reminders/platform/getunreadreminders/ReminderType/6/PageSize/${count}`, false ); }); $('[data-buttontype="all"]').on("click", function () { loadData( "apis/v4/unibase/reminders/platform/getuserreminders/PageSize/0", false ); }); $('[data-buttontype="read"]').on("click", function () { $(".pdng.lst-Notifi").addClass("d-none"); $(".pdng.lst-Notifi[data-isreaded='2']").removeClass("d-none"); }); $('[data-buttontype="unread"]').on("click", function () { $(".pdng.lst-Notifi").addClass("d-none"); $(".pdng.lst-Notifi[data-isreaded='8']").removeClass("d-none"); }); $('[data-buttontype="sent"]').on("click", function () { loadData( "apis/v4/unibase/reminders/platform/getuserreminders/PageSize/0", true ); }); try { loadData( "apis/v4/unibase/reminders/platform/getuserreminders/PageSize/0", false ); } catch (error) { console.log("LoadData Method is not loading, and getting error"); } } export function stagesLoad() { $(".stgs-li").each(function () { let html = ""; let InstalledAppId = $(this).attr("data-installedappid"); getData( `apis/v4/unibase/platform/apps/getallchangestageroles/installedappid/${InstalledAppId}` ).then(function (stg_rslt) { let data = JSON.parse(stg_rslt.result); let _stage = data.filter(function (o) { return o.IsDefault == true; }); html += ` "; $(`.stgs-li[data-installedappid='${InstalledAppId}']`).html(html); }); }); }