From 0b72762e4331f32d793031db5e5e49f52741f195 Mon Sep 17 00:00:00 2001
From: Emmanuel Viennet <emmanuel.viennet@gmail.com>
Date: Sun, 25 Dec 2022 16:40:05 -0300
Subject: [PATCH] =?UTF-8?q?Formulaire=20jury=20BUT:=20v=C3=A9rifie=20sorti?=
 =?UTF-8?q?e=20sans=20enregistrement=20(JS)=20#425?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 app/static/js/jury_but.js | 27 ++++++++++++++++++++++++++-
 sco_version.py            |  2 +-
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/app/static/js/jury_but.js b/app/static/js/jury_but.js
index 1ef24c168..c90f95d63 100644
--- a/app/static/js/jury_but.js
+++ b/app/static/js/jury_but.js
@@ -59,4 +59,29 @@ $(function () {
         }
 
     }
-});
\ No newline at end of file
+});
+
+//  ----- Etat du formulaire jury pour éviter sortie sans enregistrer
+let FORM_STATE = "";
+// Une chaine décrivant l'état du form
+function get_form_state() {
+    let codes = [];
+    // il n'y a que des <select>
+    document.querySelectorAll("select").forEach(sel => codes.push(sel.value));
+    return codes.join();
+}
+
+$('document').ready(function () {
+    FORM_STATE = get_form_state();
+});
+
+function is_modified() {
+    return FORM_STATE != get_form_state();
+}
+window.addEventListener("beforeunload", function (e) {
+    if (is_modified()) {
+        var confirmationMessage = 'Changements non enregistrés !';
+        (e || window.event).returnValue = confirmationMessage;
+        return confirmationMessage;
+    }
+});
diff --git a/sco_version.py b/sco_version.py
index 5a42b639a..98f0f59b5 100644
--- a/sco_version.py
+++ b/sco_version.py
@@ -1,7 +1,7 @@
 # -*- mode: python -*-
 # -*- coding: utf-8 -*-
 
-SCOVERSION = "9.4.19"
+SCOVERSION = "9.4.20"
 
 SCONAME = "ScoDoc"
 
-- 
GitLab