26ff8d9b4f
Set up repository with legacy .NET Framework 4.8 source (OLD/), new .NET 10 Blazor solution (NEW/), OpenSpec specifications, documentation, and project configuration.
71 lines
2.2 KiB
JavaScript
71 lines
2.2 KiB
JavaScript
// JDE Scoping Tool - JavaScript Interop Functions
|
|
|
|
// Global download function for file byte arrays (called from Blazor)
|
|
window.downloadFile = function (fileName, byteArray) {
|
|
const blob = new Blob([new Uint8Array(byteArray)]);
|
|
const url = URL.createObjectURL(blob);
|
|
const anchorElement = document.createElement('a');
|
|
anchorElement.href = url;
|
|
anchorElement.download = fileName ?? 'download';
|
|
anchorElement.click();
|
|
anchorElement.remove();
|
|
URL.revokeObjectURL(url);
|
|
};
|
|
|
|
window.jdeScopingInterop = {
|
|
// Download file from a byte array stream
|
|
downloadFileFromStream: async function (fileName, contentStreamReference) {
|
|
const arrayBuffer = await contentStreamReference.arrayBuffer();
|
|
const blob = new Blob([arrayBuffer]);
|
|
const url = URL.createObjectURL(blob);
|
|
|
|
const anchorElement = document.createElement('a');
|
|
anchorElement.href = url;
|
|
anchorElement.download = fileName ?? 'download';
|
|
anchorElement.click();
|
|
anchorElement.remove();
|
|
|
|
URL.revokeObjectURL(url);
|
|
},
|
|
|
|
// Download file from a URL
|
|
downloadFileFromUrl: function (url, fileName) {
|
|
const anchorElement = document.createElement('a');
|
|
anchorElement.href = url;
|
|
anchorElement.download = fileName ?? 'download';
|
|
anchorElement.target = '_blank';
|
|
anchorElement.click();
|
|
anchorElement.remove();
|
|
},
|
|
|
|
// Save value to localStorage
|
|
setLocalStorage: function (key, value) {
|
|
localStorage.setItem(key, value);
|
|
},
|
|
|
|
// Get value from localStorage
|
|
getLocalStorage: function (key) {
|
|
return localStorage.getItem(key);
|
|
},
|
|
|
|
// Remove value from localStorage
|
|
removeLocalStorage: function (key) {
|
|
localStorage.removeItem(key);
|
|
},
|
|
|
|
// Save value to sessionStorage (clears when browser closes)
|
|
setSessionStorage: function (key, value) {
|
|
sessionStorage.setItem(key, value);
|
|
},
|
|
|
|
// Get value from sessionStorage
|
|
getSessionStorage: function (key) {
|
|
return sessionStorage.getItem(key);
|
|
},
|
|
|
|
// Remove value from sessionStorage
|
|
removeSessionStorage: function (key) {
|
|
sessionStorage.removeItem(key);
|
|
}
|
|
};
|