Compare commits

...
10 Commits
Author SHA1 Message Date
Technoir 1750f8059b Kategorietitel wird hervorgehoben 2026-09-29 12:05:05 +02:00
Technoir 49df5b01f5 Select hat jtz Namen damit erfassbar von FormData 2026-09-29 12:04:43 +02:00
Technoir f870421f66 refactoring 2026-09-29 12:04:06 +02:00
Technoir be2a38fedc "Kategorie hinzufügen" Knopf hinzugefügt 2026-09-29 12:04:01 +02:00
Technoir 882bc0e577 refactoring 2026-09-29 12:02:36 +02:00
Technoir 5f3a6c56f9 renderAddItemForm() hinzugefügt, rendert aktiv das Form
Damit hinzugefügte Kategorien auch im Dropdownmenü erscheinen muss das
addItemForm aktiv gerendert werden.
Es wird im init() auch aufgerufen, damit die Option "Keine" erscheint.
Bei einem weiteren hinzufügen einer Kategorie wird sie erneut aufgerufen
und fügt alle vorhandenen Kategorien listElements als Option hinzu.
2026-09-29 12:02:19 +02:00
Technoir 4af57ba1de addNewItem berücksichtig jetzt, ob Gegenstand zu einer Kategorie gehört oder nicht 2026-09-29 12:00:05 +02:00
Technoir ce93c7a56e Grundgerüst Shopping Category
Attribute und render defintitionen implementiert
2026-09-29 11:56:24 +02:00
Technoir 07b58ccad7 Bearbeitung eines Gegenstandes behält Inhalt in Felder 2026-09-29 11:00:05 +02:00
Technoir b3702c0029 Klassennamen refactored, Eingabe für Kategorie hinzugefügt, Umstrukturierung main.js
index.html: Klassennamen angepasst für bessere Übersichtlichkeit und
neuen Form für Kategorie hinzugefügt
main.js: Neue Klassennamen übernommen für query-selector und Methoden
angepasst um Kategorie bei Items zu berücksichtigen
2026-09-29 10:58:23 +02:00
5 changed files with 104 additions and 17 deletions

No files matched your search

+11 -4
View File
@@ -13,14 +13,21 @@
</div>
<div class="list">
<form class="list__inputForm">
<form class="list__form__addCategory">
<span>Neue Kategorie hinzufügen:</span>
<input type="text" class="list__inputForm__categoryName" name="categoryName" placeholder="Neue Kategorie hinzufügen...">
<button class="list__inputForm_submitCategoryButton" type="submit">Hinzufügen</button>
</form>
<br>
<form class="list__form__addItem">
<span>Neuen Gegenstand hinzufügen:</span>
<input type="text" class="list__inputForm__itemName" name="itemName" placeholder="Gegenstand eingeben...">
<input type="text" class="list__inputForm__itemAmount" name="itemAmount" placeholder="Menge eingeben...">
<select class="list__inputForm_selectCategory">
<select class="list__inputForm__selectCategory" name="itemCategory">
</select>
<button class="list__inputForm__submitButton" type="submit">Hinzufügen</button>
<button class="list__inputForm__submitItemButton" type="submit">Hinzufügen</button>
</form>
<ul class="list__displayedList">
+28
View File
@@ -1,3 +1,31 @@
export class ShoppingCategory {
constructor(categoryName) {
this.categoryName = categoryName;
this.itemsInCategory = [];
this.remove = false;
this.isEditing = false;
}
render() {
let element;
if (this.isEditing) {
element = this.#renderEditing();
} else {
element = this.#renderNormal();
}
return element;
}
#renderEditing() {
}
#renderNormal() {
}
addItem(item) {
this.itemsInCategory.push(item);
}
}
+3
View File
@@ -31,7 +31,10 @@ export class ShoppingListItem {
editNameField.setAttribute("name", "newItemName");
editNameField.setAttribute("value", this.name);
editAmountField.setAttribute("name", "newItemAmount");
editAmountField.setAttribute("value", this.amount);
abortButton.textContent = "Abbrechen";
abortButton.addEventListener("click", (event) => {
+55 -13
View File
@@ -1,38 +1,80 @@
import { ShoppingListItem } from "./ShoppingListItem";
import { ShoppingCategory } from "./ShoppingCategory";
const form = document.querySelector(".list__inputForm");
const addItemForm = document.querySelector(".list__form__addItem");
const addCategoryForm = document.querySelector(".list__form__addCategory")
const itemListElement = document.querySelector(".list__displayedList");
let listItems = []; //list of items that the user has
let listElements = []; // Liste der erstellten Items und Kategorien
function addNewCategory(categoryName) {
listElements.push(new ShoppingCategory(categoryName));
return 0;
}
function handleListElement(itemName, itemAmount,) {
listItems.push(new ShoppingListItem(itemName, itemAmount, renderList));
renderList();
function addNewItem(itemName, itemAmount, category) {
if (category) {
category = listElements.find((element) => element instanceof ShoppingCategory && element.categoryName == category)
category.addItem(new ShoppingListItem(itemName, itemAmount, renderItemList));
} else {
listElements.push(new ShoppingListItem(itemName, itemAmount, renderItemList));
}
renderItemList();
return 0;
}
function renderList() {
listItems = listItems.filter(item => !item.remove)
function renderItemList() {
listElements = listElements.filter(item => !item.remove)
itemListElement.innerHTML = ""; //reset innerItemList
listItems.forEach((element, index) => {
listElements.forEach((element, index) => {
itemListElement.appendChild(element.render(index));
});
}
function renderAddItemPrompt() {
const selectMenu = document.querySelector(".list__inputForm__selectCategory");
let categories = listElements.filter(element => element instanceof ShoppingCategory);
const emptySelection = document.createElement("option");
emptySelection.setAttribute("value", "");
emptySelection.selected = true;
emptySelection.textContent = "Keine"
selectMenu.innerHTML = "";
selectMenu.appendChild(emptySelection);
categories.forEach(category => {
const option = document.createElement("option");
option.setAttribute("value", category.categoryName);
option.textContent = category.categoryName;
selectMenu.appendChild(option);
});
}
function init() {
document.querySelector(".list__inputForm").addEventListener("submit", (event) => {
if (!form.checkValidity()) return;
renderAddItemPrompt();
document.querySelector(".list__form__addItem").addEventListener("submit", (event) => {
if (!addItemForm.checkValidity()) return;
event.preventDefault();
const formData = Object.fromEntries(new FormData(form));
handleListElement(formData.itemName, formData.itemAmount);
const addItemFormData = Object.fromEntries(new FormData(addItemForm));
addNewItem(addItemFormData.itemName, addItemFormData.itemAmount, addItemFormData.itemCategory);
});
document.querySelector(".list__form__addCategory").addEventListener("submit", (event) => {
if (!addCategoryForm.checkValidity()) return;
event.preventDefault();
const addCategoryFormData = Object.fromEntries(new FormData(addCategoryForm));
addNewCategory(addCategoryFormData.categoryName);
renderAddItemPrompt();
});
}
+7
View File
@@ -2,3 +2,10 @@
li:has(input:checked){
text-decoration: line-through;
}
ul[title]::before {
content: attr(title);
display: block;
font-weight: bold;
}