diff --git a/public/userarea/annotationsModal.js b/public/userarea/annotationsModal.js index 66083b3..ad66692 100644 --- a/public/userarea/annotationsModal.js +++ b/public/userarea/annotationsModal.js @@ -798,6 +798,48 @@ $(document).ready(function () { }); } + function enableDragDropPartsList() { + const list = $("#partsListAnnotations"); + if (!list.length || typeof $.ui === "undefined" || !$.ui.sortable) { + console.warn("jQuery UI o .sortable non disponibile. Ritento..."); + setTimeout(enableDragDropPartsList, 100); + return; + } + + if (list.hasClass("ui-sortable")) { + list.sortable("destroy"); // evita duplicati + } + + list.sortable({ + items: "li.list-group-item", + placeholder: "list-group-item placeholder", + axis: "y", + containment: "parent", + tolerance: "pointer", + start: function (e, ui) { + ui.item.addClass("dragging"); + }, + stop: function (e, ui) { + ui.item.removeClass("dragging"); + const newOrder = []; + list.find("li").each(function () { + const partNumber = $(this).data("part-number"); + const part = partsListData.find( + (p) => p.part_number == partNumber, + ); + if (part) newOrder.push(part); + }); + partsListData = newOrder; + console.log( + "Ordine parti aggiornato:", + partsListData.map((p) => p.part_number), + ); + markUnsaved(); + updateMarkers(); + }, + }); + } + // Delegazione evento per il checkbox $(document) .off("change.showMix", "#showMixPartsAnnotations") @@ -830,6 +872,7 @@ $(document).ready(function () { } updatePartsList(); updateMarkers(); + setTimeout(enableDragDropPartsList, 50); if ( photoAnnotations[$("#samplePhotoAnnotations").attr("src")] ?.hasDescriptions diff --git a/public/userarea/modal_annotations.php b/public/userarea/modal_annotations.php index 290b543..35f5135 100644 --- a/public/userarea/modal_annotations.php +++ b/public/userarea/modal_annotations.php @@ -255,4 +255,20 @@ cursor: pointer; border: none; } - \ No newline at end of file + + #partsListAnnotations .list-group-item.dragging { + opacity: 0.6; + background-color: #d1e7dd !important; + transform: rotate(3deg); + box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); + } + + #partsListAnnotations .placeholder { + background-color: #f8d7da !important; + border: 2px dashed #dc3545; + height: 40px; + margin: 2px 0; + border-radius: 4px; + } + + \ No newline at end of file