added feature about unsaved changes

This commit is contained in:
Lasha Kapanadze 2025-08-20 16:49:10 +04:00
parent 939a4fe03e
commit 47762a8557
2 changed files with 62 additions and 7 deletions

View File

@ -145,4 +145,24 @@
padding: 0.1rem 0.3rem;
font-size: 0.8rem;
}
/* ნორმალური Save ღილაკი */
#savePhotoBtn {
transition: all 0.3s ease-in-out;
}
/* დაუმახსოვრებელი ცვლილებები */
#savePhotoBtn.unsaved {
background-color: #dc3545 !important; /* წითელი */
border-color: #dc3545 !important;
color: white !important;
animation: pulse 1.2s infinite;
}
/* ლამაზი პულსაცია */
@keyframes pulse {
0% { box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.7); }
70% { box-shadow: 0 0 10px 15px rgba(220, 53, 69, 0); }
100% { box-shadow: 0 0 0 0 rgba(220, 53, 69, 0); }
}
</style>

View File

@ -558,6 +558,41 @@ $(document).ready(function () {
clearCanvasMarkers();
});
let unsavedChanges = false;
// --- helper functions ---
function markUnsaved() {
if (!unsavedChanges) {
unsavedChanges = true;
$("#savePhotoBtn").addClass("unsaved").text("⚠️ Salva Modifiche");
}
}
function clearUnsaved() {
unsavedChanges = false;
$("#savePhotoBtn").removeClass("unsaved").text("Salva Foto con Nome");
}
// --- event listeners ---
// როცა ვცვლით input-ს ცხრილში
$(document).on("input change", "#partsTableBody input", markUnsaved);
// როცა ვამატებთ/ვშლით რიგს
$(document).on("click", ".add-row, .add-mix-row, .remove-row", markUnsaved);
// თუ გაქვს draggable marker ან description list
$(document).on("markerChanged descriptionChanged", markUnsaved);
// --- modal close protection ---
$('#partsModal').on('hide.bs.modal', function (e) {
if (unsavedChanges) {
if (!confirm("Hai modifiche non salvate. Vuoi davvero uscire?")) {
e.preventDefault();
}
}
});
// --- SAVE BUTTON ---
$("#savePhotoBtn").on("click", function () {
const canvas = document.getElementById("photoCanvas");
const ctx = canvas.getContext("2d");
@ -602,7 +637,7 @@ $(document).ready(function () {
// ლამაზი ბექგრაუნდი
ctx.fillStyle = "rgba(255, 255, 255, 0.9)";
ctx.beginPath();
ctx.roundRect(x, y, boxWidth, boxHeight, 12); // 🟢 Rounded corners
ctx.roundRect(x, y, boxWidth, boxHeight, 12);
ctx.fill();
ctx.restore();
@ -614,7 +649,6 @@ $(document).ready(function () {
});
}
// Markers
const currentPhoto = $("#samplePhoto").attr("src");
const markers = photoMarkers[currentPhoto] || [];
@ -642,7 +676,7 @@ $(document).ready(function () {
const dataURL = canvas.toDataURL("image/png");
const timestamp = new Date().toISOString().replace(/[:.]/g, "-");
const iddatadb = $("#partsModal").data("iddatadb"); // 🟢 ეს გადავაგზავნოთ
const iddatadb = $("#partsModal").data("iddatadb");
const defaultName = `photo_${iddatadb}_${timestamp}.png`;
const newName = prompt("Inserisci il nome del file (senza estensione):", defaultName.split(".png")[0]);
@ -655,15 +689,16 @@ $(document).ready(function () {
data: {
dataURL: dataURL,
filename: finalName,
iddatadb: iddatadb // 🟢 გადავცემთ PHP
iddatadb: iddatadb
},
success: function (response) {
if (response.success) {
alert("Foto salvata con successo: " + response.file_path);
// update photo list or refresh the modal
$("#samplePhoto").attr("src", response.file_path);
loadPhoto(iddatadb); // reload to update markers
clearCanvasMarkers(); // reset markers after save
loadPhoto(iddatadb);
clearCanvasMarkers();
clearUnsaved(); // ✅ reset unsaved status
} else {
alert("Errore: " + response.message);
}