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 @@ - - Mix + Rinumera Parti @@ -593,5 +592,130 @@ max-width: 100% !important; } + /* Propagation control for dynamic extra field column */ + #partsTable th.extra-field-th { + vertical-align: middle; + } + + #partsTable th.extra-field-th .extra-propagate-wrapper { + display: flex; + align-items: center; + gap: 4px; + width: 100%; + } + + #partsTable th.extra-field-th .extra-propagate-label { + font-size: 0.75rem; + font-weight: 600; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + max-width: 95px; + } + + #partsTable th.extra-field-th .extra-propagate-input, + #partsTable th.extra-field-th .extra-propagate-select { + height: 24px !important; + font-size: 0.75rem !important; + padding: 0.1rem 0.25rem !important; + min-width: 90px; + flex: 1 1 auto; + } + + #partsTable th.extra-field-th .extra-propagate-btn { + height: 24px; + min-width: 26px; + padding: 0.1rem 0.3rem !important; + font-size: 0.75rem !important; + flex: 0 0 auto; + } + + #partsTable th.extra-field-th .select2-container { + flex: 1 1 auto; + min-width: 90px; + max-width: 100% !important; + } + + #partsTable th.extra-field-th .select2-selection--single { + height: 24px !important; + } + + #partsTable th.extra-field-th .select2-selection__rendered { + line-height: 22px !important; + font-size: 0.75rem !important; + padding-left: 4px !important; + } + + #partsTable th.extra-field-th .select2-selection__arrow { + height: 22px !important; + } + + /* Extra field propagation header - full column width */ + #partsTable th.extra-field-th { + width: auto !important; + min-width: 220px !important; + max-width: none !important; + padding: 0.25rem !important; + } + + #partsTable .extra-propagate-wrapper { + width: 100% !important; + min-width: 100% !important; + max-width: 100% !important; + display: flex; + flex-direction: column; + gap: 4px; + box-sizing: border-box; + } + + #partsTable .extra-propagate-label { + width: 100% !important; + max-width: 100% !important; + display: block; + font-size: 0.82rem; + font-weight: 700; + line-height: 1.15; + color: #222; + white-space: nowrap !important; + overflow: visible !important; + text-overflow: unset !important; + text-align: center; + } + + #partsTable .extra-propagate-control { + width: 100% !important; + display: flex; + align-items: center; + gap: 5px; + box-sizing: border-box; + } + + #partsTable .extra-propagate-control .extra-propagate-input, + #partsTable .extra-propagate-control .extra-propagate-select { + flex: 1 1 auto !important; + width: 100% !important; + min-width: 0 !important; + max-width: none !important; + } + + #partsTable .extra-propagate-control .select2-container { + flex: 1 1 auto !important; + width: 100% !important; + min-width: 0 !important; + max-width: none !important; + } + + #partsTable .extra-propagate-control .select2-selection { + width: 100% !important; + } + + #partsTable .extra-propagate-btn { + flex: 0 0 30px !important; + width: 30px !important; + height: 24px !important; + min-width: 30px !important; + padding: 0.1rem 0.25rem !important; + } + /* rosso */ \ No newline at end of file diff --git a/public/userarea/partsTable.js b/public/userarea/partsTable.js index 7f5c6e8..f6fc697 100644 --- a/public/userarea/partsTable.js +++ b/public/userarea/partsTable.js @@ -107,8 +107,45 @@ $(document).ready(function () { if (!partsExtraField) return ""; const selectedValueId = $row ? $row.data("extra-value-id") || "" : ""; + const selectedValueText = $row + ? $row.data("extra-value-text") || "" + : ""; // SceltaMultipla -> select + hidden value id + if ( + (partsExtraField.data_type || "").toLowerCase() === "sceltamultipla" + ) { + const opts = [`Select…`] + .concat( + extraFieldOptions.map( + (o) => + `${o.label}`, + ), + ) + .join(""); + + return ` + + + + ${opts} + `; + } + + // Testo -> input + hidden field_id + return ` + + + + `; + } + + function buildExtraFieldHeaderHtml() { + if (!partsExtraField) return ""; + + const label = partsExtraField.field_label || "Extra"; + + // SceltaMultipla: titolo sopra, select + bottone sotto if ( (partsExtraField.data_type || "").toLowerCase() === "sceltamultipla" ) { @@ -121,19 +158,38 @@ $(document).ready(function () { .join(""); return ` - - - - ${opts} - `; + + + + ${label} + + + + ${opts} + + + + + + + `; } - // 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 = $( + 'Seleziona un valore da propagare.', + ); + $("#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 = $( + 'Inserisci un valore da propagare.', + ); + $("#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() {