From 05de62c87a6b4e10b2a11a4f2de180397188598c Mon Sep 17 00:00:00 2001
From: Dennis Heinrich
Date: Thu, 10 Apr 2025 19:13:13 +0200
Subject: [PATCH] WIP: Speichern und hochladen einer JSON-Datei
---
assets/script/all.js | 43 ++++++++++++++++++++++++++++++++++++++++++-
index.html | 18 ++++++++++++++++++
2 files changed, 60 insertions(+), 1 deletion(-)
diff --git a/assets/script/all.js b/assets/script/all.js
index 57d1d99..93415be 100644
--- a/assets/script/all.js
+++ b/assets/script/all.js
@@ -21,6 +21,18 @@ class Element {
return document.querySelector('#input-export-import');
}
+ static getFileExportButton() {
+ return document.querySelector('#export-file');
+ }
+
+ static getFileImportButton() {
+ return document.querySelector('#import-file-button');
+ }
+
+ static getFileImportFileInput() {
+ return document.querySelector('#import-file');
+ }
+
/**
* Get the product list element
* @returns {HTMLElement}
@@ -703,4 +715,33 @@ const cartManager = new CartManager();
const productManager = new ProductManager();
const tabManager = new TabManager();
const themeManager = new ThemeManager();
-const cartHistoryManager = new CartHistoryManager();
\ No newline at end of file
+const cartHistoryManager = new CartHistoryManager();
+
+
+Element.getFileExportButton().addEventListener('click', () => {
+ const blob = new Blob([Element.getImportExportTextarea().value], { type: 'application/json' });
+ const url = URL.createObjectURL(blob);
+ const a = document.createElement('a');
+ a.href = url;
+ a.download = 'products.json';
+ document.body.appendChild(a);
+ a.click();
+ setTimeout(() => {
+ URL.revokeObjectURL(url);
+ a.remove();
+ }, 0);
+});
+
+Element.getFileImportButton().addEventListener('click', () => {
+ let inputJsonFile = Element.getFileImportFileInput();
+ let fileContent = inputJsonFile.files[0];
+ if (fileContent) {
+ const reader = new FileReader();
+ reader.onload = async (e) => {
+ const json = JSON.parse(e.target.result);
+ await productManager.convertAndSaveProductImages(json);
+ location.reload();
+ };
+ reader.readAsText(fileContent);
+ }
+})
\ No newline at end of file
diff --git a/index.html b/index.html
index 9595fea..83d2f8a 100644
--- a/index.html
+++ b/index.html
@@ -117,6 +117,24 @@
lädt die Software das Bild herunter und speichert es in der JSON-Datei als Base64-kodierte
Version. Die ursprüngliche URL wird dabei nicht mehr gespeichert.
+
+
+
+
+
+ |
+
+
+
+
+
+
+
+