add unsaved data warning to offline interface. tweak oils_lock_page/oils_unlock_page...
authorphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 7 Dec 2010 20:01:09 +0000 (20:01 +0000)
committerphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 7 Dec 2010 20:01:09 +0000 (20:01 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@18930 dcc99617-32d9-48b4-a31d-7c20da2025e4

12 files changed:
Open-ILS/xul/staff_client/chrome/content/OpenILS/global_util.js
Open-ILS/xul/staff_client/chrome/content/circ/offline.js
Open-ILS/xul/staff_client/chrome/content/circ/offline_checkin.js
Open-ILS/xul/staff_client/chrome/content/circ/offline_checkin.xul
Open-ILS/xul/staff_client/chrome/content/circ/offline_checkout.js
Open-ILS/xul/staff_client/chrome/content/circ/offline_checkout.xul
Open-ILS/xul/staff_client/chrome/content/circ/offline_in_house_use.js
Open-ILS/xul/staff_client/chrome/content/circ/offline_in_house_use.xul
Open-ILS/xul/staff_client/chrome/content/circ/offline_register.js
Open-ILS/xul/staff_client/chrome/content/circ/offline_register.xul
Open-ILS/xul/staff_client/chrome/content/circ/offline_renew.js
Open-ILS/xul/staff_client/chrome/content/circ/offline_renew.xul

index c207eb9..aa6b966 100644 (file)
@@ -3,37 +3,39 @@
     function oils_lock_page(params) {
         dump('oils_lock_page\n');
         if (!params) { params = {}; }
-        if (window.oils_lock) {
+        if (window.oils_lock > 0) {
             if (!params.allow_multiple_locks) {
-                return 'already locked';
+                return window.oils_lock;
             }
         }
-        window.oils_lock = true;
+        window.oils_lock++;
         if (typeof xulG != 'undefined') {
             if (typeof xulG.unlock_tab == 'function') {
                 xulG.lock_tab();
             }
         }
-        return 'locked';
+        return window.oils_lock;
     }
 
     function oils_unlock_page(params) {
         dump('oils_unlock_page\n');
-        window.oils_lock = false;
+        window.oils_lock--;
+        if (window.oils_lock < 0) { window.oils_lock = 0; }
         if (typeof xulG != 'undefined') {
             if (typeof xulG.unlock_tab == 'function') {
                 xulG.unlock_tab();
             }
         }
-        return 'unlocked';
+        return window.oils_lock;
     }
 
+    window.oils_lock = 0;
     window.addEventListener(
         'close',
         function(ev) {
             try {
                 dump('oils_lock_page/oils_unlock_page onclose handler\n');
-                if (window.oils_lock) {
+                if (window.oils_lock > 0) {
                     var confirmation = window.confirm($('offlineStrings').getString('menu.close_window.unsaved_data_warning'));
                     if (!confirmation) {
                         ev.preventDefault();
@@ -41,7 +43,7 @@
                     }
                 }
 
-                window.oils_lock = false;
+                window.oils_lock = 0;
                 if (typeof xulG != 'undefined') {
                     if (typeof xulG.unlock_tab == 'function') {
                         xulG.unlock_tab();
index 12fe1b7..d3cc499 100644 (file)
@@ -31,23 +31,68 @@ circ.offline.prototype = {
                         ],
                         'cmd_checkout' : [
                             ['command'],
-                            function() { obj.deck.set_iframe('offline_checkout.xul',{},{}); }
+                            function() {
+                                obj.deck.set_iframe(
+                                    'offline_checkout.xul',
+                                    {},
+                                    {
+                                        'lock' : function() { oils_lock_page({'allow_multiple_locks':true}); },
+                                        'unlock' : oils_unlock_page
+                                    }
+                                );
+                            }
                         ],
                         'cmd_renew' : [
                             ['command'],
-                            function() { obj.deck.set_iframe('offline_renew.xul',{},{}); }
+                            function() {
+                                obj.deck.set_iframe(
+                                    'offline_renew.xul',
+                                    {},
+                                    {
+                                        'lock' : function() { oils_lock_page({'allow_multiple_locks':true}); },
+                                        'unlock' : oils_unlock_page
+                                    }
+                                );
+                            }
                         ],
                         'cmd_in_house_use' : [
                             ['command'],
-                            function() { obj.deck.set_iframe('offline_in_house_use.xul',{},{}); }
+                            function() {
+                                obj.deck.set_iframe(
+                                    'offline_in_house_use.xul',
+                                    {},
+                                    {
+                                        'lock' : function() { oils_lock_page({'allow_multiple_locks':true}); },
+                                        'unlock' : oils_unlock_page
+                                    }
+                                );
+                            }
                         ],
                         'cmd_checkin' : [
                             ['command'],
-                            function() { obj.deck.set_iframe('offline_checkin.xul',{},{}); }
+                            function() {
+                                obj.deck.set_iframe(
+                                    'offline_checkin.xul',
+                                    {},
+                                    {
+                                        'lock' : function() { oils_lock_page({'allow_multiple_locks':true}); },
+                                        'unlock' : oils_unlock_page
+                                    }
+                                );
+                            }
                         ],
                         'cmd_register_patron' : [
                             ['command'],
-                            function() { obj.deck.set_iframe('offline_register.xul',{},{}); }
+                            function() {
+                                obj.deck.set_iframe(
+                                    'offline_register.xul',
+                                    {},
+                                    {
+                                        'lock' : function() { oils_lock_page({'allow_multiple_locks':true}); },
+                                        'unlock' : oils_unlock_page
+                                    }
+                                );
+                            }
                         ],
                         'cmd_print_last_receipt' : [
                             ['command'],
@@ -58,7 +103,14 @@ circ.offline.prototype = {
                         ],
                         'cmd_exit' : [
                             ['command'],
-                            function() { try { xulG.close_tab(); } catch(E) { window.close(); } }
+                            function() {
+                                try {
+                                    xulG.close_tab();
+                                } catch(E) {
+                                    JSAN.use('util.widgets');
+                                    util.widgets.dispatch('close',window);
+                                }
+                            }
                         ],
                     }
                 }
index fd6b69f..5fb625c 100644 (file)
@@ -1,4 +1,5 @@
 var offlineStrings;
+var local_lock = false;
 
 function my_init() {
     try {
@@ -26,6 +27,13 @@ function my_init() {
 
         JSAN.use('util.date');
 
+        function handle_lock(ev) {
+            if (!local_lock) {
+                local_lock = true;
+                xulG.lock();
+            }
+        }
+        $('i_barcode').addEventListener('change',handle_lock,false);
         $('i_barcode').addEventListener('keypress',handle_keypress,false);
         $('i_barcode').focus();    
 
@@ -92,6 +100,11 @@ function append_to_list() {
 
         var x = $('i_barcode'); x.value = ''; x.focus();
 
+        if (!local_lock) {
+            local_lock = true;
+            xulG.lock();
+        }
+
     } catch(E) {
 
         dump(E+'\n'); alert(E);
@@ -109,6 +122,11 @@ function next_patron() {
         }
         file.close();
 
+        if (local_lock) {
+            local_lock = false;
+            xulG.unlock();
+        }
+
         if ($('print_receipt').checked) {
             try {
                 var params = {
index c6a8242..8c43929 100644 (file)
@@ -67,7 +67,7 @@
                 </hbox>
                 <hbox>
                     <spacer flex="1"/>
-                    <button id="cancel" label="&common.cancel;" oncommand="g.list.clear()"/>
+                    <button id="cancel" hidden="true" label="&common.cancel;" oncommand="g.list.clear()"/>
                     <button id="submit" label="&common.save_transactions.label;" accesskey="&common.save_transactions.accesskey;" />
                 </hbox>
             </vbox>
index 1b6e3e1..5db785c 100644 (file)
@@ -1,4 +1,5 @@
 var offlineStrings;
+var local_lock = false;
 
 function my_init() {
     try {
@@ -31,14 +32,23 @@ function my_init() {
         var todayPlus = new Date(); todayPlus.setTime( today.getTime() + 24*60*60*1000*14 );
         todayPlus = util.date.formatted_date(todayPlus,"%F");
 
+        function handle_lock(ev) {
+            if (!local_lock) {
+                local_lock = true;
+                xulG.lock();
+            }
+        }
+
         $('duedate').setAttribute('value',todayPlus);
         $('duedate').addEventListener('change',check_date,false);
 
         $('p_barcode').addEventListener('change',test_patron,false);
+        $('p_barcode').addEventListener('change',handle_lock,false);
 
         $('p_barcode').addEventListener('keypress',handle_keypress,false);
         $('p_barcode').focus();    
 
+        $('i_barcode').addEventListener('change',handle_lock,false);
         $('i_barcode').addEventListener('keypress',handle_keypress,false);
         $('enter').addEventListener('command',handle_enter,false);
 
@@ -238,6 +248,11 @@ function append_to_list(checkout_type,count) {
 
         var x = $('i_barcode'); x.value = ''; x.focus();
 
+        if (!local_lock) {
+            local_lock = true;
+            xulG.lock();
+        }
+
     } catch(E) {
 
         dump(E+'\n'); alert(E);
@@ -261,6 +276,11 @@ function save_xacts() {
         file.append_object(row);
     }
     file.close();
+
+    if (local_lock) {
+        local_lock = false;
+        xulG.unlock();
+    }
 }
 
 function next_patron(cancel) {
index 1fff66f..a66f3df 100644 (file)
                 </hbox>
                 <hbox>
                     <spacer flex="1"/>
-                    <button id="cancel" label="&common.cancel;" />
+                    <button id="cancel" hidden="true" label="&common.cancel;" />
                     <button id="submit" label="&common.save_transactions.label;" accesskey="&common.save_transactions.accesskey;" />
                 </hbox>
             </vbox>
index f842406..fc59c5a 100644 (file)
@@ -1,4 +1,5 @@
 var offlineStrings;
+var local_lock = false;
 
 function my_init() {
     try {
@@ -24,6 +25,13 @@ function my_init() {
             'map_row_to_column' : circ.util.std_map_row_to_column(),
         } );
 
+        function handle_lock(ev) {
+            if (!local_lock) {
+                local_lock = true;
+                xulG.lock();
+            }
+        }
+        $('i_barcode').addEventListener('change',handle_lock,false);
         $('i_barcode').addEventListener('keypress',handle_keypress,false);
         $('enter').addEventListener('command',handle_enter,false);
         $('submit').addEventListener('command',next_patron,false);
@@ -95,6 +103,11 @@ function append_to_list() {
 
         var x = $('i_barcode'); x.value = ''; x.focus();
 
+        if (!local_lock) {
+            local_lock = true;
+            xulG.lock();
+        }
+
     } catch(E) {
 
         dump(E+'\n'); alert(E);
@@ -112,6 +125,11 @@ function next_patron() {
         }
         file.close();
         
+        if (local_lock) {
+            local_lock = false;
+            xulG.unlock();
+        }
+
         if ($('print_receipt').checked) {
             try {
                 var params = {
index 697a576..57d7d66 100644 (file)
@@ -76,7 +76,7 @@
                 </hbox>
                 <hbox>
                     <spacer flex="1"/>
-                    <button id="cancel" label="&common.cancel;" oncommand="g.list.clear()"/>
+                    <button id="cancel" hidden="true" label="&common.cancel;" oncommand="g.list.clear()"/>
                     <button id="submit" label="&common.save_transactions.label;" accesskey="&common.save_transactions.accesskey;" />
                 </hbox>
             </vbox>
index 80ee2ac..2d3e1d5 100644 (file)
@@ -1,4 +1,5 @@
 var offlineStrings;
+var local_lock = false;
 
 function my_init() {
     try {
@@ -21,6 +22,48 @@ function my_init() {
         $('barcode').addEventListener('keypress',handle_keypress,false);
         $('submit').addEventListener('command',next_patron,false);
 
+        function handle_lock(ev) {
+            if (!local_lock) {
+                local_lock = true;
+                xulG.lock();
+            }
+        }
+        $('barcode').addEventListener('change',handle_lock,false);
+        $('passwd').addEventListener('change',handle_lock,false);
+        $('ident_value').addEventListener('change',handle_lock,false);
+        $('first_given_name').addEventListener('change',handle_lock,false);
+        $('family_name').addEventListener('change',handle_lock,false);
+        $('dob').addEventListener('change',handle_lock,false);
+        $('street1').addEventListener('change',handle_lock,false);
+        $('street2').addEventListener('change',handle_lock,false);
+        $('city').addEventListener('change',handle_lock,false);
+        $('state').addEventListener('change',handle_lock,false);
+        $('country').addEventListener('change',handle_lock,false);
+        $('post_code').addEventListener('change',handle_lock,false);
+
+        $('cancel').addEventListener(
+            'command',
+            function(ev) {
+                $('barcode').value = '';
+                $('passwd').value = '';
+                $('ident_value').value = '';
+                $('first_given_name').value = '';
+                $('family_name').value = '';
+                $('dob').value = '';
+                $('street1').value = '';
+                $('street2').value = '';
+                $('city').value = '';
+                $('state').value = '';
+                $('country').value = '';
+                $('post_code').value = '';
+                if (local_lock) {
+                    local_lock = false;
+                    xulG.unlock();
+                }
+            },
+            false
+        );
+
         JSAN.use('util.file');
         JSAN.use('util.widgets');
 
@@ -316,6 +359,11 @@ function next_patron() {
         file.append_object(obj);
         file.close();
 
+        if (local_lock) {
+            local_lock = false;
+            xulG.unlock();
+        }
+
         alert(offlineStrings.getString('circ.offline_register.patron.saved'));
 
         $('passwd').value = parseInt(Math.random()*8999+1000);
index a7e1745..571a649 100644 (file)
         </hbox>
         <hbox>
             <spacer flex="1"/>
-            <button id="cancel" label="&common.cancel;" />
+            <button id="cancel" hidden="true" label="&common.cancel;" />
             <button id="submit" label="&staff.circ.offline_register.submit.label;" accesskey="&staff.circ.offline_register.submit.accesskey;" />
         </hbox>
     </groupbox>
index 3b20468..fc1b286 100644 (file)
@@ -1,4 +1,6 @@
 var offlineStrings;
+var local_lock = false;
+
 function my_init() {
     try {
         offlineStrings = $('offlineStrings');
@@ -27,14 +29,23 @@ function my_init() {
         var todayPlus = new Date(); todayPlus.setTime( today.getTime() + 24*60*60*1000*14 );
         todayPlus = util.date.formatted_date(todayPlus,"%F");
 
+        function handle_lock(ev) {
+            if (!local_lock) {
+                local_lock = true;
+                xulG.lock();
+            }
+        }
+
         $('duedate').setAttribute('value',todayPlus);
         $('duedate').addEventListener('change',check_date,false);
 
+        $('p_barcode').addEventListener('change',handle_lock,false);
         $('p_barcode').addEventListener('change',test_patron,false);
 
         $('p_barcode').addEventListener('keypress',handle_keypress,false);
         $('p_barcode').focus();    
 
+        $('i_barcode').addEventListener('change',handle_lock,false);
         $('i_barcode').addEventListener('keypress',handle_keypress,false);
         $('enter').addEventListener('command',handle_enter,false);
 
@@ -199,6 +210,11 @@ function append_to_list(checkout_type,count) {
 
         var x = $('i_barcode'); x.value = ''; x.focus();
 
+        if (!local_lock) {
+            local_lock = true;
+            xulG.lock();
+        }
+
     } catch(E) {
 
         dump(E+'\n'); alert(E);
@@ -220,7 +236,12 @@ function next_patron(cancel) {
                     file.append_object(row);
                 }
                 file.close();
-                
+
+                if (local_lock) {
+                    local_lock = false;
+                    xulG.unlock();
+                }
+               
                 if ($('print_receipt').checked) {
                     try {
                         var params = {
index 7c839c1..3d41709 100644 (file)
                 </hbox>
                 <hbox>
                     <spacer flex="1"/>
-                    <button id="cancel" label="&common.cancel;" />
+                    <button id="cancel" hidden="true" label="&common.cancel;" />
                     <button id="submit" label="&common.save_transactions.label;" accesskey="&common.save_transactions.accesskey;" />
                 </hbox>
             </vbox>