From c71def838dda86a4ce8f78d5ca54cd4a533ff921 Mon Sep 17 00:00:00 2001 From: Gemini Agent Date: Tue, 12 May 2026 09:20:32 +0000 Subject: [PATCH] Fix workflow issues: allow split dragging and add return-to-table prompt - Modified API handler so adding items from Phase 1 always creates distinct rows on the Table. This allows splitting and dragging identical items into different backpack compartments. - Added a modal prompt when removing an item from a backpack, asking the user whether to delete it completely or just move it back to the virtual table. --- src/api_packing_list_handler.php | 45 +++++++++++------------- src/manage_packing_list_items.php | 57 +++++++++++++++++++++++++++---- 2 files changed, 70 insertions(+), 32 deletions(-) diff --git a/src/api_packing_list_handler.php b/src/api_packing_list_handler.php index cf251f7..53d70f9 100644 --- a/src/api_packing_list_handler.php +++ b/src/api_packing_list_handler.php @@ -185,34 +185,27 @@ try { $include_children = !empty($data['include_children']); function adjust_single($conn, $packing_list_id, $art_id, $delta) { - $stmt_find = $conn->prepare("SELECT id, quantity FROM packing_list_items WHERE packing_list_id = ? AND article_id = ? AND carrier_user_id IS NULL AND backpack_id IS NULL AND backpack_compartment_id IS NULL AND parent_packing_list_item_id IS NULL LIMIT 1"); - $stmt_find->bind_param("ii", $packing_list_id, $art_id); - $stmt_find->execute(); - $res = $stmt_find->get_result(); - if ($row = $res->fetch_assoc()) { - $new_quantity = $row['quantity'] + $delta; - if ($new_quantity > 0) { - $stmt_update = $conn->prepare("UPDATE packing_list_items SET quantity = ? WHERE id = ?"); - $stmt_update->bind_param("ii", $new_quantity, $row['id']); - $stmt_update->execute(); - $stmt_update->close(); - } else { - $stmt_del = $conn->prepare("DELETE FROM packing_list_items WHERE id = ?"); - $stmt_del->bind_param("i", $row['id']); - $stmt_del->execute(); - $stmt_del->close(); - } - } else { - if ($delta > 0) { - $idx_res = $conn->query("SELECT MAX(order_index) as max_idx FROM packing_list_items WHERE packing_list_id = $packing_list_id"); - $next_idx = ($idx_res->fetch_assoc()['max_idx'] ?? 0) + 1; - $stmt_insert = $conn->prepare("INSERT INTO packing_list_items (packing_list_id, article_id, quantity, order_index) VALUES (?, ?, ?, ?)"); - $stmt_insert->bind_param("iiii", $packing_list_id, $art_id, $delta, $next_idx); - $stmt_insert->execute(); - $stmt_insert->close(); + if ($delta > 0) { + $idx_res = $conn->query("SELECT MAX(order_index) as max_idx FROM packing_list_items WHERE packing_list_id = $packing_list_id"); + $next_idx = ($idx_res->fetch_assoc()['max_idx'] ?? 0) + 1; + $stmt_insert = $conn->prepare("INSERT INTO packing_list_items (packing_list_id, article_id, quantity, order_index) VALUES (?, ?, ?, ?)"); + $stmt_insert->bind_param("iiii", $packing_list_id, $art_id, $delta, $next_idx); + $stmt_insert->execute(); + $stmt_insert->close(); + } else if ($delta < 0) { + $stmt_find = $conn->prepare("SELECT id, quantity FROM packing_list_items WHERE packing_list_id = ? AND article_id = ? AND carrier_user_id IS NULL AND backpack_id IS NULL AND backpack_compartment_id IS NULL AND parent_packing_list_item_id IS NULL ORDER BY quantity ASC LIMIT 1"); + $stmt_find->bind_param("ii", $packing_list_id, $art_id); + $stmt_find->execute(); + $res = $stmt_find->get_result(); + if ($row = $res->fetch_assoc()) { + if ($row['quantity'] > 1) { + $conn->query("UPDATE packing_list_items SET quantity = quantity - 1 WHERE id = " . $row['id']); + } else { + $conn->query("DELETE FROM packing_list_items WHERE id = " . $row['id']); + } } + $stmt_find->close(); } - $stmt_find->close(); } adjust_single($conn, $packing_list_id, $article_id, $delta); diff --git a/src/manage_packing_list_items.php b/src/manage_packing_list_items.php index 76d50c0..fba1232 100644 --- a/src/manage_packing_list_items.php +++ b/src/manage_packing_list_items.php @@ -307,6 +307,24 @@ $conn->close(); + +
Änderungen gespeichert!
@@ -731,6 +749,9 @@ $conn->close(); }, 300); } + let itemToRemoveId = null; + let itemToRemoveEl = null; + function handlePackedItemActions(e) { const button = e.target.closest('button'); if (!button) return; @@ -739,12 +760,36 @@ $conn->close(); const itemId = itemEl.dataset.itemId; if (button.classList.contains('remove-item-btn')) { - if (confirm('Diesen Artikel wirklich aus der Liste entfernen?')) { - itemEl.remove(); - sendApiRequest({ action: 'delete_item', item_id: itemId }).then(newItems => { - if(Array.isArray(newItems)) packedItems = newItems; - fullRender(); - }); + const isTable = (itemEl.closest('#table-container') !== null); + if (isTable) { + if (confirm('Diesen Artikel wirklich aus der Liste entfernen?')) { + itemEl.remove(); + sendApiRequest({ action: 'delete_item', item_id: itemId }).then(newItems => { + if(Array.isArray(newItems)) packedItems = newItems; + fullRender(); + }); + } + } else { + itemToRemoveId = itemId; + itemToRemoveEl = itemEl; + if (!window.removeItemModalInstance) { + window.removeItemModalInstance = new bootstrap.Modal(document.getElementById('removeItemModal')); + document.getElementById('btn-remove-delete').onclick = () => { + window.removeItemModalInstance.hide(); + itemToRemoveEl.remove(); + sendApiRequest({ action: 'delete_item', item_id: itemToRemoveId }).then(newItems => { + if(Array.isArray(newItems)) packedItems = newItems; + fullRender(); + }); + }; + document.getElementById('btn-remove-totable').onclick = () => { + window.removeItemModalInstance.hide(); + const tableContainer = document.getElementById('table-container'); + tableContainer.appendChild(itemToRemoveEl); + syncListState(); + }; + } + window.removeItemModalInstance.show(); } } }