improve UI responsiveness with setTimeout
authorJason Etheridge <jason@esilibrary.com>
Mon, 28 Feb 2011 06:00:45 +0000 (01:00 -0500)
committerJason Etheridge <jason@esilibrary.com>
Wed, 2 Mar 2011 15:20:57 +0000 (10:20 -0500)
Open-ILS/xul/staff_client/server/cat/volume_copy_creator.js

index 07398b2..37d1500 100644 (file)
@@ -359,12 +359,21 @@ g.render_barcode_entry = function(node,callnumber,count,ou_id) {
                         setTimeout( function() { ev.target.select(); ev.target.focus(); }, 0);
                     }
                     if (xulG.unified_interface) {
-                        g.gather_copies();
-                        try {
-                            xulG.refresh_copy_editor();
-                        } catch(E) {
-                            alert('Error in volume_copy_editor.js trying to call xulG.refresh_copy_editor(): ' + E);
+                        if (g.update_copy_editor_timeoutID) {
+                            clearTimeout(g.update_copy_editor_timeoutID);
                         }
+                        // This function is expensive when it comes to keeping the UI responsive, so let's give it a delay
+                        // that quick entry of consecutive barcodes can override
+                        g.update_copy_editor_timeoutID = setTimeout(
+                            function() {
+                                g.gather_copies();
+                                try {
+                                    xulG.refresh_copy_editor();
+                                } catch(E) {
+                                    alert('Error in volume_copy_editor.js trying to call xulG.refresh_copy_editor(): ' + E);
+                                }
+                            }, 2000
+                        );
                     }
                 }, false);
                 tb.addEventListener( 'focus', function(ev) { g.last_focus = ev.target; }, false );