prevent some race conditions with multiple onchange handlers
authorJason Etheridge <jason@esilibrary.com>
Tue, 8 Mar 2011 20:58:04 +0000 (15:58 -0500)
committerJason Etheridge <jason@esilibrary.com>
Tue, 8 Mar 2011 20:58:04 +0000 (15:58 -0500)
Open-ILS/xul/staff_client/chrome/content/util/widgets.js
Open-ILS/xul/staff_client/server/cat/volume_copy_creator.js

index 3e0dbc9..2bad0b0 100644 (file)
@@ -211,7 +211,7 @@ util.widgets.insertAfter = function(parent_node,new_node,sibling_node) {
     }
 }
 
-util.widgets.apply_vertical_tab_on_enter_handler = function(node,onfailure) {
+util.widgets.apply_vertical_tab_on_enter_handler = function(node,onfailure,no_enter_func) {
     try {
         node.addEventListener(
             'keypress',
@@ -226,9 +226,14 @@ util.widgets.apply_vertical_tab_on_enter_handler = function(node,onfailure) {
                         ev.preventDefault(); ev.stopPropagation();
                         return true;
                     } else {
+                        dump('keypress: attempting onfailure\n');
                         if (typeof onfailure == 'function') return onfailure(ev);
                         return false;
                     }
+                } else {
+                    if (typeof no_enter_func == 'function') {
+                        no_enter_func(ev);
+                    }
                 }
             },
             false
index 78e6110..782b99f 100644 (file)
@@ -200,7 +200,8 @@ g.render_volume_count_entry = function(row,ou_id) {
     }
     util.widgets.apply_vertical_tab_on_enter_handler(
         tb,
-        function() { render_copy_count_entry({'target':tb}); setTimeout(function(){util.widgets.vertical_tab(tb);},0); }
+        function() { render_copy_count_entry({'target':tb}); setTimeout(function(){util.widgets.vertical_tab(tb);},0); },
+        g.abort_gather_copies_soon
     );
     tb.addEventListener( 'change', render_copy_count_entry, false);
     tb.addEventListener( 'change', g.gather_copies_soon, false);
@@ -260,7 +261,6 @@ g.render_callnumber_copy_count_entry = function(row,ou_id,count) {
         x.setAttribute('style','font-weight: bold');
 
     function handle_change(call_number_column_textbox,number_of_copies_column_textbox,barcode_column_box) {
-        if (call_number_column_textbox.value == '') return;
         if (isNaN( Number( number_of_copies_column_textbox.value ) )) return;
         if ( Number( number_of_copies_column_textbox.value ) > g_max_copies_that_can_be_added_at_a_time_per_volume ) {
             g.error.yns_alert($("catStrings").getFormattedString('staff.cat.volume_copy_creator.render_volume_count_entry.message', [g_max_copies_that_can_be_added_at_a_time_per_volume]),
@@ -337,7 +337,8 @@ g.render_callnumber_copy_count_entry = function(row,ou_id,count) {
                                     util.widgets.vertical_tab(call_number_column_textbox);
                                 },0
                             );
-                        }
+                        },
+                        g.abort_gather_copies_soon
                     );
                     call_number_column_textbox.addEventListener( 'change', handle_change_call_number_column_textbox, false);
                     call_number_column_textbox.addEventListener( 'change', g.gather_copies_soon, false);
@@ -382,7 +383,8 @@ g.render_callnumber_copy_count_entry = function(row,ou_id,count) {
                                     util.widgets.vertical_tab(number_of_copies_column_textbox);
                                 },0
                             );
-                        }
+                        },
+                        g.abort_gather_copies_soon
                     );
                     number_of_copies_column_textbox.addEventListener( 'change', handle_change_number_of_copies_column_textbox, false);
                     number_of_copies_column_textbox.addEventListener( 'change', g.gather_copies_soon, false);
@@ -560,11 +562,13 @@ g.render_barcode_entry = function(node,callnumber,count,ou_id) {
             if (set_handlers) {
                 util.widgets.apply_vertical_tab_on_enter_handler(
                     tb,
-                    function() { ready_to_create({'target':tb}); setTimeout(function(){util.widgets.vertical_tab(tb);},0); }
+                    function() { ready_to_create({'target':tb}); setTimeout(function(){util.widgets.vertical_tab(tb);},0); },
+                    g.abort_gather_copies_soon
                 );
                 util.widgets.apply_vertical_tab_on_enter_handler(
                     part_menu.firstChild,
-                    function() { setTimeout(function(){util.widgets.vertical_tab(part_menu.firstChild);},0); }
+                    function() { setTimeout(function(){util.widgets.vertical_tab(part_menu.firstChild);},0); },
+                    g.abort_gather_copies_soon
                 );
                 tb.addEventListener('change', function(ev) {
                     var barcode = String( ev.target.value ).replace(/\s/g,'');
@@ -621,7 +625,15 @@ g.generate_barcodes = function() {
     }
 }
 
+g.abort_gather_copies_soon = function() {
+    dump('g.abort_gather_copies_soon()\n');
+    if (g.update_copy_editor_timeoutID) {
+        clearTimeout(g.update_copy_editor_timeoutID);
+    }
+}
+
 g.gather_copies_soon = function() {
+    dump('g.gather_copies_soon()\n');
     if (g.update_copy_editor_timeoutID) {
         clearTimeout(g.update_copy_editor_timeoutID);
     }
@@ -644,6 +656,7 @@ g.gather_copies_soon = function() {
 g.new_acp_id = -1;
 
 g.gather_copies = function() {
+    dump('g.gather_copies()\n');
     try {
         var nl = document.getElementsByTagName('textbox');