From f3e5cb4ffdcb26b633e6769352f29162d647073e Mon Sep 17 00:00:00 2001 From: solocla Date: Tue, 5 May 2026 09:37:18 +0200 Subject: [PATCH] fixed capitolato riferimento --- public/userarea/modal_partsTable.php | 128 +++++++++++++++- public/userarea/partsTable.js | 212 ++++++++++++++++++++++++--- 2 files changed, 317 insertions(+), 23 deletions(-) diff --git a/public/userarea/modal_partsTable.php b/public/userarea/modal_partsTable.php index 2080ebc..ac3e849 100644 --- a/public/userarea/modal_partsTable.php +++ b/public/userarea/modal_partsTable.php @@ -20,8 +20,7 @@ - - + + + + `; } - // Testo -> input + hidden field_id + // Campo testo: titolo sopra, input + bottone sotto return ` - - - - `; + +
+
+ ${label} +
+
+ + +
+
+ `; } function initializeExtraFieldSelect2($context) { @@ -191,6 +247,79 @@ $(document).ready(function () { saveRow($row); }); + $(document).on("click", ".extra-propagate-btn", function (e) { + e.preventDefault(); + + if (!partsExtraField) return; + + const isSelect = + (partsExtraField.data_type || "").toLowerCase() === + "sceltamultipla"; + + let propagateValueId = null; + let propagateValueText = null; + + if (isSelect) { + propagateValueId = + $("#partsTable thead .extra-propagate-select").val() || ""; + + if (!propagateValueId) { + const errorMsg = $( + '', + ); + $("#partsModal .modal-body").prepend(errorMsg); + setTimeout(() => { + errorMsg.fadeOut(500, function () { + $(this).remove(); + }); + }, 3500); + return; + } + } else { + propagateValueText = ( + $("#partsTable thead .extra-propagate-input").val() || "" + ).trim(); + + if (!propagateValueText) { + const errorMsg = $( + '', + ); + $("#partsModal .modal-body").prepend(errorMsg); + setTimeout(() => { + errorMsg.fadeOut(500, function () { + $(this).remove(); + }); + }, 3500); + return; + } + } + + $("#partsTableBody tr").each(function () { + const $row = $(this); + + if (isSelect) { + const $select = $row.find(".part-extra-select"); + + if ($select.length) { + $select.val(propagateValueId).trigger("change.select2"); + + $row.data("extra-value-id", propagateValueId); + $row.find(".part-extra-value-id").val(propagateValueId); + } + } else { + const $input = $row.find(".part-extra-field"); + + if ($input.length) { + $input.val(propagateValueText); + + $row.data("extra-value-text", propagateValueText); + } + } + + saveRow($row); + }); + }); + function applyExtraFieldColumn() { const $theadRow = $("#partsTable thead tr"); @@ -203,16 +332,17 @@ $(document).ready(function () { }); // 3) se non c'è campo extra -> fine - if (!partsExtraField) return; + if (!partsExtraField) { + if (typeof window.applyPartsColumnWidths === "function") { + setTimeout(window.applyPartsColumnWidths, 100); + } + return; + } - // 4) inserisci header prima di "Azioni" (ultima colonna) - $theadRow - .find("th:last") - .before( - `${partsExtraField.field_label}`, - ); + // 4) inserisci header propagabile prima di "Azioni" ultima colonna + $theadRow.find("th:last").before(buildExtraFieldHeaderHtml()); - // 5) aggiungi cella a ogni riga già presente (una sola volta) + // 5) aggiungi cella a ogni riga già presente $("#partsTableBody tr").each(function () { const $row = $(this); $row.find("td:last").before(buildExtraFieldCellHtml($row)); @@ -225,6 +355,33 @@ $(document).ready(function () { }); initializeExtraFieldSelect2($("#partsTableBody")); + + // Select2 anche sul campo di propagazione in testata + if ( + (partsExtraField.data_type || "").toLowerCase() === "sceltamultipla" + ) { + const $headerSelect = $( + "#partsTable thead .extra-propagate-select", + ); + + if ($headerSelect.length && typeof $.fn.select2 !== "undefined") { + if ($headerSelect.hasClass("select2-hidden-accessible")) { + $headerSelect.select2("destroy"); + } + + $headerSelect.select2({ + placeholder: "Select…", + allowClear: true, + width: "100%", + dropdownParent: $("#partsModal"), + minimumResultsForSearch: 0, + }); + } + } + + if (typeof window.applyPartsColumnWidths === "function") { + setTimeout(window.applyPartsColumnWidths, 100); + } } function setPartId($row, id) { @@ -971,7 +1128,7 @@ $(document).ready(function () { // Raccogli tutti i dati della riga per evitare sovrascritture const partNumber = $row.find(".part-number").val(); const partDescription = $row.find(".part-description").val().trim(); - const mix = partDescription.startsWith("Mix") ? "Y" : "N"; + const mix = getRowMix($row); const idmatrice = $row.find(".part-matrice").val() || null; const dateexpiry = $row.find(".part-dateexpiry").val() || null; @@ -1070,7 +1227,7 @@ $(document).ready(function () { // Raccogli tutti i dati della riga per evitare sovrascritture const partNumber = $row.find(".part-number").val(); const partDescription = $row.find(".part-description").val().trim(); - const mix = partDescription.startsWith("Mix") ? "Y" : "N"; + const mix = getRowMix($row); const idmatrice = $row.find(".part-matrice").val() || null; const note = $row.data("note") || null; @@ -1440,6 +1597,19 @@ $(document).ready(function () { ); } + if ( + part.extra_value_text !== undefined && + part.extra_value_text !== null + ) { + $row.data( + "extra-value-text", + part.extra_value_text, + ); + $row.find(".part-extra-field").val( + part.extra_value_text, + ); + } + initializeExtraFieldSelect2($row); const $select = $("#partsTableBody").find( @@ -2481,7 +2651,7 @@ $(document).on("click", "#showHideImageBtn", function () { // =================== (function () { // Larghezze default per indice colonna (0-based) - const defaultWidths = [55, 320, 360, 150, 230]; + const defaultWidths = [55, 320, 360, 150, 220, 230]; const savedWidths = [...defaultWidths]; function getColgroup() {