Fix workflow issues: allow split dragging and add return-to-table prompt
All checks were successful
Docker Build & Push / build-and-push (push) Successful in 11s
All checks were successful
Docker Build & Push / build-and-push (push) Successful in 11s
- 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.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -307,6 +307,24 @@ $conn->close();
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal fade" id="removeItemModal" tabindex="-1" aria-labelledby="removeItemModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="removeItemModalLabel">Artikel entfernen</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
Was möchtest du mit diesem Artikel tun?
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-danger" id="btn-remove-delete">Komplett löschen</button>
|
||||
<button type="button" class="btn btn-primary" id="btn-remove-totable">Zurück auf den Tisch</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="save-feedback" class="save-feedback">Änderungen gespeichert!</div>
|
||||
<div id="image-preview-tooltip" class="image-preview-tooltip"></div>
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user