added controller for QR photo upload and inserted route for it. added functional for multiple photo upload.

This commit is contained in:
2025-08-11 16:30:24 +04:00
parent 8978980901
commit 7ad20993d9
8 changed files with 174 additions and 53 deletions
+58 -28
View File
@@ -61,35 +61,19 @@ $(document).ready(function () {
method: "GET",
data: { iddatadb: iddatadb },
success: function (response) {
if (response.success && response.file_path) {
const img = $("#samplePhoto");
img.attr("src", response.file_path);
img.on("load", function () {
const container = img.parent();
const canvas = document.getElementById("photoCanvas");
const containerWidth = container.width();
const containerHeight = container.height();
const scaleX = containerWidth / img[0].naturalWidth;
const scaleY = containerHeight / img[0].naturalHeight;
const scale = Math.min(scaleX, scaleY);
canvas.width = img[0].naturalWidth * scale;
canvas.height = img[0].naturalHeight * scale;
canvas.style.width = `${containerWidth}px`;
canvas.style.height = `${containerHeight}px`;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.drawImage(
img.get(0),
0,
0,
canvas.width,
canvas.height,
);
updateMarkers();
});
if (response.success) {
if (response.photos && response.photos.length > 1) {
// Multiple photos available, create a selector
showPhotoSelector(response.photos);
} else if (response.photos && response.photos.length === 1) {
// Only one photo, load it directly
loadSinglePhoto(response.photos[0]);
} else {
$("#samplePhoto").attr("src", "");
alert("Nessuna foto trovata per questo TRF.");
}
} else {
$("#samplePhoto").attr("src", "");
alert("Nessuna foto trovata per questo TRF.");
alert(response.message || "Errore nel caricamento della foto.");
}
},
error: function (xhr, status, error) {
@@ -98,6 +82,52 @@ $(document).ready(function () {
});
}
function showPhotoSelector(photos) {
const selectorContainer = $("#photoSelectorContainer"); // A div to hold the photo selector
selectorContainer.empty(); // Clear any previous options
// Create a dropdown or buttons to select a photo
const selector = $('<select id="photoSelector"></select>');
photos.forEach((photo, index) => {
const option = $('<option></option>').val(photo).text(`Photo ${index + 1}`);
selector.append(option);
});
selector.on("change", function () {
const selectedPhoto = $(this).val();
loadSinglePhoto(selectedPhoto);
});
selectorContainer.append(selector);
selectorContainer.show(); // Make sure the selector is visible
}
function loadSinglePhoto(photoPath) {
const img = $("#samplePhoto");
img.attr("src", photoPath);
img.on("load", function () {
const container = img.parent();
const canvas = document.getElementById("photoCanvas");
const containerWidth = container.width();
const containerHeight = container.height();
const scaleX = containerWidth / img[0].naturalWidth;
const scaleY = containerHeight / img[0].naturalHeight;
const scale = Math.min(scaleX, scaleY);
canvas.width = img[0].naturalWidth * scale;
canvas.height = img[0].naturalHeight * scale;
canvas.style.width = `${containerWidth}px`;
canvas.style.height = `${containerHeight}px`;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.drawImage(img.get(0), 0, 0, canvas.width, canvas.height);
updateMarkers();
});
}
function addNewRow(nextPartNumber, isMix = false) {
const description = isMix ? "Mix" : "";
const newRow = `