From ef40e60d6eca9a86520a74f44eacfe3ba8bc0f5f Mon Sep 17 00:00:00 2001 From: Frank Cools Date: Mon, 6 Oct 2025 17:56:47 +0200 Subject: [PATCH] Replace standard JavaScript confirm with Dolibarr-style modal for unvalidation - Replaced onclick='return confirm()' with onclick='confirmUnvalidation()' - Added confirmUnvalidation() JavaScript function with Dolibarr-style modal - Added closeUnvalidationModal() and proceedUnvalidation() functions - Modal has red warning styling to indicate destructive action - Added UnvalidationConfirmationMessage and YesUnvalidate translations - Modal includes escape key handler and proper styling - Consistent with validation modal design and behavior --- declarationtva_view.php | 73 ++++++++++++++++++++++++++++++++- langs/en_US/declarationtva.lang | 2 + langs/fr_FR/declarationtva.lang | 2 + 3 files changed, 76 insertions(+), 1 deletion(-) diff --git a/declarationtva_view.php b/declarationtva_view.php index 2c326d4..4ca0b31 100644 --- a/declarationtva_view.php +++ b/declarationtva_view.php @@ -479,7 +479,7 @@ if ($declarationtva->status == 'draft') { } elseif ($declarationtva->status == 'validated') { print '' . $langs->trans("Submit") . ' '; // Add unvalidate button for testing - print '' . $langs->trans("Unvalidate") . ' '; + print '' . $langs->trans("Unvalidate") . ' '; } print '' . $langs->trans("BackToList") . ''; @@ -651,6 +651,77 @@ function proceedValidation(declarationId) { // Redirect to validation action window.location.href = "' . $_SERVER['PHP_SELF'] . '?id=" + declarationId + "&action=validate&token=' . newToken() . '"; } + +function confirmUnvalidation(declarationId) { + // Create a proper Dolibarr-style modal dialog for unvalidation + var dialog = document.createElement("div"); + dialog.id = "unvalidationModal"; + dialog.style.cssText = "position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.6); z-index: 10000; display: flex; align-items: center; justify-content: center; font-family: Arial, sans-serif;"; + + var dialogContent = document.createElement("div"); + dialogContent.style.cssText = "background: white; border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,0.3); max-width: 500px; width: 90%; max-height: 90%; overflow: hidden;"; + + // Header + var header = document.createElement("div"); + header.style.cssText = "background: #f8f9fa; padding: 20px; border-bottom: 1px solid #dee2e6; display: flex; align-items: center;"; + header.innerHTML = ` +
+

' . $langs->trans("ConfirmUnvalidate") . '

+
+ + `; + + // Body + var body = document.createElement("div"); + body.style.cssText = "padding: 20px;"; + body.innerHTML = ` +
+
+ ! +
+
+

' . $langs->trans("UnvalidationConfirmationMessage") . '

+
+
+ `; + + // Footer + var footer = document.createElement("div"); + footer.style.cssText = "background: #f8f9fa; padding: 15px 20px; border-top: 1px solid #dee2e6; display: flex; justify-content: flex-end; gap: 10px;"; + footer.innerHTML = ` + + + `; + + dialogContent.appendChild(header); + dialogContent.appendChild(body); + dialogContent.appendChild(footer); + dialog.appendChild(dialogContent); + document.body.appendChild(dialog); + + // Add escape key handler + document.addEventListener("keydown", function(e) { + if (e.key === "Escape") { + closeUnvalidationModal(); + } + }); +} + +function closeUnvalidationModal() { + var modal = document.getElementById("unvalidationModal"); + if (modal) { + modal.remove(); + } +} + +function proceedUnvalidation(declarationId) { + // Redirect to unvalidation action + window.location.href = "' . $_SERVER['PHP_SELF'] . '?id=" + declarationId + "&action=unvalidate&token=' . newToken() . '"; +} '; // Print footer diff --git a/langs/en_US/declarationtva.lang b/langs/en_US/declarationtva.lang index c393e2d..84f2387 100644 --- a/langs/en_US/declarationtva.lang +++ b/langs/en_US/declarationtva.lang @@ -513,3 +513,5 @@ DraftDeclaration = Draft Declaration ValidatedPDFAvailable = Validated PDF Available NoDocument = No Document DownloadPDF = Download PDF +UnvalidationConfirmationMessage = Are you sure you want to unvalidate this declaration? This action will revert the declaration to draft status and remove the generated PDF. +YesUnvalidate = Yes, unvalidate diff --git a/langs/fr_FR/declarationtva.lang b/langs/fr_FR/declarationtva.lang index d4dfb02..785af87 100644 --- a/langs/fr_FR/declarationtva.lang +++ b/langs/fr_FR/declarationtva.lang @@ -485,3 +485,5 @@ DraftDeclaration = Déclaration brouillon ValidatedPDFAvailable = PDF validé disponible NoDocument = Aucun document DownloadPDF = Télécharger le PDF +UnvalidationConfirmationMessage = Êtes-vous sûr de vouloir annuler la validation de cette déclaration ? Cette action remettra la déclaration en mode brouillon et supprimera le PDF généré. +YesUnvalidate = Oui, annuler la validation