diff --git a/src/main/resources/static/js/index.js b/src/main/resources/static/js/index.js new file mode 100644 index 0000000..60e1eec --- /dev/null +++ b/src/main/resources/static/js/index.js @@ -0,0 +1,32 @@ +import { ShoppingList } from "./ShoppingList.js"; + + +const deleteListButtons = document.querySelectorAll('.shoppingListOverview__deleteListButton'); +const shoppingLists = []; + + +function fillList() { + document.querySelectorAll('.shoppingListOverview__shoppingList') + .forEach(list => { + shoppingLists.push(new ShoppingList(list.id)); + console.log(list.id); + }); + +} + +function deleteList(id) { + fetch(`/api/list/${id}`, { method: "DELETE" }).then(r => console.log("Liste entfernt")) +} + + +function init() { + deleteListButtons.forEach(button => { + button.addEventListener("click", () => { + const id = button.dataset.id; // liest data-id + deleteList(id); + }); + }); + fillList(); +} + +document.addEventListener('DOMContentLoaded', init);