Compare commits

...
10 Commits
6 changed files with 112 additions and 4 deletions

No files matched your search

@@ -0,0 +1,4 @@
package de.timaldinger.einkaufsliste.Dto;
public record ShoppingListPatchDTO(String newListName) {
}
+16
View File
@@ -1,6 +1,22 @@
.category__name--bold {
font-weight: bold;
}
.category__name--big {
font-size : 1.5rem;
}
.item:has(.item__markAsDone:checked) .item__text{
text-decoration: line-through;
}
.item {
display: flex;
align-items: center;
gap: .5em;
}
.item__text{
display: inline-flex;
gap: .25em;
}
@@ -20,6 +20,9 @@ export class ShoppingItem {
const checkboxDone = document.createElement("input");
const span = document.createElement("span");
const spanName = document.createElement("span");
const spanAmount = document.createElement("span");
const deleteItemButton = document.createElement("button");
li.id = this.itemID;
@@ -29,11 +32,19 @@ export class ShoppingItem {
checkboxDone.setAttribute("autocomplete", "off");
checkboxDone.classList.add("item__markAsDone");
span.textContent = this.itemName + " " + this.itemAmount;
span.classList.add("item__text");
spanName.classList.add("item__textName");
spanAmount.classList.add("item__textAmount");
spanName.textContent = this.itemName;
spanAmount.textContent = this.itemAmount;
deleteItemButton.classList.add("item__deleteButton");
deleteItemButton.textContent = "Löschen";
span.appendChild(spanName);
span.appendChild(spanAmount);
li.appendChild(checkboxDone)
li.appendChild(span);
li.appendChild(deleteItemButton);
+44
View File
@@ -22,6 +22,48 @@ async function addCategory(categoryName) {
return 0;
}
//textElement ist immer das li mit der id
async function editItem(textElement) {
//erstellen das Forms
const formElement = ui.createEditItemForm(textElement)
let id = textElement.id;
textElement.replaceWith(formElement);
formElement.querySelector(".editForm__name").focus();
function save() {
let formData = Object.fromEntries(new FormData(formElement));
let newName = formData.newItemName;
let newAmount = formData.newItemAmount;
textElement.querySelector(".item__textName").textContent = newName;
textElement.querySelector(".item__textAmount").textContent = newAmount;
formElement.replaceWith(textElement);
console.log(`editing item ${id} with ${formData}`)
api.editItem(id, { itemName: newName, itemAmount: newAmount });
}
formElement.addEventListener("submit", (event) => {
save();
});
formElement.addEventListener("keydown", (e) => {
if (e.key == "Escape") formElement.replaceWith(textElement);
})
}
async function editCategory(categoryElement) {
}
function deleteItem(li) {
api.deleteItem(li.id);
ui.deleteItem(li);
@@ -64,6 +106,8 @@ function init() {
const li = event.target.closest("li");
const checkbox = li.querySelector("input[type=checkbox]");
deleteCategory(checkbox.checked, li.id);
} else if (event.target.closest(".item__text")) {
editItem(event.target.closest("li"));
}
});
@@ -14,6 +14,33 @@ export function addItem(itemAsJSON) {
list.appendChild(item.render());
}
export function createEditItemForm(textElement) {
const editForm = document.createElement("form");
const inputName = document.createElement("input");
const inputAmount = document.createElement("input");
const abortButton = document.createElement("button");
const saveButton = document.createElement("button");
inputName.setAttribute("name", "newItemName");
inputName.setAttribute("value", textElement.querySelector(".item__textName").textContent);
inputName.classList.add("editForm__name");
inputAmount.setAttribute("name", "newItemAmount");
inputAmount.setAttribute("value", textElement.querySelector(".item__textAmount").textContent);
inputAmount.classList.add("editForm__amount");
abortButton.textContent = "Abbrechen";
saveButton.textContent = "Speichern";
editForm.appendChild(inputName);
editForm.appendChild(inputAmount);
editForm.appendChild(saveButton);
editForm.appendChild(abortButton);
return editForm;
}
export function deleteItem(li) {
li.remove();
}
+9 -3
View File
@@ -45,8 +45,11 @@
<!-- Items der Kategorie -->
<ul>
<li th:each="item: ${category.itemsInCategory}" th:id="${item.id}" class="item"> <!-- erstellung von einem Item -->
<input type="checkbox" class="item__markAsDone" th:checked="${item.isDone}">
<span th:text="|${item.itemName} ${item.itemAmount}|"></span>
<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>
<span th:text="${item.itemAmount}" class="item__textAmount"></span>
</span>
<button class="item__deleteButton">Löschen</button>
</li>
</ul>
@@ -54,7 +57,10 @@
<li th:each="item: ${items}" th:id="${item.id}" class="item"> <!-- erstellung items ohne Kategorie -->
<input type="checkbox" class="item__markAsDone" th:checked="${item.isDone}" autocomplete="off">
<span th:text="|${item.itemName} ${item.itemAmount}|"></span>
<span class="item__text">
<span th:text="${item.itemName}" class="item__textName"></span>
<span th:text="${item.itemAmount}" class="item__textAmount"></span>
</span>
<button class="item__deleteButton">Löschen</button>
</li>
</ul>