From 48d775f4d576526b27eb8b679c5fa2bc17f1a086 Mon Sep 17 00:00:00 2001 From: solocla Date: Wed, 22 Jul 2026 08:47:59 +0200 Subject: [PATCH] sample unlock date time copy paste on arrival --- public/userarea/gridRenderer.js | 54 +++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/public/userarea/gridRenderer.js b/public/userarea/gridRenderer.js index bffa0fa..4dc6b97 100644 --- a/public/userarea/gridRenderer.js +++ b/public/userarea/gridRenderer.js @@ -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") {