{"version":3,"file":"FileExport.min.js","sources":["EncompassWebServices/Controls/FileExport.js"],"sourcesContent":["\"use strict\";\r\n\r\nconst BC_FileExport = function (EWS) {\r\n this.EWS = EWS;\r\n this.GoogleAttempts = 0;\r\n\r\n const me = this;\r\n let IsSubmit = false;\r\n\r\n EWS.Command.AddMenu(\"BC_FileExport_ExportMenu\", (control, name, menu, callback) => {\r\n menu.innerHTML = \"\";\r\n\r\n callback(control, menu);\r\n }, (control, name, menu, menuArgs) => {\r\n if (!IsSubmit) {\r\n // Task 969413: JavaScript Error: DashboardID=100120 (0) - TypeError: Cannot read property 'replaceChild' of null\r\n IsSubmit = true;\r\n menu.style.display = \"none\";\r\n menu.innerHTML = \"\";\r\n\r\n const processUrlCallback = menuArgs.processUrlCallback;\r\n const processGoogleCallback = menuArgs.processGoogleCallback;\r\n // Task 916478: Report Print: Print Preview is different in 21.02 than in 20.09. Printing the same report Driver Manifest 5.1 has different layouts in different ECP\r\n let customOptions = menuArgs.customOptions;\r\n\r\n EWS.VerifySession(() => {\r\n const myRequest = new ECP.EC_Request(\"FileExport_ExportMenu\");\r\n // Task 757605: I still have an issue with one of my other saved reports. When I try to export the file I get an error code 'error in promise'\r\n myRequest.AddRequestVariable(\"Url\", menuArgs.url, ECP.EC_Verb.Post);\r\n if (!EC_Fmt.isNull(menuArgs.formats)) {\r\n myRequest.AddRequestVariable(\"Formats\", menuArgs.formats);\r\n }\r\n myRequest.Submit().then((result) => {\r\n let html = \"\";\r\n const options = EWS.Json.Query(result, \"$.options[?(@.format != 'WebQuery')]\");\r\n\r\n for (let i = 0; i < options.length; i++) {\r\n html += `
\";\r\n }\r\n\r\n if (customOptions) {\r\n if (!Array.isArray(customOptions)) {\r\n customOptions = [customOptions];\r\n }\r\n for (let i = 0; i < customOptions.length; i++) {\r\n const option = customOptions[i];\r\n\r\n html += ` \";\r\n }\r\n }\r\n\r\n const query = EWS.Json.Query(result, \"$.options[?(@.format == 'WebQuery')]\")[0];\r\n\r\n if (query) {\r\n html += \"\"\r\n + ` \";\r\n }\r\n\r\n menu.innerHTML = html;\r\n menu.style.display = \"block\";\r\n\r\n menu = EC_Fmt.RemoveAllEventListeners(menu);\r\n\r\n menu.addEventListener(\"click\", (event) => {\r\n const trigger = event.target.closest(\".ews-menu-item\");\r\n\r\n if (trigger) {\r\n const format = trigger.getAttribute(\"format\");\r\n let url = trigger.getAttribute(\"url\");\r\n\r\n if (processUrlCallback) {\r\n url = processUrlCallback(url, format);\r\n }\r\n\r\n // Task 1033298: Adding Google Analytics as a default feature of dashboards\r\n gtag(\"event\", \"share\", { content_type: format });\r\n\r\n switch (format) {\r\n case \"Google\":\r\n me.AuthGoogle(url, null, processGoogleCallback);\r\n break;\r\n\r\n case \"Print\":\r\n Print_Preview(trigger.getAttribute(\"url\"), \"XLSX\", null, null, processUrlCallback);\r\n break;\r\n\r\n case \"WebQuery\":\r\n const PostData = new FormData();\r\n\r\n PostData.append(\"Format\", \"WebQuery\");\r\n PostData.append(\"Lifetime\", \"180\");\r\n PostData.append(\"Impersonate\", \"True\");\r\n PostData.append(\"Url\", url.replace(\"Format=WebQuery\", \"\"));\r\n\r\n EWS.VerifySession(() => {\r\n fetch(\"api?APICommand=QuickLinkAjax&Requests=Generate\", {\r\n credentials: \"same-origin\",\r\n method: \"POST\",\r\n body: PostData\r\n }).then(response => response.json()).then((responseJson) => {\r\n window.location.href = responseJson.url;\r\n });\r\n });\r\n break;\r\n case \"BrowserPrint\":\r\n menu.style.display = \"none\";\r\n window.print();\r\n break;\r\n\r\n case \"Custom\":\r\n const sequence = EC_Fmt.Null2ZeroInt(trigger.getAttribute(\"sequence\"));\r\n const option = customOptions[sequence];\r\n if (option?.processCallback) {\r\n option.processCallback();\r\n break;\r\n }\r\n break;\r\n\r\n default:\r\n let title = document.getElementsByTagName(\"title\");\r\n if (title.length > 0) {\r\n title = title[0].innerHTML;\r\n }\r\n EC_Fmt.DownloadFileFromURL(url, EC_Fmt.Null2EmptyStr(title));\r\n\r\n // Task 661168: Adding a download file animation\r\n menu.style.display = \"block\";\r\n\r\n const originalIcon = trigger.querySelector(\"div.ews-menu-icon\");\r\n const originalPosition = originalIcon.getBoundingClientRect();\r\n\r\n const animationContainer = document.createElement(\"div\");\r\n animationContainer.classList.add(\"ews-menu\");\r\n animationContainer.setAttribute(\"style\", `position:fixed;display:block;top:${originalPosition.top}px;left:${originalPosition.left}px;z-index:10001;color:var(--neutral-120)`);\r\n const icon = document.createElement(\"div\");\r\n animationContainer.appendChild(icon);\r\n\r\n document.body.appendChild(animationContainer);\r\n icon.setAttribute(\"style\", `position:fixed;display:block;top:${originalPosition.top}px;left:${originalPosition.left}px;z-index:10001;color:var(--neutral-120)`);\r\n icon.classList = originalIcon.classList;\r\n icon.innerHTML = ` ${title}`;\r\n requestAnimationFrame(() => {\r\n icon.classList.add(\"ews-menu-icon-download-animation\");\r\n setTimeout(() => {\r\n menu.style.display = \"none\";\r\n document.body.removeChild(animationContainer);\r\n }, 1000);\r\n });\r\n\r\n break;\r\n }\r\n // Task 694365: After clicking Export --> Print, do not hide\r\n if (menu) {\r\n menu.style.display = \"none\";\r\n }\r\n }\r\n });\r\n IsSubmit = false;\r\n });\r\n }, true, null, () => {\r\n // Task 604081: Export and print buttons do nothing on Quicklinks reports - Add option to login when clicking those buttons\r\n ECP.Dialog.ShowDialog(\"Confirm\", `