var Granite = Granite || {}; (function (document, $) { "use strict"; var askforlogin, askfornda, askforsla, askforroles, askforeuc, documentid, thankYouURL, askforeuc_url, thankyou_url, askforroles_url, tepHomePage, isTepPage, resourcePath; askforlogin = getCookie('askforlogin'); askfornda = getCookie('askfornda'); askforsla = getCookie('askforsla'); askforroles = getCookie('askforroles'); askforeuc = getCookie('askforeuc'); documentid = getCookie('documentid'); askforroles_url = getCookie('askforroles_url'); askforeuc_url = getCookie('askforeuc_url'); thankyou_url = getCookie('thankyou_url'); resourcePath = getCookie('resourcePath'); tepHomePage = getCookie('tepHomePage'); isTepPage = getCookie('isTepPage'); document.addEventListener("DOMContentLoaded", () => { var rootElement = document.querySelector('.hiddencontainer'); if (window.location.href.includes('/utils/login-redirect') && document.querySelector('[data-userid="yes"]') && resourcePath) { document.cookie = "resourcePath=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"; window.location.replace(resourcePath); } if (askforlogin === 'true') { rootElement.querySelector(".login-component").classList.remove("hidden"); } else if (askfornda === 'true') { rootElement.querySelector(".nda-component").classList.remove("hidden"); } else if (askforsla === 'true') { rootElement.querySelector(".sla-component").classList.remove("hidden"); } else if (askforeuc === 'true') { rootElement.querySelector(".euc-component").classList.remove("hidden"); } if (rootElement && askforlogin != 'true') { const bodyData = { "nda": toBoolean(askfornda), "sla": toBoolean(askforsla), "euc": toBoolean(askforeuc) }; const url = rootElement.querySelector('[data-update-sla-nda-url]').getAttribute('data-update-sla-nda-url'); if (toBoolean(askfornda)) { rootElement.querySelector('.nda-component .accept-btn').addEventListener('click', function () { document.cookie = "resourcePath=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"; updateUser(url, bodyData); }); } else if (toBoolean(askforsla)) { rootElement.querySelector('.sla-component .accept-btn').addEventListener('click', function () { document.cookie = "resourcePath=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"; updateUser(url, bodyData); }); } else if (toBoolean(askforeuc)) { rootElement.querySelector('.euc-component .accept-btn').addEventListener('click', function () { document.cookie = "resourcePath=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"; const euc_service_url = document.querySelector('[data-update-euc-url]')?.getAttribute('data-update-euc-url'); if(!euc_service_url) { console.error('could not find url', document.querySelector('[data-update-euc-url]')); return; } const accessLink = askforroles === 'true' ? askforroles_url : null; console.log("EUC URL is "+euc_service_url); updateUser(euc_service_url, bodyData, accessLink); }); } else if (toBoolean(askforroles)) { if (getStorage(documentid + '_getacessDone', 600)) { redirectToForm(rootElement, thankyou_url, true); } else { if(toBoolean(isTepPage) && tepHomePage !== null && tepHomePage !== undefined && tepHomePage !== ''){ window.location.href = tepHomePage; } else{ redirectToForm(rootElement, askforroles_url, true); } } } } }); function toBoolean(value) { if (value === 'true') { return true; } else if (value === 'false') { return false; } return null; } function getCookie(name) { const value = `; ${document.cookie}`; const parts = value.split(`; ${name}=`); if (name !== 'resourcePath') { document.cookie = name + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"; } if (parts.length === 2) { return parts.pop().split(';').shift(); } } function setLocalStorageValuesAndRedirect(link) { localStorage.setItem('askforeuc', askforeuc); localStorage.setItem('askforroles', askforroles); localStorage.setItem('askforroles_url', askforroles_url); localStorage.setItem('thankYouUrl', thankyou_url); localStorage.setItem('documentid', documentid); localStorage.setItem(documentid+'_resourcePath', resourcePath.replace(".html", "")); window.location.href = link; } function redirectToForm(rootElement, cookieValue, shouldRedirectImmediately = false) { console.log('redirection added for ' + cookieValue); if(shouldRedirectImmediately) { setLocalStorageValuesAndRedirect(cookieValue); } else { rootElement.querySelector('.euc-component .accept-btn').addEventListener('click', () => setLocalStorageValuesAndRedirect(cookieValue)); } } function handleEUC(rootElement) { if (getStorage(documentid + '_geteucDone', 600)) { redirectToForm(rootElement, thankyou_url); } else { redirectToForm(rootElement, askforeuc_url); } } async function getCsrfToken() { const response = await fetch('/libs/granite/csrf/token.json'); const json = await response.json(); return json.token; } async function updateUser(url, bodyData, link = null) { try { const headers = { 'CSRF-Token': await getCsrfToken() }; fetch(url, { method: 'POST', headers: headers, body: JSON.stringify(bodyData) }).then(response => response.json()) .then(responseData => { if (responseData.success) { if(!!link) { askforeuc = "false"; if (getStorage(documentid + '_getacessDone', 600) && thankYouURL) { window.location.href = thankYouURL; } else { setLocalStorageValuesAndRedirect(link); } } else { if (resourcePath.includes('/content/micron/')) { window.location.replace(resourcePath + '.html'); } else { window.location.replace(resourcePath); } } } }); } catch (e) { console.log(e); } } function getStorage(name,timeout) { var object = JSON.parse(localStorage.getItem(name)); if(object) { if(Math.round((new Date()).getTime()/1000) < (object.timestamp+timeout)){ return object.value; } else { localStorage.removeItem(name); } } return null; } }(document, Granite.$));