save und abort entfernt und gekürtzt
This commit is contained in:
1 parent
e715e66929
commit
ed05aa3a53
1 file changed
+8
-44
@@ -36,30 +36,12 @@ async function editItem(shoppingItem, id) {
|
||||
|
||||
formElement.querySelector(".editForm__name").focus();
|
||||
|
||||
async function save() {
|
||||
|
||||
formElement.addEventListener("submit", async (event) => {
|
||||
event.preventDefault();
|
||||
let formData = Object.fromEntries(new FormData(formElement));
|
||||
console.log(`editing item ${id} with ${formData}`)
|
||||
|
||||
const response = await api.editItem(id, { itemName: formData.newItemName, itemAmount: formData.newItemAmount });
|
||||
|
||||
if (!response.ok) {
|
||||
const json = await response.json();
|
||||
console.error(`Error editingItem ${json}`);
|
||||
showError(json.msg)
|
||||
return;
|
||||
}
|
||||
|
||||
ui.editItem(shoppingItem, formElement, formData);
|
||||
}
|
||||
|
||||
function abort() {
|
||||
formElement.replaceWith(shoppingItem);
|
||||
}
|
||||
|
||||
formElement.addEventListener("submit", (event) => {
|
||||
event.preventDefault();
|
||||
save();
|
||||
let result = handleResponse(api.editItem(id, { itemName: formData.newItemName, itemAmount: formData.newItemAmount }), `kapot item`);
|
||||
if (result) ui.editItem(shoppingItem, formElement, formData);
|
||||
});
|
||||
|
||||
formElement.addEventListener("click", (e) => {
|
||||
@@ -83,32 +65,14 @@ function editCategory(categoryElement, id) {
|
||||
|
||||
formElement.querySelector(".editForm__name").focus();
|
||||
|
||||
async function save() {
|
||||
|
||||
formElement.addEventListener("submit", async (event) => {
|
||||
event.preventDefault();
|
||||
let formData = Object.fromEntries(new FormData(formElement));
|
||||
|
||||
console.log(`editing catogory ${id} with ${formData}`)
|
||||
const result = await handleResponse(api.editCategory(id, { categoryName: formData.newCategoryName }), `error editing category`);
|
||||
if (result) ui.editCategory(id, formElement, formData, categoryDiv);
|
||||
|
||||
const response = await api.editCategory(id, { categoryName: formData.newCategoryName });
|
||||
|
||||
if (!response.ok) {
|
||||
const json = await response.json();
|
||||
console.error(`Error editing category ${json}`);
|
||||
showError(json.msg);
|
||||
return;
|
||||
}
|
||||
|
||||
ui.editCategory(id, formElement, formData, categoryDiv);
|
||||
}
|
||||
|
||||
function abort() {
|
||||
formElement.replaceWith(categoryDiv);
|
||||
}
|
||||
|
||||
|
||||
formElement.addEventListener("submit", (event) => {
|
||||
event.preventDefault();
|
||||
save();
|
||||
});
|
||||
|
||||
formElement.addEventListener("click", (e) => {
|
||||
|
||||
Reference in new issue
Block a user