[Patchew-devel] [PATCH 11/17] mods: ask for confirmation after the user has added an item

Paolo Bonzini pbonzini at redhat.com
Thu May 2 11:17:58 UTC 2019


---
 static/js/config-editor.js | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/static/js/config-editor.js b/static/js/config-editor.js
index c0f326f..562077d 100644
--- a/static/js/config-editor.js
+++ b/static/js/config-editor.js
@@ -2,6 +2,16 @@ function current_project() {
     return $('h2').text();
 }
 
+function confirm_leaving_page(enable) {
+    if (enable) {
+        window.onbeforeunload = function() {
+            return "You have modified the configuration but have not saved it yet.";
+        };
+    } else {
+        window.onbeforeunload = null;
+    }
+}
+
 function save_done(btn, succeeded, error) {
     $(btn).text("Save");
     $(btn).removeClass("disabled");
@@ -9,6 +19,7 @@ function save_done(btn, succeeded, error) {
     if (succeeded) {
         info.addClass("alert-success");
         info.html("Saved");
+        confirm_leaving_page(false);
     } else {
         info.addClass("alert-danger");
         info.html("Error: " + error);
@@ -101,6 +112,7 @@ function map_add_item(btn) {
     });
     nt.find(".panel-collapse").collapse("show");
     container.find("> .items").append(nt);
+    confirm_leaving_page(true);
 }
 
 function map_delete_item(btn) {
-- 
2.21.0





More information about the Patchew-devel mailing list