diff --git a/src/main/resources/static/js/list/list.js b/src/main/resources/static/js/list/list.js new file mode 100644 index 0000000..17de9be --- /dev/null +++ b/src/main/resources/static/js/list/list.js @@ -0,0 +1,49 @@ +import { ShoppingListItem } from "../shared/ShoppingList.js"; +import { ShoppingCategory } from "./ShoppingCategory.js"; + +const addItemForm = document.querySelector(".addItemForm"); +const addCategoryForm = document.querySelector(".addCategoryForm") +const itemListElement = document.querySelector(".displayedList"); +const deleteAllDoneItemsButton = document.querySelector(".deleteAllDoneItemsButton"); + +const currentList = document.querySelector(".list"); + +let listElements = []; // Liste der erstellten Items und Kategorien + +function addNewCategory(categoryName) { + let id = currentList.id; + fetch(`/api/list/${id}/category/`, + { + method: "POST" + , body: JSON.stringify({ "categoryName": categoryName }) + , headers: { "Content-Type": "application/json" } + }).then(r => console.log("Add new category")); + listElements.push(new ShoppingCategory(categoryName, renderAddItemPrompt, renderItemList)); + renderItemList(); + return 0; +} + + +export function addNewItem(itemName, itemAmount, categoryID) { + let id = currentList.id; + fetch(`/api/list/${id}/item`, + { + method: "POST", + body: JSON.stringify({ + "itemName": itemName, + "itemAmount": itemAmount, + "categoryID": categoryID + }), + headers: { "Content-Type": "application/json" } + }).then(r => console.log("added new item")); + + + return 0; +} + +function init() { + +} + + +document.addEventListener('DOMContentLoaded', init);