function showLoadingSpinner() { $(".lds-spinner").show(); $(".container-fluid").hide(); } function hideLoadingSpinner() { $(".lds-spinner").hide(); $(".container-fluid").show(); } function calculateSumAndValidate() { var sum = 0; $('td[data-attribute="qfza_ownershipshare"]').each(function () { var value = parseFloat($(this).text().trim()) || 0; sum += value; }); var newRow = '' + 'Total' + '' + sum + "%" + "" + ""; $("#subgrid_Shareholding tbody .total-row").remove(); $("#subgrid_Shareholding tbody").append(newRow); } function getFormattedDate() { var currentDate = new Date(); var day = currentDate.getDate(); var month = currentDate.getMonth() + 1; var year = currentDate.getFullYear(); day = day < 10 ? "0" + day : day; month = month < 10 ? "0" + month : month; var formattedDate = day + "/" + month + "/" + year; return formattedDate; } function parseDateString(dateString) { var parts = dateString.split("/"); var day = parseInt(parts[0], 10); var month = parseInt(parts[1], 10) - 1; var year = parseInt(parts[2], 10); // var thresholdYear = 50; // Example threshold, considering years >= 50 as 1900s, and < 50 as 2000s // var century = year >= thresholdYear ? 1900 : 2000; // year += century; return new Date(year, month, day); } function setErrorForFields(input, currentState, currentURL) { let result = currentState; if (!$(input).val()) { if ($(input).next(".error-message").length == 0) if (currentURL.indexOf("ar-AE") != -1) { $(input).after( 'يرجى إكمال هذا الحقل المطلوب' ); } else { $(input).after( 'Please complete this required field' ); } $(input).addClass("error"); result = false; $(input).focus(); } else { $(input).removeClass("error"); $(input).next(".error-message").remove(); } return result; } function setErrorForSpecialFields(input, currentState, currentURL) { let result = currentState; if (!$(input).val()) { if ($(input).parent().next(".error-message").length == 0) if (currentURL.indexOf("ar-AE") != -1) { $(input) .parent() .after( 'يرجى إكمال هذا الحقل المطلوب' ); } else { $(input) .parent() .after( 'Please complete this required field' ); } $(input).css("outline", "1px solid #EEB6B6"); result = false; $(input).focus(); } else { $(input).css("outline", "none"); $(input).parent().next(".error-message").remove(); } return result; } function getData( dataTableId, url, columns, rowsPerPage, filterEnabled, lengthChangeEnabled, bInfoEnabled ) { var myComponent = document.querySelector( `data-table[tableId="${dataTableId}"]` ); var myElement = myComponent.shadowRoot.querySelector(`#${dataTableId}`); $(myElement).DataTable({ ajax: function (data, callback, settings) { webapi.safeAjax({ type: "GET", contentType: "application/json", url: url, success: function (response) { let responseData = response["value"]; callback({ draw: data.draw, recordsTotal: response.length, data: responseData, }); }, }); }, columns: columns, filter: filterEnabled, lengthChange: lengthChangeEnabled, pageLength: rowsPerPage, bInfo: bInfoEnabled, }); } function validateDateFormat(date, currentState) { let result = currentState; let dateRegex = /^(0[1-9]|[12][0-9]|3[01])\/(0[1-9]|1[012])\/(19|20)\d\d$/; if ($(date).val()) { if (!dateRegex.test($(date).val())) { if ($(date).parent().next(".error-message").length == 0) { $(date) .parent() .after( 'The date format is not valid' ); $(date).css("outline", "1px solid #EEB6B6"); } result = false; $(date).focus(); } // else if (dateRegex.test($(date).val())) { // $(date).css("outline", "none"); // $(date).parent().next(".error-message").remove(); // } } return result; } $(document).ready(function () { hideLoadingSpinner(); const handlePushMessages = (event) => { console.log(`Message received: ${JSON.stringify(event.data)}`); // Create a new notification card element var notificationCard = document.createElement("div"); notificationCard.className = "notification-card mb-2 d-flex align-items-center me-4"; // Create the notification card content element var notificationCardContent = document.createElement("div"); notificationCardContent.className = "notification-card-content ms-3 mt-3 text-start"; // Set the content of the notification card content element notificationCardContent.innerHTML = `

${event.data.subject}

${event.data.message}

`; // notificationCardContent.innerHTML = `

${event.data.subject}

${event.data.text}

`; // Append the notification card content element to the notification card element notificationCard.appendChild(notificationCardContent); // Create the close icon element var closeIcon = document.createElement("img"); closeIcon.src = "~/assets/close-icon.svg"; closeIcon.alt = "close-icon"; // Append the close icon element to the notification card element notificationCard.appendChild(closeIcon); // Append the notification card element to the notification container var notificationContainer = document.querySelector( ".notification-container" ); notificationContainer.appendChild(notificationCard); }; navigator.serviceWorker.addEventListener("message", handlePushMessages); (function (webapi, $) { function safeAjax(ajaxOptions) { var deferredAjax = $.Deferred(); shell .getTokenDeferred() .done(function (token) { // Add headers for ajax if (!ajaxOptions.headers) { $.extend(ajaxOptions, { headers: { __RequestVerificationToken: token, }, }); } else { ajaxOptions.headers["__RequestVerificationToken"] = token; } $.ajax(ajaxOptions) .done(function (data, textStatus, jqXHR) { validateLoginSession( data, textStatus, jqXHR, deferredAjax.resolve ); }) .fail(deferredAjax.reject); //ajax }) .fail(function () { deferredAjax.rejectWith(this, arguments); // On token failure pass the token ajax and args }); return deferredAjax.promise(); } webapi.safeAjax = safeAjax; localStorage.setItem("webapitext", safeAjax); localStorage.setItem("webapi", JSON.stringify(safeAjax)); })((window.webapi = window.webapi || {}), jQuery); if (Notification.permission !== "granted") { Notification.requestPermission().then(function (permission) { if (permission === "granted") { console.log("Notification permission granted!"); } else { console.warn("Notification permission denied."); } }); } if (!location.pathname.contains("services-home")) { $(".lds-spinner").hide(); $(".container-fluid").show(); } function urlBase64ToUint8Array(base64String) { var padding = "=".repeat((4 - (base64String.length % 4)) % 4); var base64 = (base64String + padding) .replace(/\-/g, "+") .replace(/_/g, "/"); var rawData = window.atob(base64); var outputArray = new Uint8Array(rawData.length); for (var i = 0; i < rawData.length; ++i) { outputArray[i] = rawData.charCodeAt(i); } return outputArray; } window.generatePaymentLink = function () { showLoadingSpinner(); let btn1 = document.createElement("a"); var link = ""; var url = decodeURI(window.location.href); var urlafter = url.split("?"); var params = urlafter[1].split("&"); if (params[0]) { var GUID = params[0].split("="); } btn1.innerHTML = "PAY"; const date = new Date(); var record = {}; record.qfza_encryptedurlgenerationtime = date; // Text webapi.safeAjax({ type: "PATCH", contentType: "application/json", url: "/_api/hexa_requests(" + GUID[1] + ")", data: JSON.stringify(record), success: function (data, textStatus, xhr) { console.log("Record updated"); webapi.safeAjax({ type: "GET", url: "/_api/hexa_requests(" + GUID[1] + ")?$select=qfza_encryptedurl", contentType: "application/json", success: function (data, textStatus, xhr) { var result = data; //console.log(result); // Columns var es_requestid = result["hexa_requestid"]; // Guid var qfza_encryptedurl = result["qfza_encryptedurl"]; // Text // location.href = qfza_encryptedurl; link = qfza_encryptedurl; assignLink(btn1, link); }, error: function (xhr, textStatus, errorThrown) { console.error(errorThrown); }, }); }, error: function (xhr, textStatus, errorThrown) { console.error(errorThrown); }, }); btn1.classList.add("create-case-btn"); btn1.style.letterSpacing = "3px"; btn1.style.border = "none"; btn1.style.textAlign = "center"; btn1.style.width = "10%"; }; function assignLink(btn1, link) { if ( $("#hexa_externalstatus").val() === "253d386e-437e-ee11-8179-0022489fd7a3" ) $(".form-custom-actions").append(btn1); btn1.href = link; hideLoadingSpinner(); } });