fixed capitolato riferimento
This commit is contained in:
+191
-21
@@ -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 = [`<option value="">Select…</option>`]
|
||||
.concat(
|
||||
extraFieldOptions.map(
|
||||
(o) =>
|
||||
`<option value="${o.id}" ${String(o.id) === String(selectedValueId) ? "selected" : ""}>${o.label}</option>`,
|
||||
),
|
||||
)
|
||||
.join("");
|
||||
|
||||
return `
|
||||
<td class="extra-field-td" style="width:200px;">
|
||||
<input type="hidden" class="part-extra-field-id" value="${partsExtraField.field_id}">
|
||||
<input type="hidden" class="part-extra-value-id" value="${selectedValueId || ""}">
|
||||
<select class="form-control form-control-sm part-extra-select" data-selected="${selectedValueId || ""}">${opts}</select>
|
||||
</td>`;
|
||||
}
|
||||
|
||||
// Testo -> input + hidden field_id
|
||||
return `
|
||||
<td class="extra-field-td" style="width:200px;">
|
||||
<input type="hidden" class="part-extra-field-id" value="${partsExtraField.field_id}">
|
||||
<input type="text" class="form-control form-control-sm part-extra-field" data-type="${partsExtraField.data_type || ""}" value="${selectedValueText || ""}">
|
||||
</td>`;
|
||||
}
|
||||
|
||||
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 `
|
||||
<td class="extra-field-td" style="width:200px;">
|
||||
<input type="hidden" class="part-extra-field-id" value="${partsExtraField.field_id}">
|
||||
<input type="hidden" class="part-extra-value-id" value="">
|
||||
<select class="form-control form-control-sm part-extra-select" data-selected="${selectedValueId || ""}">${opts}</select>
|
||||
</td>`;
|
||||
<th class="extra-field-th">
|
||||
<div class="extra-propagate-wrapper">
|
||||
<div class="extra-propagate-label" title="${label}">
|
||||
${label}
|
||||
</div>
|
||||
<div class="extra-propagate-control">
|
||||
<select class="form-control form-control-sm extra-propagate-select">
|
||||
${opts}
|
||||
</select>
|
||||
<button type="button" class="btn btn-primary btn-sm extra-propagate-btn" title="Propaga a tutte le parti">
|
||||
<i class="fas fa-arrow-down"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</th>`;
|
||||
}
|
||||
|
||||
// Testo -> input + hidden field_id
|
||||
// Campo testo: titolo sopra, input + bottone sotto
|
||||
return `
|
||||
<td class="extra-field-td" style="width:200px;">
|
||||
<input type="hidden" class="part-extra-field-id" value="${partsExtraField.field_id}">
|
||||
<input type="text" class="form-control form-control-sm part-extra-field" data-type="${partsExtraField.data_type || ""}">
|
||||
</td>`;
|
||||
<th class="extra-field-th">
|
||||
<div class="extra-propagate-wrapper">
|
||||
<div class="extra-propagate-label" title="${label}">
|
||||
${label}
|
||||
</div>
|
||||
<div class="extra-propagate-control">
|
||||
<input type="text" class="form-control form-control-sm extra-propagate-input" placeholder="Value">
|
||||
<button type="button" class="btn btn-primary btn-sm extra-propagate-btn" title="Propaga a tutte le parti">
|
||||
<i class="fas fa-arrow-down"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</th>`;
|
||||
}
|
||||
|
||||
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 = $(
|
||||
'<div class="alert alert-warning temp-alert" role="alert">Seleziona un valore da propagare.</div>',
|
||||
);
|
||||
$("#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 = $(
|
||||
'<div class="alert alert-warning temp-alert" role="alert">Inserisci un valore da propagare.</div>',
|
||||
);
|
||||
$("#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(
|
||||
`<th class="extra-field-th" style="width:200px;">${partsExtraField.field_label}</th>`,
|
||||
);
|
||||
// 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() {
|
||||
|
||||
Reference in New Issue
Block a user