From 8bc0161e66d4195a3950b2c1c101415719bad043 Mon Sep 17 00:00:00 2001 From: CodeSteak Date: Fri, 6 Mar 2020 16:11:26 +0100 Subject: [PATCH] Implement some session storage magic for back buttons --- .../src/main/resources/static/js/back.js | 31 +++++++++++++++++++ .../resources/templates/fragments/intern.html | 2 +- .../templates/intern/accounting/index.html | 3 ++ .../templates/intern/accounting/main.html | 3 ++ .../templates/intern/accounting/vat.html | 3 ++ .../templates/intern/articles/index.html | 3 ++ .../templates/intern/customerOrders/id.html | 3 ++ .../intern/customerOrders/index.html | 3 ++ .../templates/intern/customers/id.html | 3 ++ .../templates/intern/customers/index.html | 2 ++ .../resources/templates/intern/index.html | 6 ++-- .../templates/intern/listedArticles/id.html | 3 ++ .../intern/listedArticles/index.html | 3 ++ .../intern/supplierOrders/index.html | 3 ++ .../templates/intern/suppliers/id.html | 3 ++ .../templates/intern/suppliers/index.html | 3 ++ .../templates/intern/warehouse/index.html | 3 ++ .../intern/warehouse/slots/index.html | 3 ++ .../templates/intern/warehouse/todo.html | 3 ++ .../resources/templates/shop/articles/id.html | 4 +++ .../resources/templates/shop/checkout.html | 4 ++- .../main/resources/templates/shop/index.html | 2 ++ .../main/resources/templates/shop/search.html | 2 ++ 23 files changed, 93 insertions(+), 5 deletions(-) create mode 100644 prototype/src/main/resources/static/js/back.js diff --git a/prototype/src/main/resources/static/js/back.js b/prototype/src/main/resources/static/js/back.js new file mode 100644 index 0000000..9f41110 --- /dev/null +++ b/prototype/src/main/resources/static/js/back.js @@ -0,0 +1,31 @@ +document.addEventListener("DOMContentLoaded", function(event) { + let back = document.getElementsByClassName('back')[0]; + if (!back) { + return; + } + + let group = back.dataset.group || 'default'; + let name = back.dataset.name; + let insert = back.dataset.insert == "true"; + + if (name) { + window.sessionStorage.setItem('back-' + 'group', JSON.stringify({ + 'text': name, + 'location': window.location.toString() + })); + } + + let history = JSON.parse(window.sessionStorage.getItem('back-' + 'group')); + if (insert && history) { + + let a = document.createElement("a"); + a.href = "#"; + a.onclick = function() { + window.location = history.location; + }; + + a.innerText = history.text || 'Zurück'; + back.appendChild(a); + } + +}); diff --git a/prototype/src/main/resources/templates/fragments/intern.html b/prototype/src/main/resources/templates/fragments/intern.html index 529b3bc..e082898 100644 --- a/prototype/src/main/resources/templates/fragments/intern.html +++ b/prototype/src/main/resources/templates/fragments/intern.html @@ -13,7 +13,7 @@