added arrows to jump parts
This commit is contained in:
parent
198b8c08ad
commit
e8dd585df4
@ -350,6 +350,9 @@ $gridMeta = [
|
||||
<script>
|
||||
window.gridData = <?= json_encode($gridDataArray, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ?>;
|
||||
window.gridMeta = <?= json_encode($gridMeta, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ?>;
|
||||
|
||||
// Visible records in the current imported.php page
|
||||
window.visibleIddatadbList = window.gridData.map(row => parseInt(row.iddatadb, 10)).filter(Boolean);
|
||||
</script>
|
||||
|
||||
<!doctype html>
|
||||
|
||||
@ -2,7 +2,24 @@
|
||||
<div class="modal-dialog modal-xl" style="max-width: 95vw !important;">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="partsModalLabel">Parti per TRF: <span id="trfHeader"></span></h5>
|
||||
<h5 class="modal-title" id="partsModalLabel">
|
||||
Parti per TRF:
|
||||
<span id="trfHeader"></span>
|
||||
</h5>
|
||||
|
||||
<div class="ms-auto me-3 d-flex align-items-center gap-2">
|
||||
<button type="button" class="btn btn-outline-secondary btn-sm" id="prevPartsRecordBtn" title="Record precedente">
|
||||
<i class="fas fa-chevron-left"></i>
|
||||
</button>
|
||||
|
||||
<span id="partsRecordCounter" class="text-muted" style="font-size: 12px; min-width: 70px; text-align: center;">
|
||||
-
|
||||
</span>
|
||||
|
||||
<button type="button" class="btn btn-outline-secondary btn-sm" id="nextPartsRecordBtn" title="Record successivo">
|
||||
<i class="fas fa-chevron-right"></i>
|
||||
</button>
|
||||
</div>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
|
||||
@ -9,6 +9,7 @@ $(document).ready(function () {
|
||||
let quotations = [];
|
||||
let partsExtraField = null; // {field_id, field_label} oppure null
|
||||
let extraFieldOptions = []; // [{id,label}]
|
||||
let isLoadingPartsRecord = false;
|
||||
|
||||
// --- ROW ID helpers: niente più cache impazzita di jQuery .data() ---
|
||||
function getPartId($row) {
|
||||
@ -509,21 +510,175 @@ $(document).ready(function () {
|
||||
// MODAL HANDLING
|
||||
// ===================
|
||||
function loadParts(iddatadb, idquotations, callback = null) {
|
||||
isLoadingPartsRecord = true;
|
||||
unsavedChanges = false;
|
||||
|
||||
// Store current modal context
|
||||
$("#partsModal").data("iddatadb", iddatadb || null);
|
||||
$("#partsModal").data("idquotations", idquotations || null);
|
||||
|
||||
// Store the visible record list from the main grid
|
||||
if (Array.isArray(window.visibleIddatadbList)) {
|
||||
$("#partsModal").data(
|
||||
"visible-iddatadb-list",
|
||||
window.visibleIddatadbList,
|
||||
);
|
||||
}
|
||||
|
||||
updatePartsRecordHeader(iddatadb);
|
||||
|
||||
const finishLoading = function () {
|
||||
unsavedChanges = false;
|
||||
isLoadingPartsRecord = false;
|
||||
|
||||
if (callback) callback();
|
||||
};
|
||||
|
||||
if (iddatadb) {
|
||||
loadMacroMatrici();
|
||||
initializeGlobalSelect2();
|
||||
loadPartsExtraField(iddatadb, function () {
|
||||
loadPhoto(iddatadb, idquotations);
|
||||
loadExistingParts(iddatadb, idquotations, callback);
|
||||
loadExistingParts(iddatadb, idquotations, finishLoading);
|
||||
});
|
||||
} else {
|
||||
loadPartsExtraField(iddatadb, function () {
|
||||
loadPhoto(iddatadb, idquotations);
|
||||
loadExistingParts(iddatadb, idquotations, callback);
|
||||
loadExistingParts(iddatadb, idquotations, finishLoading);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// ===================
|
||||
// PARTS MODAL RECORD NAVIGATION
|
||||
// ===================
|
||||
|
||||
function getVisiblePartsRecordList() {
|
||||
const listFromModal = $("#partsModal").data("visible-iddatadb-list");
|
||||
|
||||
if (Array.isArray(listFromModal) && listFromModal.length > 0) {
|
||||
return listFromModal.map((v) => parseInt(v, 10)).filter(Boolean);
|
||||
}
|
||||
|
||||
if (
|
||||
Array.isArray(window.visibleIddatadbList) &&
|
||||
window.visibleIddatadbList.length > 0
|
||||
) {
|
||||
return window.visibleIddatadbList
|
||||
.map((v) => parseInt(v, 10))
|
||||
.filter(Boolean);
|
||||
}
|
||||
|
||||
if (Array.isArray(window.gridData) && window.gridData.length > 0) {
|
||||
return window.gridData
|
||||
.map((row) => parseInt(row.iddatadb, 10))
|
||||
.filter(Boolean);
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
function getGridRecordById(iddatadb) {
|
||||
if (!Array.isArray(window.gridData)) return null;
|
||||
|
||||
return (
|
||||
window.gridData.find((row) => {
|
||||
return parseInt(row.iddatadb, 10) === parseInt(iddatadb, 10);
|
||||
}) || null
|
||||
);
|
||||
}
|
||||
|
||||
function getRecordHeaderLabel(iddatadb) {
|
||||
const record = getGridRecordById(iddatadb);
|
||||
|
||||
if (!record) {
|
||||
return iddatadb ? "#" + iddatadb : "";
|
||||
}
|
||||
|
||||
// Prefer main field value if available
|
||||
if (record.mainFieldValue) {
|
||||
return record.mainFieldValue;
|
||||
}
|
||||
|
||||
// Fallbacks
|
||||
if (record.importreferencecode) {
|
||||
return record.importreferencecode;
|
||||
}
|
||||
|
||||
if (record.filename_import) {
|
||||
return record.filename_import;
|
||||
}
|
||||
|
||||
return "#" + iddatadb;
|
||||
}
|
||||
|
||||
function updatePartsRecordHeader(iddatadb) {
|
||||
const list = getVisiblePartsRecordList();
|
||||
const currentId = parseInt(iddatadb, 10);
|
||||
const currentIndex = list.indexOf(currentId);
|
||||
|
||||
$("#trfHeader").text(getRecordHeaderLabel(currentId));
|
||||
|
||||
if (list.length <= 1 || currentIndex === -1) {
|
||||
$("#partsRecordCounter").text("-");
|
||||
$("#prevPartsRecordBtn").prop("disabled", true);
|
||||
$("#nextPartsRecordBtn").prop("disabled", true);
|
||||
return;
|
||||
}
|
||||
|
||||
$("#partsRecordCounter").text(currentIndex + 1 + " / " + list.length);
|
||||
|
||||
$("#prevPartsRecordBtn").prop("disabled", currentIndex <= 0);
|
||||
$("#nextPartsRecordBtn").prop(
|
||||
"disabled",
|
||||
currentIndex >= list.length - 1,
|
||||
);
|
||||
}
|
||||
|
||||
function goToAdjacentPartsRecord(direction) {
|
||||
const list = getVisiblePartsRecordList();
|
||||
const currentId = parseInt($("#partsModal").data("iddatadb"), 10);
|
||||
const currentIndex = list.indexOf(currentId);
|
||||
|
||||
if (currentIndex === -1) return;
|
||||
|
||||
const nextIndex = currentIndex + direction;
|
||||
|
||||
if (nextIndex < 0 || nextIndex >= list.length) return;
|
||||
|
||||
if (
|
||||
!isLoadingPartsRecord &&
|
||||
unsavedChanges &&
|
||||
!confirm(
|
||||
"Hai modifiche non salvate. Vuoi cambiare record senza salvare?",
|
||||
)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
const nextIddatadb = list[nextIndex];
|
||||
|
||||
// Reset local modal state before loading the next record
|
||||
partMatrice = {};
|
||||
unsavedChanges = false;
|
||||
$("#partsTableBody").empty();
|
||||
$("#photoSelectorContainer").empty().hide();
|
||||
$("#samplePhoto").attr("src", "");
|
||||
$(".temp-alert").remove();
|
||||
|
||||
loadParts(nextIddatadb, null);
|
||||
}
|
||||
|
||||
$(document).on("click", "#prevPartsRecordBtn", function (e) {
|
||||
e.preventDefault();
|
||||
goToAdjacentPartsRecord(-1);
|
||||
});
|
||||
|
||||
$(document).on("click", "#nextPartsRecordBtn", function (e) {
|
||||
e.preventDefault();
|
||||
goToAdjacentPartsRecord(1);
|
||||
});
|
||||
|
||||
// EVENTO PER APRIRE IL SECONDO MODALE
|
||||
$(document).on("click", "#openAnnotationsBtn", function () {
|
||||
console.log("Clic su Apri Annotazioni...");
|
||||
@ -1090,7 +1245,10 @@ $(document).ready(function () {
|
||||
initializeExtraFieldSelect2($newRow);
|
||||
|
||||
updateRowButtons();
|
||||
markUnsaved();
|
||||
|
||||
if (!isLoadingPartsRecord) {
|
||||
markUnsaved();
|
||||
}
|
||||
}
|
||||
|
||||
// ===================
|
||||
@ -2142,6 +2300,8 @@ $(document).ready(function () {
|
||||
});
|
||||
|
||||
function markUnsaved() {
|
||||
if (isLoadingPartsRecord) return;
|
||||
|
||||
if (!unsavedChanges) {
|
||||
unsavedChanges = true;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user