fixed disegno jump

This commit is contained in:
2026-10-23 20:34:55 +02:00
parent 128e229578
commit 341894cd22
+66 -10
View File
@@ -1271,7 +1271,12 @@ function revisionLabel($rev)
}
function loadExistingAttachments(idmatrice) {
$("#existingAttachmentsList").html('<div class="empty-attachments">Caricamento file...</div>');
const $attList = $("#existingAttachmentsList");
const keepScroll = $attList.scrollTop();
// mostro "Caricamento" solo se la lista è vuota, altrimenti lascio i file visibili finché arrivano i nuovi
if (!$attList.find('.attachment-existing-row').length) {
$attList.html('<div class="empty-attachments">Caricamento file...</div>');
}
fetch("get_matrice_attachments.php?id=" + encodeURIComponent(idmatrice))
.then(r => r.json())
@@ -1385,12 +1390,61 @@ function revisionLabel($rev)
`;
container.append(html);
});
$attList.scrollTop(keepScroll);
})
.catch(() => {
$("#existingAttachmentsList").html('<div class="empty-attachments">Errore nel caricamento dei file</div>');
});
}
// Aggiorna solo la riga dell'allegato dopo un cambio di flag, senza ricaricare la lista
const ATT_FLAGS = {
is_disegno: {
rowClass: 'is-disegno',
badge: '<span class="badge-disegno"><i class="fa-solid fa-compass-drafting"></i> Disegno tecnico</span>',
titleOn: 'Togli da disegni tecnici',
titleOff: 'Segna come disegno tecnico'
},
is_strumento: {
rowClass: 'is-strumento',
badge: '<span class="badge-strumento"><i class="fa-solid fa-screwdriver-wrench"></i> Strumento di lavoro</span>',
titleOn: 'Togli da strumenti di lavoro',
titleOff: 'Segna come strumento di lavoro'
},
is_ciclo: {
rowClass: 'is-ciclo',
badge: '<span class="badge-ciclo"><i class="fa-solid fa-arrows-rotate"></i> Ciclo di lavoro</span>',
titleOn: 'Togli da cicli di lavoro',
titleOff: 'Segna come ciclo di lavoro'
}
};
function applyAttachmentFlag($btn, field, value) {
const cfg = ATT_FLAGS[field];
if (!cfg) return;
const on = value === 1;
const $row = $btn.closest('.attachment-existing-row');
// pulsante
$btn.data('value', value).attr('data-value', value)
.toggleClass('active', on)
.attr('title', on ? cfg.titleOn : cfg.titleOff);
// bordo/colore della riga
$row.toggleClass(cfg.rowClass, on);
// badge accanto al nome, sempre nello stesso ordine
const $title = $row.find('.attachment-meta-title');
$title.find('.badge-disegno, .badge-strumento, .badge-ciclo').remove();
['is_disegno', 'is_strumento', 'is_ciclo'].forEach(f => {
if ($row.hasClass(ATT_FLAGS[f].rowClass)) {
$title.append(' ' + ATT_FLAGS[f].badge);
}
});
}
function openFilePreview(filePath, fileName) {
const ext = getFileExt(fileName);
$("#filePreviewTitle").text(fileName || 'Anteprima file');
@@ -2024,7 +2078,6 @@ function revisionLabel($rev)
const $btn = $(this);
const id = $btn.data("id");
const newValue = parseInt($btn.data("value"), 10) === 1 ? 0 : 1;
const idmatrice = $("#mf_idmatrice").val();
$btn.prop("disabled", true);
@@ -2037,16 +2090,19 @@ function revisionLabel($rev)
})
.then(r => r.json())
.then(data => {
$btn.prop("disabled", false);
if (!data.success) {
Swal.fire({
icon: "error",
title: "Errore",
text: data.message || ""
});
$btn.prop("disabled", false);
return;
}
applyAttachmentFlag($btn, 'is_disegno', newValue);
Swal.fire({
toast: true,
position: "top-end",
@@ -2055,16 +2111,14 @@ function revisionLabel($rev)
showConfirmButton: false,
timer: 1500
});
loadExistingAttachments(idmatrice);
})
.catch(() => {
$btn.prop("disabled", false);
Swal.fire({
icon: "error",
title: "Errore",
text: "Errore di comunicazione con il server"
});
$btn.prop("disabled", false);
});
});
@@ -2073,7 +2127,6 @@ function revisionLabel($rev)
const id = $btn.data("id");
const field = $btn.data("field");
const newValue = parseInt($btn.data("value"), 10) === 1 ? 0 : 1;
const idmatrice = $("#mf_idmatrice").val();
$btn.prop("disabled", true);
@@ -2088,15 +2141,19 @@ function revisionLabel($rev)
})
.then(r => r.json())
.then(data => {
$btn.prop("disabled", false);
if (!data.success) {
Swal.fire({
icon: "error",
title: "Errore",
text: data.message || ""
});
$btn.prop("disabled", false);
return;
}
applyAttachmentFlag($btn, field, newValue);
Swal.fire({
toast: true,
position: "top-end",
@@ -2105,15 +2162,14 @@ function revisionLabel($rev)
showConfirmButton: false,
timer: 1500
});
loadExistingAttachments(idmatrice);
})
.catch(() => {
$btn.prop("disabled", false);
Swal.fire({
icon: "error",
title: "Errore",
text: "Errore di comunicazione con il server"
});
$btn.prop("disabled", false);
});
});