added feature about unsaved changes
This commit is contained in:
@@ -145,4 +145,24 @@
|
|||||||
padding: 0.1rem 0.3rem;
|
padding: 0.1rem 0.3rem;
|
||||||
font-size: 0.8rem;
|
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>
|
</style>
|
||||||
|
|||||||
@@ -558,6 +558,41 @@ $(document).ready(function () {
|
|||||||
clearCanvasMarkers();
|
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 () {
|
$("#savePhotoBtn").on("click", function () {
|
||||||
const canvas = document.getElementById("photoCanvas");
|
const canvas = document.getElementById("photoCanvas");
|
||||||
const ctx = canvas.getContext("2d");
|
const ctx = canvas.getContext("2d");
|
||||||
@@ -602,7 +637,7 @@ $(document).ready(function () {
|
|||||||
// ლამაზი ბექგრაუნდი
|
// ლამაზი ბექგრაუნდი
|
||||||
ctx.fillStyle = "rgba(255, 255, 255, 0.9)";
|
ctx.fillStyle = "rgba(255, 255, 255, 0.9)";
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
ctx.roundRect(x, y, boxWidth, boxHeight, 12); // 🟢 Rounded corners
|
ctx.roundRect(x, y, boxWidth, boxHeight, 12);
|
||||||
ctx.fill();
|
ctx.fill();
|
||||||
|
|
||||||
ctx.restore();
|
ctx.restore();
|
||||||
@@ -614,7 +649,6 @@ $(document).ready(function () {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Markers
|
// Markers
|
||||||
const currentPhoto = $("#samplePhoto").attr("src");
|
const currentPhoto = $("#samplePhoto").attr("src");
|
||||||
const markers = photoMarkers[currentPhoto] || [];
|
const markers = photoMarkers[currentPhoto] || [];
|
||||||
@@ -642,7 +676,7 @@ $(document).ready(function () {
|
|||||||
|
|
||||||
const dataURL = canvas.toDataURL("image/png");
|
const dataURL = canvas.toDataURL("image/png");
|
||||||
const timestamp = new Date().toISOString().replace(/[:.]/g, "-");
|
const timestamp = new Date().toISOString().replace(/[:.]/g, "-");
|
||||||
const iddatadb = $("#partsModal").data("iddatadb"); // 🟢 ეს გადავაგზავნოთ
|
const iddatadb = $("#partsModal").data("iddatadb");
|
||||||
const defaultName = `photo_${iddatadb}_${timestamp}.png`;
|
const defaultName = `photo_${iddatadb}_${timestamp}.png`;
|
||||||
|
|
||||||
const newName = prompt("Inserisci il nome del file (senza estensione):", defaultName.split(".png")[0]);
|
const newName = prompt("Inserisci il nome del file (senza estensione):", defaultName.split(".png")[0]);
|
||||||
@@ -655,15 +689,16 @@ $(document).ready(function () {
|
|||||||
data: {
|
data: {
|
||||||
dataURL: dataURL,
|
dataURL: dataURL,
|
||||||
filename: finalName,
|
filename: finalName,
|
||||||
iddatadb: iddatadb // 🟢 გადავცემთ PHP–ს
|
iddatadb: iddatadb
|
||||||
},
|
},
|
||||||
success: function (response) {
|
success: function (response) {
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
alert("Foto salvata con successo: " + response.file_path);
|
alert("Foto salvata con successo: " + response.file_path);
|
||||||
// update photo list or refresh the modal
|
|
||||||
$("#samplePhoto").attr("src", response.file_path);
|
$("#samplePhoto").attr("src", response.file_path);
|
||||||
loadPhoto(iddatadb); // reload to update markers
|
loadPhoto(iddatadb);
|
||||||
clearCanvasMarkers(); // reset markers after save
|
clearCanvasMarkers();
|
||||||
|
|
||||||
|
clearUnsaved(); // ✅ reset unsaved status
|
||||||
} else {
|
} else {
|
||||||
alert("Errore: " + response.message);
|
alert("Errore: " + response.message);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user