Compare commits
4
Commits
1750f8059b
...
bb0853aa9c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bb0853aa9c | ||
|
|
1e542236d0 | ||
|
|
a0c17a9541 | ||
|
|
4a032000ae |
No files matched your search
+30
-1
@@ -1,14 +1,18 @@
|
||||
export class ShoppingCategory {
|
||||
|
||||
constructor(categoryName) {
|
||||
constructor(categoryName, onDelete) {
|
||||
this.categoryName = categoryName;
|
||||
this.itemsInCategory = [];
|
||||
this.remove = false;
|
||||
this.isEditing = false;
|
||||
this.onDelete = onDelete;
|
||||
}
|
||||
|
||||
render() {
|
||||
let element;
|
||||
if (this.itemsInCategory.length == 0) return;
|
||||
|
||||
|
||||
if (this.isEditing) {
|
||||
element = this.#renderEditing();
|
||||
} else {
|
||||
@@ -23,6 +27,31 @@ export class ShoppingCategory {
|
||||
}
|
||||
|
||||
#renderNormal() {
|
||||
|
||||
const outerLi = document.createElement("li");
|
||||
const h2CategoryName = document.createElement("h2");
|
||||
const removeCategoryButton = document.createElement("button"); // Entfernen der Kategorie
|
||||
const ul = document.createElement("ul");
|
||||
|
||||
|
||||
const items = this.itemsInCategory.filter((item) => !item.remove);
|
||||
|
||||
h2CategoryName.textContent = this.categoryName;
|
||||
|
||||
removeCategoryButton.textContent = "Löschen";
|
||||
removeCategoryButton.addEventListener("click", () => {
|
||||
this.remove = true;
|
||||
this.onDelete();
|
||||
});
|
||||
|
||||
items.forEach((item, index) => {
|
||||
ul.append(item.render());
|
||||
});
|
||||
|
||||
outerLi.appendChild(h2CategoryName);
|
||||
outerLi.append(removeCategoryButton);
|
||||
outerLi.appendChild(ul);
|
||||
return outerLi;
|
||||
}
|
||||
|
||||
addItem(item) {
|
||||
|
||||
@@ -72,7 +72,6 @@ export class ShoppingListItem {
|
||||
const li = document.createElement("li");
|
||||
const listContent = document.createElement("span");
|
||||
const removeButton = document.createElement("button");
|
||||
const editButton = document.createElement("button");
|
||||
const doneButton = document.createElement("input");
|
||||
|
||||
doneButton.setAttribute("type", "checkbox");
|
||||
@@ -80,8 +79,7 @@ export class ShoppingListItem {
|
||||
this.isDone = doneButton.checked;
|
||||
});
|
||||
|
||||
editButton.textContent = "Bearbeiten"
|
||||
editButton.addEventListener("click", () => {
|
||||
listContent.addEventListener("click", () => {
|
||||
this.isEditing = true;
|
||||
this.onChange();
|
||||
});
|
||||
@@ -96,7 +94,6 @@ export class ShoppingListItem {
|
||||
|
||||
li.appendChild(doneButton);
|
||||
li.appendChild(listContent);
|
||||
li.appendChild(editButton);
|
||||
li.appendChild(removeButton);
|
||||
|
||||
return li;
|
||||
|
||||
+2
-2
@@ -8,10 +8,11 @@ const itemListElement = document.querySelector(".list__displayedList");
|
||||
let listElements = []; // Liste der erstellten Items und Kategorien
|
||||
|
||||
function addNewCategory(categoryName) {
|
||||
listElements.push(new ShoppingCategory(categoryName));
|
||||
listElements.push(new ShoppingCategory(categoryName, renderItemList));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
function addNewItem(itemName, itemAmount, category) {
|
||||
if (category) {
|
||||
category = listElements.find((element) => element instanceof ShoppingCategory && element.categoryName == category)
|
||||
@@ -24,7 +25,6 @@ function addNewItem(itemName, itemAmount, category) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
function renderItemList() {
|
||||
listElements = listElements.filter(item => !item.remove)
|
||||
itemListElement.innerHTML = ""; //reset innerItemList
|
||||
|
||||
@@ -2,10 +2,3 @@
|
||||
li:has(input:checked){
|
||||
text-decoration: line-through;
|
||||
}
|
||||
|
||||
ul[title]::before {
|
||||
content: attr(title);
|
||||
display: block;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user