let PORTAL_ID = '79c2d59f-df0e-ee11-8f6d-0022482dbb52', $ipModal = null, ipRecord = null, ipRecordName = null, ipEntityName = null, ipEntityId = null, tableId = null, ipReload = false, // Set in FDCE Page Copy on ready ipSubmitted = false, ipAdmin = false, ipScriptItems = []; const MODAL_TYPE = { Small: 0, Medium: 1, Large: 2 } const MODAL_TITLE = { Add: 'Add', Edit: 'Edit', Delete: 'Delete' }; //Web API ajax wrapper (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, "Prefer": "odata.include-annotations=*" } }); } 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; })(window.webapi = window.webapi || {}, jQuery) // Notification component var notificationMsg = (function () { var $processingMsgEl = $('#processingMsg'), _msg = 'Processing...', _stack = 0, _endTimeout; return { show: function (msg) { $processingMsgEl.text(msg || _msg); if (_stack === 0) { clearTimeout(_endTimeout); $processingMsgEl.show(); } _stack++; }, hide: function () { _stack--; if (_stack <= 0) { _stack = 0; clearTimeout(_endTimeout); _endTimeout = setTimeout(function () { $processingMsgEl.hide(); }, 500); } } } })(); //Applicaton ajax wrapper function appAjax(processingMsg, ajaxOptions) { notificationMsg.show(processingMsg); return webapi.safeAjax(ajaxOptions) .fail(function (response) { if (response.responseJSON) { alert("Error: " + response.responseJSON.error.message) } else { alert("Error: Web API is not available... ") } }).always(notificationMsg.hide); } function redirectAccess() { let url_string = window.location.href, url = new URL(url_string), id = url.searchParams.get("id"); if (id == null || id == "") { if (url_string.split('/').length > 4) { // Redirect to blank page window.location.replace(window.location.origin); } else { $('#ip-message-container').show(); $('#ip-main-container').hide(); } } } function setNavigation() { let url_string = window.location.href, nav = url_string.split('/'); console.log('here'); if (nav.length > 3) { console.log(nav); let selector = '#ip-nav-container .ip-nav-item[data-nav-id="' + nav[4] + '"]'; $(selector).addClass('active'); } } function navigate(path, id, admin) { let newPath = `/Page/${path}/?id=${id}`; if (admin) newPath += `&admin=${admin}`; window.location = newPath; } function navClicked(path, id, admin) { let url_string = window.location.href if (url_string.indexOf("Manufacturer-Information") > -1) { updateManufacturerRecord().done(function() { navigate(path, id, admin); }); } else if (url_string.indexOf("Prescribing-Information") > -1) { updatePIRecord().done(function() { navigate(path, id, admin); }); } else navigate(path, id, admin); } function openDefaultTab() { $('#ip-tab-group .ip-tab-item:first-child').click(); } function openTab(tabName) { // Hide all tabs $('.ip-tab-content').hide(); if (tabName == null) { openDefaultTab(); } else { // Show current tab $(`#${tabName}`).show(); // Remove active from all tab buttons $('.ip-tab-item').removeClass('active'); // Set current tab button as actie $(`#ip-tab-item-${tabName}`).addClass('active'); // Set open tab const url = new URL(window.location.href); url.searchParams.set('tab', tabName); window.history.replaceState(null, null, url); } } function openTabWithParams() { const url = new URL(window.location.href), tabName = url.searchParams.get('tab'); openTab(tabName); } function getModal(modalType, modalTitle) { let $modal = $('#formModal'), modalSize = ''; // Set modal size switch (modalType) { case MODAL_TYPE.Small: modalSize = 'modal-sm' break; case MODAL_TYPE.Large: modalSize = 'modal-lg' break; default: break; } $modal.find('.modal-dialog').addClass(modalSize); // Set modal title $modal.find('.modal-title').text(modalTitle); return $modal.clone(); } function resetModal(modal) { $('body').append(modal.clone()); } function loadScript(parent, items) { items.forEach(function(item) { if (item.element && item.script) { let elmt = $(parent).find(item.element); if (elmt.length > 0) elmt.append($('