diff --git a/src/main/resources/static/js/list/list.js b/src/main/resources/static/js/list/list.js index 17de9be..902ccbb 100644 --- a/src/main/resources/static/js/list/list.js +++ b/src/main/resources/static/js/list/list.js @@ -1,45 +1,11 @@ -import { ShoppingListItem } from "../shared/ShoppingList.js"; +import { ShoppingListItem } from "../shared/"; 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"); +import * as api from "./listAPI.js" +import * as ui from "./listFrontend.js" 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() { diff --git a/src/main/resources/static/js/list/listAPI.js b/src/main/resources/static/js/list/listAPI.js new file mode 100644 index 0000000..de60656 --- /dev/null +++ b/src/main/resources/static/js/list/listAPI.js @@ -0,0 +1,40 @@ + +export function addItem(currentList, 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; +} + + +export function deleteItem() { + +} + +export function addCategory() { + 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 deleteCategory() { + +} diff --git a/src/main/resources/static/js/list/listFrontend.js b/src/main/resources/static/js/list/listFrontend.js new file mode 100644 index 0000000..6cc6ebb --- /dev/null +++ b/src/main/resources/static/js/list/listFrontend.js @@ -0,0 +1,16 @@ + +export function addItem() { + +} + +export function deleteItem() { + +} + +export function addCategory() { + +} + +export function deleteCategory() { + +}