sample unlock date time copy paste on arrival

This commit is contained in:
2026-07-22 08:47:59 +02:00
parent bd9bd52c10
commit 48d775f4d5
+54
View File
@@ -1225,6 +1225,59 @@
function attachEvents() {
if (!rowContainer) return;
// ── Auto-copy: Sample Arrival date/time → Unlock date/time ──────────
// Coppie basate sui fieldId dei campi (source → target)
const AUTO_COPY_FIELD_PAIRS = [
{ from: 259, to: 260 }, // Sample Arrival date → Unlock Date
{ from: 348, to: 349 }, // Sample Arrival time → Unlock time
];
// Risolve fieldId → col.key (mapping id) usando le definizioni colonne
function colKeyByFieldId(fieldId) {
const col = columns.find(
(c) =>
(c.type === "detail" || c.type === "main_field") &&
String(c.fieldId) === String(fieldId),
);
return col ? String(col.key) : null;
}
// Precalcola le coppie come col.key (sourceKey → targetKey)
const AUTO_COPY_KEY_PAIRS = AUTO_COPY_FIELD_PAIRS.map((p) => ({
fromKey: colKeyByFieldId(p.from),
toKey: colKeyByFieldId(p.to),
})).filter((p) => p.fromKey && p.toKey);
function applyAutoCopy(rowIndex, changedColKey, value) {
const pair = AUTO_COPY_KEY_PAIRS.find(
(p) => p.fromKey === String(changedColKey),
);
if (!pair) return;
const row = data[rowIndex];
if (!row) return;
if (!row.details) row.details = {};
row.details[pair.toKey] = value;
row._dirty = true;
// Aggiorna la cella target visibile, se presente
const targetCell = rowContainer.querySelector(
`.grid-cell[data-row="${rowIndex}"][data-col="${pair.toKey}"]`,
);
if (targetCell) {
const input = targetCell.querySelector(".cell-input");
if (input) {
if ($(input).hasClass("select2-hidden-accessible")) {
$(input).val(value).trigger("change.select2");
} else {
input.value = value;
}
}
targetCell.classList.add("cell-changed");
}
}
// Cell value changes → write to gridData
rowContainer.addEventListener("change", function (e) {
const cell = e.target.closest(".grid-cell");
@@ -1239,6 +1292,7 @@
data[rowIndex].mainFieldValue = value;
}
setDetailValue(rowIndex, colKey, value);
applyAutoCopy(rowIndex, colKey, value);
} else if (colType === "fixed") {
setFixedValue(rowIndex, colKey, value);
} else if (colType === "idclient") {