refactoring

This commit is contained in:
Technoir committed 2026-09-30 14:35:15 +02:00
1 parent 3f89d22f02
commit 0fb44f0fd3
1 file changed
+19 -18
+19 -18
View File
@@ -1,8 +1,8 @@
export class ShoppingListItem {
constructor(name, amount, onChange) {
this.name = name;
this.amount = amount;
constructor(itemName, itemAmount, onChange) {
this.itemName = itemName;
this.itemAmount = itemAmount;
this.isDone = false;
this.isEditing = false;
this.remove = false;
@@ -13,7 +13,7 @@ export class ShoppingListItem {
render() {
let li;
if (this.isEditing) {
li = this.#renderEditing();
li = this.#rendereditIng();
} else {
li = this.#renderNormal()
}
@@ -21,20 +21,20 @@ export class ShoppingListItem {
}
#renderEditing() {
#rendereditIng() {
const li = document.createElement("li");
const editForm = document.createElement("form");
const editNameField = document.createElement("input");
const editAmountField = document.createElement("input");
const editItemNameField = document.createElement("input");
const editItemAmountField = document.createElement("input");
const saveButton = document.createElement("button");
const abortButton = document.createElement("button");
editNameField.setAttribute("name", "newItemName");
editNameField.setAttribute("value", this.name);
editItemNameField.setAttribute("name", "newItemName");
editItemNameField.setAttribute("value", this.name);
editAmountField.setAttribute("name", "newItemAmount");
editAmountField.setAttribute("value", this.amount);
editItemAmountField.setAttribute("itemName", "newItemAmount");
editItemAmountField.setAttribute("value", this.amount);
abortButton.textContent = "Abbrechen";
abortButton.addEventListener("click", (event) => {
@@ -49,18 +49,18 @@ export class ShoppingListItem {
const editFormData = Object.fromEntries(new FormData(editForm));
if (!editFormData.newItemName && !editFormData.newItemAmount) {
if (!editFormData.newItemitemName && !editFormData.newItemitemAmount) {
return;
}
this.name = editFormData.newItemName;
this.amount = editFormData.newItemAmount;
this.isEditing = false;
this.itemName = editFormData.newItemName;
this.itemAmount = editFormData.newItemAmount;
this.isediting = false;
this.onChange();
});
editForm.appendChild(editNameField);
editForm.appendChild(editAmountField);
editForm.appendChild(editItemNameField);
editForm.appendChild(editItemAmountField);
editForm.appendChild(saveButton);
editForm.appendChild(abortButton);
li.appendChild(editForm);
@@ -74,6 +74,7 @@ export class ShoppingListItem {
const removeButton = document.createElement("button");
const doneButton = document.createElement("input");
doneButton.setAttribute("type", "checkbox");
doneButton.addEventListener("change", () => {
this.isDone = doneButton.checked;
@@ -90,7 +91,7 @@ export class ShoppingListItem {
this.onChange();
});
listContent.textContent = this.name + " " + this.amount;
listContent.textContent = this.itemName + " " + this.itemAmount;
li.appendChild(doneButton);
li.appendChild(listContent);