Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6ec0c2062e | |||
| 03771e3ca8 |
@@ -18,10 +18,9 @@ $(document).ready(function () {
|
||||
let fabricCanvas = null;
|
||||
let descriptionTextbox = null;
|
||||
let markerObjects = {};
|
||||
let nextMarkerId = 1;
|
||||
let partsListData = [];
|
||||
// DIMENSIONE GLOBALE MARKER
|
||||
let globalMarkerSize = 16;
|
||||
let globalMarkerSize = 24;
|
||||
|
||||
// ===================
|
||||
// MODAL INITIALIZATION
|
||||
@@ -33,7 +32,7 @@ $(document).ready(function () {
|
||||
trfHeader,
|
||||
});
|
||||
|
||||
$("#annotationsModal").attr("data-iddatadb", iddatadb);
|
||||
$("#annotationsModal").attr('data-iddatadb', iddatadb);
|
||||
|
||||
if (!iddatadb && !idquotations) {
|
||||
const errorMsg = $(
|
||||
@@ -137,7 +136,7 @@ $(document).ready(function () {
|
||||
}
|
||||
descriptionTextbox = null;
|
||||
markerObjects = {};
|
||||
globalMarkerSize = 16;
|
||||
globalMarkerSize = 24;
|
||||
$("#photoSelectorContainerAnnotations").empty().hide();
|
||||
$("#samplePhotoAnnotations").attr("src", "");
|
||||
$("#partsListAnnotations").empty();
|
||||
@@ -160,20 +159,6 @@ $(document).ready(function () {
|
||||
.on("input", "#markerSizeSlider", function () {
|
||||
globalMarkerSize = parseInt($(this).val());
|
||||
$("#markerSizeValue").text(globalMarkerSize + "px");
|
||||
|
||||
partsListData.forEach(function (part) {
|
||||
if (part && part.part_number != null) {
|
||||
partSizes[part.part_number] = globalMarkerSize;
|
||||
}
|
||||
});
|
||||
|
||||
$("#partsListAnnotations .marker-size-slider").val(
|
||||
globalMarkerSize,
|
||||
);
|
||||
$("#partsListAnnotations .marker-size-value").text(
|
||||
globalMarkerSize + "px",
|
||||
);
|
||||
|
||||
updateMarkers();
|
||||
markUnsaved();
|
||||
});
|
||||
@@ -381,13 +366,22 @@ $(document).ready(function () {
|
||||
|
||||
const partColor =
|
||||
partColors[selectedPartNumber] || "#ff0000";
|
||||
const existingMarker = photoAnnotations[
|
||||
currentPhoto
|
||||
].markers.find((m) => m.partNumber == selectedPartNumber);
|
||||
|
||||
if (existingMarker) {
|
||||
existingMarker.x = x;
|
||||
existingMarker.y = y;
|
||||
existingMarker.color = partColor;
|
||||
} else {
|
||||
photoAnnotations[currentPhoto].markers.push({
|
||||
id: nextMarkerId++,
|
||||
partNumber: selectedPartNumber,
|
||||
x,
|
||||
y,
|
||||
color: partColor,
|
||||
});
|
||||
}
|
||||
|
||||
console.log("Marker aggiunto/spostato:", {
|
||||
partNumber: selectedPartNumber,
|
||||
@@ -397,6 +391,8 @@ $(document).ready(function () {
|
||||
});
|
||||
updateMarkers();
|
||||
markUnsaved();
|
||||
selectedPartNumber = null;
|
||||
$("#partsListAnnotations li").removeClass("active");
|
||||
});
|
||||
|
||||
fabricCanvas.upperCanvasEl.focus();
|
||||
@@ -554,14 +550,9 @@ $(document).ready(function () {
|
||||
});
|
||||
modal.show();
|
||||
} else {
|
||||
let iddatadb =
|
||||
$("#annotationsModal").attr("data-iddatadb");
|
||||
let iddatadb = $("#annotationsModal").attr('data-iddatadb');
|
||||
|
||||
$(
|
||||
"button.parts-btn[data-iddatadb='" +
|
||||
iddatadb +
|
||||
"']",
|
||||
).trigger("click");
|
||||
$("button.parts-btn[data-iddatadb='" + iddatadb + "']").trigger('click');
|
||||
}
|
||||
},
|
||||
).fail(function (xhr) {
|
||||
@@ -669,21 +660,8 @@ $(document).ready(function () {
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const $listItem = $(this);
|
||||
const partNumber = $listItem.data("part-number");
|
||||
|
||||
if (
|
||||
selectedPartNumber == partNumber &&
|
||||
$listItem.hasClass("active")
|
||||
) {
|
||||
selectedPartNumber = null;
|
||||
$listItem.removeClass("active");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
selectedPartNumber = partNumber;
|
||||
selectedPartNumber = $listItem.data("part-number");
|
||||
$listItem.addClass("active").siblings().removeClass("active");
|
||||
console.log(
|
||||
"Parte selezionata tramite riga:",
|
||||
@@ -733,23 +711,12 @@ $(document).ready(function () {
|
||||
.find(".selected-color")
|
||||
.css("background-color", color);
|
||||
|
||||
let currentPhoto = $("#samplePhotoAnnotations").attr("src");
|
||||
let annotations = photoAnnotations[currentPhoto];
|
||||
|
||||
if (annotations) {
|
||||
annotations.markers.forEach(function (m) {
|
||||
if (m.partNumber == partNumber) {
|
||||
m.color = color;
|
||||
let group = markerObjects[m.id];
|
||||
|
||||
if (group) {
|
||||
let circle = group.item(0);
|
||||
|
||||
// Se il marker è già presente, aggiorna anche sul canvas
|
||||
if (markerObjects[partNumber]) {
|
||||
const group = markerObjects[partNumber];
|
||||
const circle = group.item(0); // il cerchio
|
||||
circle.set("fill", color);
|
||||
circle.set("stroke", color);
|
||||
}
|
||||
}
|
||||
});
|
||||
fabricCanvas.renderAll();
|
||||
}
|
||||
|
||||
@@ -937,9 +904,9 @@ $(document).ready(function () {
|
||||
"updateMarkers chiamato, markerObjects:",
|
||||
Object.keys(markerObjects),
|
||||
);
|
||||
for (let markerId in markerObjects) {
|
||||
fabricCanvas.remove(markerObjects[markerId]);
|
||||
delete markerObjects[markerId];
|
||||
for (let partNumber in markerObjects) {
|
||||
fabricCanvas.remove(markerObjects[partNumber]);
|
||||
delete markerObjects[partNumber];
|
||||
}
|
||||
markerObjects = {};
|
||||
|
||||
@@ -1020,9 +987,6 @@ $(document).ready(function () {
|
||||
lockRotation: true,
|
||||
});
|
||||
|
||||
group.markerId = marker.id;
|
||||
group.partNumber = marker.partNumber;
|
||||
|
||||
group.on("moving", function () {
|
||||
marker.x = this.left / photoData.scale;
|
||||
marker.y = this.top / photoData.scale;
|
||||
@@ -1035,7 +999,7 @@ $(document).ready(function () {
|
||||
});
|
||||
|
||||
fabricCanvas.add(group);
|
||||
markerObjects[marker.id] = group;
|
||||
markerObjects[marker.partNumber] = group;
|
||||
});
|
||||
|
||||
fabricCanvas.renderAll();
|
||||
@@ -1189,9 +1153,9 @@ $(document).ready(function () {
|
||||
}
|
||||
}
|
||||
|
||||
for (let markerId in markerObjects) {
|
||||
fabricCanvas.remove(markerObjects[markerId]);
|
||||
delete markerObjects[markerId];
|
||||
for (let partNumber in markerObjects) {
|
||||
fabricCanvas.remove(markerObjects[partNumber]);
|
||||
delete markerObjects[partNumber];
|
||||
}
|
||||
markerObjects = {};
|
||||
|
||||
@@ -1226,9 +1190,9 @@ $(document).ready(function () {
|
||||
photoAnnotations[currentPhoto].markers.length > 0
|
||||
) {
|
||||
const lastMarker = photoAnnotations[currentPhoto].markers.pop();
|
||||
if (markerObjects[lastMarker.id]) {
|
||||
fabricCanvas.remove(markerObjects[lastMarker.id]);
|
||||
delete markerObjects[lastMarker.id];
|
||||
if (markerObjects[lastMarker.partNumber]) {
|
||||
fabricCanvas.remove(markerObjects[lastMarker.partNumber]);
|
||||
delete markerObjects[lastMarker.partNumber];
|
||||
fabricCanvas.renderAll();
|
||||
}
|
||||
console.log("Ultimo marker rimosso:", lastMarker);
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
|
||||
include('include/headscript.php');
|
||||
|
||||
$dbHandler = DBHandlerSelect::getInstance();
|
||||
$pdo = $dbHandler->getConnection();
|
||||
|
||||
// Recupera l'ID dell'utente loggato
|
||||
$user_id = $iduserlogin ?? 1;
|
||||
|
||||
if (!$user_id) {
|
||||
echo json_encode(['success' => false, 'message' => "ID dell'utente autenticato mancante"]);
|
||||
exit;
|
||||
}
|
||||
|
||||
try {
|
||||
$stmt = $pdo->prepare(
|
||||
"SELECT DISTINCT q.*
|
||||
FROM quotations q
|
||||
INNER JOIN identification_parts ip
|
||||
ON ip.idquotations = q.id
|
||||
AND ip.iddatadb IS NULL
|
||||
WHERE q.iduser = :iduser"
|
||||
);
|
||||
$stmt->execute([':iduser' => $user_id]);
|
||||
$quotations = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
echo json_encode(['success' => true, 'quotations' => $quotations]);
|
||||
} catch (PDOException $e) {
|
||||
echo json_encode(['success' => false, 'message' => 'Errore nel caricamento delle quotations: ' . $e->getMessage()]);
|
||||
}
|
||||
@@ -8,7 +8,7 @@
|
||||
<!-- SLIDER PER DIMENSIONE MARKER -->
|
||||
<div style="display: flex; align-items: center; gap: 10px; margin-left: 20px;">
|
||||
<label for="markerSizeSlider" style="margin: 0; font-size: 0.9rem; white-space: nowrap;">Dimensione marker:</label>
|
||||
<input type="range" id="markerSizeSlider" min="16" max="48" value="16" step="2" style="width: 120px;">
|
||||
<input type="range" id="markerSizeSlider" min="16" max="48" value="24" step="2" style="width: 120px;">
|
||||
<span id="markerSizeValue" style="font-weight: bold; min-width: 30px;">24px</span>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
<div style="display: flex; align-items: center;">
|
||||
<button type="button" class="btn btn-info btn-sm" id="renumberPartsBtn" style="padding: 0.1rem 0.5rem; font-size: 0.8rem;">Rinumera Parti</button>
|
||||
<button type="button" class="btn btn-secondary btn-sm ms-2" id="toggleVoiceBtn" style="padding: 0.1rem 0.5rem; font-size: 0.8rem;"><i class="fas fa-microphone"></i> Voce</button>
|
||||
<button type="button" class="btn btn-info btn-sm ms-2 d-none" id="quotationeBtn" style="padding: 0.1rem 0.5rem; font-size: 0.8rem;">Add Quotation</button>
|
||||
<button type="button" class="btn btn-primary btn-sm ms-2" id="showHideImageBtn" style="padding: 0.1rem 0.5rem; font-size: 0.8rem;">
|
||||
<i class="fas fa-eye-slash" style="font-size: 0.8rem;"></i>
|
||||
<i class="fas fa-image ms-1" style="font-size: 0.8rem;"></i>
|
||||
@@ -145,6 +146,24 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Finestra modale "Aggiungi preventivo" -->
|
||||
<div class="modal fade" id="addQuotationModal" tabindex="-1" aria-labelledby="addQuotationModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-md">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="addQuotationModalLabel">Choose a quotation</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<select id="addQuotationSelect" class="form-control form-control-sm" style="width: 100% !important; min-width: 100% !important"></select>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary btn-sm" data-bs-dismiss="modal">Annulla</button>
|
||||
<button type="button" class="btn btn-primary btn-sm" id="addQuotationBtn">Confirm</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
/* --- Base --- */
|
||||
@@ -161,6 +180,14 @@
|
||||
max-width: 100% !important
|
||||
}
|
||||
|
||||
#addQuotationModal {
|
||||
z-index: 1060 !important
|
||||
}
|
||||
|
||||
#addQuotationModal .modal-backdrop {
|
||||
z-index: 1055 !important
|
||||
}
|
||||
|
||||
/* Tabelle */
|
||||
#partsTable tr {
|
||||
display: table-row !important
|
||||
|
||||
@@ -6,6 +6,7 @@ $(document).ready(function () {
|
||||
let unsavedChanges = false;
|
||||
let matrici = [];
|
||||
let macroMatrici = [];
|
||||
let quotations = [];
|
||||
|
||||
// --- ROW ID helpers: niente più cache impazzita di jQuery .data() ---
|
||||
function getPartId($row) {
|
||||
@@ -141,7 +142,7 @@ $(document).ready(function () {
|
||||
// ===================
|
||||
// MODAL HANDLING
|
||||
// ===================
|
||||
function loadParts(iddatadb, idquotations) {
|
||||
function loadParts(iddatadb, idquotations, callback = null) {
|
||||
if (iddatadb) {
|
||||
if (matrici.length === 0) {
|
||||
$.ajax({
|
||||
@@ -153,14 +154,14 @@ $(document).ready(function () {
|
||||
loadMacroMatrici();
|
||||
initializeGlobalSelect2();
|
||||
loadPhoto(iddatadb, idquotations);
|
||||
loadExistingParts(iddatadb, idquotations);
|
||||
loadExistingParts(iddatadb, idquotations, callback);
|
||||
},
|
||||
error: function (xhr, status, error) {
|
||||
matrici = [];
|
||||
loadMacroMatrici();
|
||||
initializeGlobalSelect2();
|
||||
loadPhoto(iddatadb, idquotations);
|
||||
loadExistingParts(iddatadb, idquotations);
|
||||
loadExistingParts(iddatadb, idquotations, callback);
|
||||
const errorMsg = $(
|
||||
'<div class="alert alert-danger temp-alert" role="alert">Errore nel caricamento delle matrici: ' +
|
||||
error +
|
||||
@@ -180,11 +181,11 @@ $(document).ready(function () {
|
||||
loadMacroMatrici();
|
||||
initializeGlobalSelect2();
|
||||
loadPhoto(iddatadb, idquotations);
|
||||
loadExistingParts(iddatadb, idquotations);
|
||||
loadExistingParts(iddatadb, idquotations, callback);
|
||||
}
|
||||
} else {
|
||||
loadPhoto(iddatadb, idquotations);
|
||||
loadExistingParts(iddatadb, idquotations);
|
||||
loadExistingParts(iddatadb, idquotations, callback);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -589,6 +590,8 @@ $(document).ready(function () {
|
||||
if (response.success) {
|
||||
$saveStatus.show();
|
||||
setTimeout(() => $saveStatus.hide(), 2000);
|
||||
|
||||
if (!$("#quotationeBtn").hasClass('d-none')) $("#quotationeBtn").addClass("d-none");
|
||||
} else {
|
||||
const errorMsg = $(
|
||||
'<div class="alert alert-danger temp-alert" role="alert">Errore nel salvataggio: ' +
|
||||
@@ -1155,7 +1158,7 @@ $(document).ready(function () {
|
||||
saveRow($(this).closest("tr"));
|
||||
});
|
||||
|
||||
function loadExistingParts(iddatadb, idquotations) {
|
||||
function loadExistingParts(iddatadb, idquotations, callback = null) {
|
||||
const endpoint = idquotations
|
||||
? "load_parts_quotation.php"
|
||||
: "load_parts.php";
|
||||
@@ -1233,8 +1236,11 @@ $(document).ready(function () {
|
||||
});
|
||||
} else {
|
||||
addNewRow(1, false); // Riga iniziale normale
|
||||
$("#quotationeBtn").removeClass("d-none");
|
||||
}
|
||||
updateRowButtons();
|
||||
|
||||
if (callback) callback();
|
||||
},
|
||||
error: function (xhr, status, error) {
|
||||
const errorMsg = $(
|
||||
@@ -1787,6 +1793,122 @@ $(document).ready(function () {
|
||||
|
||||
// Esporta la funzione loadParts per essere usata da import_Edit2.php
|
||||
window.loadParts = loadParts;
|
||||
|
||||
$(document).on("click", "#quotationeBtn", function () {
|
||||
$("#addQuotationModal").modal("show");
|
||||
|
||||
if (quotations.length > 0) {
|
||||
reloadQuotations();
|
||||
} else {
|
||||
$.ajax({
|
||||
url: "load_quotations.php",
|
||||
method: "GET",
|
||||
success: function (response) {
|
||||
quotations = response?.quotations || [];
|
||||
|
||||
reloadQuotations();
|
||||
},
|
||||
error: function (xhr, status, error) {
|
||||
console.error("Errore AJAX caricamento quotations:", error, xhr.responseText);
|
||||
let message = `
|
||||
<div class="alert alert-danger temp-alert" role="alert">
|
||||
Errore nel caricamento delle quotations: ${error} (${xhr.status})
|
||||
</div>
|
||||
`;
|
||||
|
||||
$("#partsModal .modal-body").prepend(errorMsg);
|
||||
|
||||
setTimeout(function () {
|
||||
message.fadeOut(500, function () {
|
||||
$(this).remove();
|
||||
});
|
||||
}, 5000);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$(document).on("click", "#addQuotationBtn", function () {
|
||||
const quotationId = $("#addQuotationSelect").val();
|
||||
|
||||
if (quotationId && confirm("Confermo di collegare la quotazione al campione?")) {
|
||||
$("#addQuotationModal").modal("hide");
|
||||
|
||||
loadParts(null, quotationId, () => {
|
||||
$("#quotationeBtn").addClass("d-none");
|
||||
|
||||
setTimeout(() => {
|
||||
$("#partsTableBody tr").each(function () {
|
||||
$(this).find(".save-loading").show();
|
||||
});
|
||||
|
||||
let photoList = $('#photoSelector option').map(function () {
|
||||
return this.value?.split('/')?.pop();
|
||||
}).get();
|
||||
|
||||
if (!photoList.length) {
|
||||
let path = $('#samplePhoto').attr("src")?.split('/')?.pop();
|
||||
|
||||
if (path) photoList = [path];
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: "save_parts_photo_iddatadb.php",
|
||||
method: "POST",
|
||||
data: JSON.stringify({
|
||||
iddatadb: $("#partsModal").data("iddatadb"),
|
||||
photoList,
|
||||
partIds: $('#partsTableBody tr').map(function () {
|
||||
return $(this).data("part-id");
|
||||
}).get(),
|
||||
}),
|
||||
success: function () {
|
||||
$("#partsTableBody tr").each(function () {
|
||||
let $row = $(this);
|
||||
let $saveStatus = $row.find(".save-status");
|
||||
let $saveLoading = $row.find(".save-loading");
|
||||
|
||||
$saveLoading.hide();
|
||||
$saveStatus.show();
|
||||
|
||||
setTimeout(() => $saveStatus.hide(), 2000);
|
||||
});
|
||||
}, error: function (xhr, status, error) {
|
||||
let message = `
|
||||
<div class="alert alert-danger temp-alert" role="alert">
|
||||
Errore di salvataggio: ${error} (${xhr.status})
|
||||
</div>
|
||||
`;
|
||||
|
||||
$("#partsModal .modal-body").prepend(message);
|
||||
|
||||
setTimeout(function () {
|
||||
message.fadeOut(500, function () {
|
||||
$(this).remove();
|
||||
});
|
||||
}, 5000);
|
||||
}
|
||||
});
|
||||
}, 100);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function reloadQuotations() {
|
||||
if (quotations.length > 0) {
|
||||
$("#addQuotationSelect").empty();
|
||||
|
||||
$("#addQuotationSelect").append("<option value=''>Seleziona Quotation</option>");
|
||||
|
||||
quotations.forEach(quotation => {
|
||||
if (quotation?.description) {
|
||||
$("#addQuotationSelect").append(`<option value='${quotation?.id}'>${quotation?.description}</option>`);
|
||||
}
|
||||
});
|
||||
|
||||
$("#addQuotationSelect").select2();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$(document).on("change", ".propagate-date-input", function () {
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
include('include/headscript.php');
|
||||
|
||||
$dbHandler = DBHandlerSelect::getInstance();
|
||||
$pdo = $dbHandler->getConnection();
|
||||
|
||||
$data = json_decode(file_get_contents('php://input'), true);
|
||||
|
||||
$iddatadb = $data['iddatadb'] ?? null;
|
||||
$partIds = $data['partIds'] ?? [];
|
||||
$photoList = $data['photoList'] ?? null;
|
||||
|
||||
if ($iddatadb) {
|
||||
if (count($partIds) != 0) {
|
||||
$idList = array_values(array_map('intval', $partIds));
|
||||
$placeholders = [];
|
||||
$parameters = [':iddatadb' => $iddatadb];
|
||||
|
||||
foreach ($idList as $index => $id) {
|
||||
$paramName = ":id{$index}";
|
||||
$placeholders[] = $paramName;
|
||||
$parameters[$paramName] = $id;
|
||||
}
|
||||
|
||||
$sql = 'UPDATE identification_parts SET iddatadb = :iddatadb WHERE id IN (' . implode(',', $placeholders) . ')';
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute($parameters);
|
||||
}
|
||||
|
||||
if (count($photoList) != 0) {
|
||||
$placeholders = [];
|
||||
$parameters = [':iddatadb' => $iddatadb];
|
||||
|
||||
foreach ($photoList as $index => $photo) {
|
||||
$paramName = ":photo{$index}";
|
||||
$placeholders[] = $paramName;
|
||||
$parameters[$paramName] = $photo;
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare('UPDATE datadb_photos SET iddatadb = :iddatadb WHERE file_path IN (' . implode(',', $placeholders) . ')');
|
||||
$stmt->execute($parameters);
|
||||
}
|
||||
|
||||
echo json_encode(['success' => true, 'message' => '']);
|
||||
} else {
|
||||
echo json_encode(['success' => false, 'message' => 'Dati mancanti']);
|
||||
}
|
||||
Reference in New Issue
Block a user