id zu dataset.id gesetzt
This commit is contained in:
1 parent
d572a55ce6
commit
714d523020
6 files changed
+17
-17
No files matched your search
@@ -17,7 +17,7 @@ export class ShoppingCategory {
|
||||
const deleteCategoryButton = document.createElement("button");
|
||||
const deleteAllItemsCheckbox = document.createElement("input");
|
||||
const innerUl = document.createElement("ul");
|
||||
li.id = this.categoryID;
|
||||
li.dataset.id = this.categoryID;
|
||||
li.classList.add("category");
|
||||
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ export class ShoppingItem {
|
||||
|
||||
const deleteItemButton = document.createElement("button");
|
||||
|
||||
li.id = this.itemID;
|
||||
li.dataset.id = this.itemID;
|
||||
li.classList.add("item");
|
||||
|
||||
checkboxDone.setAttribute("type", "checkbox");
|
||||
|
||||
@@ -16,7 +16,7 @@ export function addCategory(categoryAsJSON) {
|
||||
}
|
||||
|
||||
export function deleteCategory(deleteAllItems, categoryID) {
|
||||
const category = document.getElementById(categoryID);
|
||||
const category = document.querySelector(`li[data-id='${categoryID}']`);
|
||||
if (!deleteAllItems) {
|
||||
const ul = category.querySelector("ul");
|
||||
if (ul) document.querySelector(".displayedList").append(...ul.children);
|
||||
|
||||
@@ -5,7 +5,7 @@ export function addItem(itemAsJSON) {
|
||||
if (!itemAsJSON.categoryID) {
|
||||
list = document.querySelector(".displayedList");
|
||||
} else {
|
||||
list = document.getElementById(`${itemAsJSON.categoryID}`).querySelector("ul");
|
||||
list = document.querySelector(`li[data-id='${itemAsJSON.categoryID}']`).querySelector("ul");
|
||||
}
|
||||
|
||||
const item = ShoppingItem.fromJSON(itemAsJSON);
|
||||
|
||||
@@ -9,9 +9,9 @@ const currentList = document.querySelector(".list");
|
||||
const deleteAllDoneItemsButton = document.querySelector(".deleteAllDoneItemsButton");
|
||||
|
||||
async function addItem(itemName, itemAmount, categoryID) {
|
||||
console.log(` adding item with id:${currentList.id}, name: ${itemName}, amount: ${itemAmount}, category: ${categoryID}`)
|
||||
console.log(` adding item with id:${currentList.dataset.id}, name: ${itemName}, amount: ${itemAmount}, category: ${categoryID}`)
|
||||
|
||||
const response = await api.addItem(currentList.id, itemName, itemAmount, categoryID);
|
||||
const response = await api.addItem(currentList.dataset.id, itemName, itemAmount, categoryID);
|
||||
const json = await response.json();
|
||||
|
||||
if (!response.ok) {
|
||||
@@ -27,7 +27,7 @@ async function addItem(itemName, itemAmount, categoryID) {
|
||||
async function addCategory(categoryName) {
|
||||
console.log(`adding category ${categoryName}`)
|
||||
|
||||
const response = await api.addCategory(currentList.id, categoryName);
|
||||
const response = await api.addCategory(currentList.dataset.id, categoryName);
|
||||
const json = await response.json();
|
||||
|
||||
if (!response.ok) {
|
||||
@@ -47,7 +47,7 @@ async function editItem(textElement) {
|
||||
|
||||
//erstellen das Forms
|
||||
const formElement = ui.createEditItemForm(textElement)
|
||||
let id = textElement.id;
|
||||
let id = textElement.dataset.id;
|
||||
|
||||
textElement.replaceWith(formElement);
|
||||
|
||||
@@ -87,7 +87,7 @@ function editCategory(categoryElement) {
|
||||
//wir nutzen für das Element nur das div, weil sonst alle items mitgelöscht werden würden
|
||||
const categoryDiv = categoryElement.querySelector(".category__div");
|
||||
const formElement = ui.createEditCategoryForm(categoryDiv);
|
||||
let id = categoryElement.id;
|
||||
let id = categoryElement.dataset.id;
|
||||
|
||||
categoryDiv.replaceWith(formElement);
|
||||
|
||||
@@ -122,7 +122,7 @@ function editCategory(categoryElement) {
|
||||
}
|
||||
|
||||
async function deleteItem(li) {
|
||||
const response = await api.deleteItem(li.id);
|
||||
const response = await api.deleteItem(li.dataset.id);
|
||||
|
||||
if (!response.ok) {
|
||||
const json = await response.json();
|
||||
@@ -149,7 +149,7 @@ async function deleteCategory(deleteAllItems, categoryID) {
|
||||
|
||||
async function deleteAllDoneItems() {
|
||||
console.log(`deleting all done items...`)
|
||||
const response = await api.deleteAllDoneItems(currentList.id);
|
||||
const response = await api.deleteAllDoneItems(currentList.dataset.id);
|
||||
|
||||
if (!response.ok) {
|
||||
const json = await response.json();
|
||||
@@ -189,7 +189,7 @@ function init() {
|
||||
} else if (event.target.matches(".category__deleteButton")) {
|
||||
const li = event.target.closest("li");
|
||||
const checkbox = li.querySelector("input[type=checkbox]");
|
||||
deleteCategory(checkbox.checked, li.id);
|
||||
deleteCategory(checkbox.checked, li.dataset.id);
|
||||
|
||||
} else if (event.target.closest(".item__text")) {
|
||||
editItem(event.target.closest("li"));
|
||||
@@ -201,7 +201,7 @@ function init() {
|
||||
document.querySelector(".displayedList").addEventListener("change", (e) => {
|
||||
if (e.target.matches(".item__markAsDone")) {
|
||||
const item = e.target.closest("li");
|
||||
api.editItem(item.id, { isDone: e.target.checked });
|
||||
api.editItem(item.dataset.id, { isDone: e.target.checked });
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
<h1 th:text="${list.listName}"></h1>
|
||||
</div>
|
||||
|
||||
<div class="list" th:id="${list.id}">
|
||||
<div class="list" th:data-id="${list.id}">
|
||||
<form class="addCategoryForm">
|
||||
<span>Neue Kategorie hinzufügen:</span>
|
||||
<input type="text" class="addCategoryForm__nameInput" name="categoryName" placeholder="Neue Kategorie hinzufügen...">
|
||||
@@ -52,7 +52,7 @@
|
||||
|
||||
<ul class="displayedList">
|
||||
<!-- Es werden erste alle Kategorien erstellt, jede Kategorie muss ein ul in einem li sein um Verschachtelung zu ermöglichen -->
|
||||
<li th:each="category: ${categories}" th:id="${category.id}" class="category">
|
||||
<li th:each="category: ${categories}" th:data-id="${category.id}" class="category">
|
||||
<div class="category__div">
|
||||
<span class="category__name category__name--big category__name--bold" th:text="${category.categoryName}"></span>
|
||||
<button class="category__deleteButton">Kategorie löschen</button>
|
||||
@@ -60,7 +60,7 @@
|
||||
</div>
|
||||
<!-- Items der Kategorie -->
|
||||
<ul>
|
||||
<li th:each="item: ${category.itemsInCategory}" th:id="${item.id}" class="item"> <!-- erstellung von einem Item -->
|
||||
<li th:each="item: ${category.itemsInCategory}" th:data-id="${item.id}" class="item"> <!-- erstellung von einem Item -->
|
||||
<input type="checkbox" class="item__markAsDone" th:checked="${item.isDone}" autocomplete="off">
|
||||
<span class="item__text">
|
||||
<span th:text="${item.itemName}" class="item__textName"></span>
|
||||
@@ -71,7 +71,7 @@
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li th:each="item: ${items}" th:id="${item.id}" class="item"> <!-- erstellung items ohne Kategorie -->
|
||||
<li th:each="item: ${items}" th:data-id="${item.id}" class="item"> <!-- erstellung items ohne Kategorie -->
|
||||
<input type="checkbox" class="item__markAsDone" th:checked="${item.isDone}" autocomplete="off">
|
||||
<span class="item__text">
|
||||
<span th:text="${item.itemName}" class="item__textName"></span>
|
||||
|
||||
Reference in new issue
Block a user