From 3d14bec69e95744014e9be1e389071cfefd34753 Mon Sep 17 00:00:00 2001
From: Dhanus <dhanus3133@gmail.com>
Date: Sun, 5 May 2024 13:56:09 +0530
Subject: [PATCH 1/5] [fix] Unsaved changes alert disable on preview view

---
 .../config/static/config/js/unsaved_changes.js              | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/openwisp_controller/config/static/config/js/unsaved_changes.js b/openwisp_controller/config/static/config/js/unsaved_changes.js
index 7591de97c..504990867 100644
--- a/openwisp_controller/config/static/config/js/unsaved_changes.js
+++ b/openwisp_controller/config/static/config/js/unsaved_changes.js
@@ -98,5 +98,11 @@
         });
         // bind unload event
         $(window).bind('beforeunload', unsavedChanges);
+        $(document).on("click", "input.previewlink", function () {
+          $(window).unbind("beforeunload", unsavedChanges);
+        });
+        $(document).on("click", "a.close", function () {
+          $(window).bind("beforeunload", unsavedChanges);
+        });
     });
 }(django.jQuery));

From 547a9cd4804937eaa38469a434e05e64fb9119fe Mon Sep 17 00:00:00 2001
From: Dhanus <dhanus3133@gmail.com>
Date: Wed, 8 May 2024 19:46:25 +0530
Subject: [PATCH 2/5] [chores] Quotes fixes

---
 .../config/static/config/js/unsaved_changes.js            | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/openwisp_controller/config/static/config/js/unsaved_changes.js b/openwisp_controller/config/static/config/js/unsaved_changes.js
index 504990867..bf56fd2bb 100644
--- a/openwisp_controller/config/static/config/js/unsaved_changes.js
+++ b/openwisp_controller/config/static/config/js/unsaved_changes.js
@@ -98,11 +98,11 @@
         });
         // bind unload event
         $(window).bind('beforeunload', unsavedChanges);
-        $(document).on("click", "input.previewlink", function () {
-          $(window).unbind("beforeunload", unsavedChanges);
+        $(document).on('click', 'input.previewlink', function () {
+          $(window).unbind('beforeunload', unsavedChanges);
         });
-        $(document).on("click", "a.close", function () {
-          $(window).bind("beforeunload", unsavedChanges);
+        $(document).on('click', 'a.close', function () {
+          $(window).bind('beforeunload', unsavedChanges);
         });
     });
 }(django.jQuery));

From bc45b3b0e1bb59a5f44fa8fc8ba6d45570944d2e Mon Sep 17 00:00:00 2001
From: Dhanus <dhanus3133@gmail.com>
Date: Wed, 8 May 2024 21:33:09 +0530
Subject: [PATCH 3/5] [chores] Fixed bugs

---
 .../config/static/config/js/unsaved_changes.js           | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/openwisp_controller/config/static/config/js/unsaved_changes.js b/openwisp_controller/config/static/config/js/unsaved_changes.js
index bf56fd2bb..981adf0a6 100644
--- a/openwisp_controller/config/static/config/js/unsaved_changes.js
+++ b/openwisp_controller/config/static/config/js/unsaved_changes.js
@@ -43,6 +43,9 @@
             message = 'You haven\'t saved your changes yet!',
             initialValue,
             name;
+        if (currentValues['organization'] === '') {
+            currentValues['organization'] = 'null';
+        }
         if (gettext) { message = gettext(message); }  // i18n if enabled
         // compare initial with current values
         for (name in django._owcInitialValues) {
@@ -98,11 +101,5 @@
         });
         // bind unload event
         $(window).bind('beforeunload', unsavedChanges);
-        $(document).on('click', 'input.previewlink', function () {
-          $(window).unbind('beforeunload', unsavedChanges);
-        });
-        $(document).on('click', 'a.close', function () {
-          $(window).bind('beforeunload', unsavedChanges);
-        });
     });
 }(django.jQuery));

From e1ba4fff5c700898cdc69d2b96ef30f75465f4cf Mon Sep 17 00:00:00 2001
From: Dhanus <dhanus3133@gmail.com>
Date: Wed, 8 May 2024 21:41:24 +0530
Subject: [PATCH 4/5] [chores] QA checks

---
 .../config/static/config/js/unsaved_changes.js                | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/openwisp_controller/config/static/config/js/unsaved_changes.js b/openwisp_controller/config/static/config/js/unsaved_changes.js
index 981adf0a6..f9e42de69 100644
--- a/openwisp_controller/config/static/config/js/unsaved_changes.js
+++ b/openwisp_controller/config/static/config/js/unsaved_changes.js
@@ -43,8 +43,8 @@
             message = 'You haven\'t saved your changes yet!',
             initialValue,
             name;
-        if (currentValues['organization'] === '') {
-            currentValues['organization'] = 'null';
+        if (currentValues.organization === '') {
+            currentValues.organization = 'null';
         }
         if (gettext) { message = gettext(message); }  // i18n if enabled
         // compare initial with current values

From c66e0faa1b7733611af449ee65dd695f659dfae7 Mon Sep 17 00:00:00 2001
From: Dhanus <dhanus3133@gmail.com>
Date: Wed, 8 May 2024 21:45:38 +0530
Subject: [PATCH 5/5] [chores] Add comment

---
 openwisp_controller/config/static/config/js/unsaved_changes.js | 1 +
 1 file changed, 1 insertion(+)

diff --git a/openwisp_controller/config/static/config/js/unsaved_changes.js b/openwisp_controller/config/static/config/js/unsaved_changes.js
index f9e42de69..5bee77ead 100644
--- a/openwisp_controller/config/static/config/js/unsaved_changes.js
+++ b/openwisp_controller/config/static/config/js/unsaved_changes.js
@@ -43,6 +43,7 @@
             message = 'You haven\'t saved your changes yet!',
             initialValue,
             name;
+        // django initial values returns organization as 'null' when it is empty
         if (currentValues.organization === '') {
             currentValues.organization = 'null';
         }