oils_lock_page() and oils_unlock_page() for xul interfaces that wraps xulG.lock_tab...
authorphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 7 Dec 2010 16:58:17 +0000 (16:58 +0000)
committerphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 7 Dec 2010 16:58:17 +0000 (16:58 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@18928 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/xul/staff_client/chrome/content/OpenILS/global_util.js

index 459a628..54d8665 100644 (file)
@@ -1,5 +1,55 @@
     function $(id) { return document.getElementById(id); }
 
+    function oils_lock_page(params) {
+        if (!params) { params = {}; }
+        if (window.oils_lock) {
+            if (!params.allow_multiple_locks) {
+                return 'already locked';
+            }
+        }
+        window.oils_lock = true;
+        if (typeof xulG != 'undefined') {
+            if (typeof xulG.unlock_tab == 'function') {
+                xulG.lock_tab();
+            }
+        }
+        return 'locked';
+    }
+
+    function oils_unlock_page(params) {
+        window.oils_lock = false;
+        if (typeof xulG != 'undefined') {
+            if (typeof xulG.unlock_tab == 'function') {
+                xulG.unlock_tab();
+            }
+        }
+        return 'unlocked';
+    }
+
+    window.addEventListener(
+        'close',
+        function(ev) {
+
+                if (window.oils_lock) {
+                    var confirmation = window.confirm($('offlineStrings').getString('menu.close_window.unsaved_data_warning'));
+                    if (!confirmation) {
+                        ev.preventDefault();
+                        return false;
+                    }
+                }
+
+                window.oils_lock = false;
+                if (typeof xulG != 'undefined') {
+                    if (typeof xulG.unlock_tab == 'function') {
+                        xulG.unlock_tab();
+                    }
+                }
+
+                return true;
+        },
+        false
+    );
+
     function ses(a,params) {
         try {
             if (!params) params = {};