Scoping Issues: Use a function to resolve user/tsbere/fix_race_conditions
authorThomas Berezansky <tsbere@mvlc.org>
Fri, 28 Sep 2012 19:09:29 +0000 (15:09 -0400)
committerThomas Berezansky <tsbere@mvlc.org>
Fri, 28 Sep 2012 19:09:29 +0000 (15:09 -0400)
The loop scoping doesn't play nice with the load callback. By wrapping all
of that in a function we create a new scope and solve the issue.

Signed-off-by: Thomas Berezansky <tsbere@mvlc.org>
Open-ILS/xul/staff_client/server/circ/circ_summary.xul

index 6b7f6fa..70600cd 100644 (file)
                 $('r_last').disabled = false; $('r_all').disabled = false;    
 
                 var gb = $('circs');
-                for (var j = 0; j < g.circs.length; j++) {
+                function addcirc(circid) {
                     var iframe = document.createElement('iframe');
                     iframe.setAttribute('style','overflow: none; min-height: 100px;');
                     iframe.setAttribute('flex','1');
                     gb.appendChild(iframe);
                     var setXulG = function() {
-                        get_contentWindow(iframe).xulG = { 'circ_id' : g.circs[j].id() };
+                        get_contentWindow(iframe).xulG = { 'circ_id' : circid };
                         iframe.removeEventListener('load', setXulG, true);
                     };
                     iframe.addEventListener('load', setXulG, true);
                     iframe.setAttribute('src', urls.XUL_CIRC_BRIEF); // + '?circ_id=' + g.circs[j].id() );
                 }
+                for (var j = 0; j < g.circs.length; j++) {
+                    addcirc(g.circs[j].id());
+                }
             } catch(E) {
                 g.error.standard_unexpected_error_alert('error showing circs',E);
             }