From: Thomas Berezansky Date: Thu, 27 Sep 2012 20:12:29 +0000 (-0400) Subject: Fix race conditions: use addEventListener X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=41b8494fed57024a243c1405cc3c28b5c6a2e6f7;p=working%2FEvergreen.git Fix race conditions: use addEventListener Instead of setting xulG before we know the document has loaded, or in some cases after it has loaded but already been looked for, listen for the load event in capture mode and set it then. Signed-off-by: Thomas Berezansky --- diff --git a/Open-ILS/xul/staff_client/chrome/content/main/main.js b/Open-ILS/xul/staff_client/chrome/content/main/main.js index c131bbe594..889a754dc5 100644 --- a/Open-ILS/xul/staff_client/chrome/content/main/main.js +++ b/Open-ILS/xul/staff_client/chrome/content/main/main.js @@ -406,16 +406,16 @@ function main_init() { var deck = document.getElementById('progress_space'); util.widgets.remove_children( deck ); var iframe = document.createElement('iframe'); deck.appendChild(iframe); + iframe.addEventListener('load', function() { iframe.contentWindow.xulG = xulG; }, true); iframe.setAttribute( 'src', urls.XUL_LOGIN_DATA ); - iframe.contentWindow.xulG = xulG; G.data_xul = iframe.contentWindow; } else { xulG.file = G.file; var deck = G.auth.controller.view.ws_deck; JSAN.use('util.widgets'); util.widgets.remove_children('ws_deck'); var iframe = document.createElement('iframe'); deck.appendChild(iframe); + iframe.addEventListener('load', function() { iframe.contentWindow.xulG = xulG; }, true); iframe.setAttribute( 'src', urls.XUL_WORKSTATION_INFO ); - iframe.contentWindow.xulG = xulG; deck.selectedIndex = deck.childNodes.length - 1; } }; diff --git a/Open-ILS/xul/staff_client/chrome/content/main/menu.js b/Open-ILS/xul/staff_client/chrome/content/main/menu.js index 55a36826ce..36a8d0fbd0 100644 --- a/Open-ILS/xul/staff_client/chrome/content/main/menu.js +++ b/Open-ILS/xul/staff_client/chrome/content/main/menu.js @@ -2391,44 +2391,48 @@ commands: frame.setAttribute('flex','1'); panel.appendChild(frame); dump('creating iframe with src = ' + url + '\n'); - frame.setAttribute('src',url); - try { - var cw = frame.contentWindow; - if (typeof cw.wrappedJSObject != 'undefined') cw = cw.wrappedJSObject; - cw.IAMXUL = true; - cw.xulG = content_params; - cw.addEventListener( - 'load', - function() { - try { - if (typeof cw.help_context_set_locally == 'undefined') { - var help_params = { - 'protocol' : cw.location.protocol, - 'hostname' : cw.location.hostname, - 'port' : cw.location.port, - 'pathname' : cw.location.pathname, - 'src' : '' - }; - obj.set_help_context(help_params); - } else if (typeof cw.default_focus == 'function') { - cw.default_focus(); + var setContentParams = function() { + try { + var cw = frame.contentWindow; + if (typeof cw.wrappedJSObject != 'undefined') cw = cw.wrappedJSObject; + cw.IAMXUL = true; + cw.xulG = content_params; + cw.addEventListener( + 'load', + function() { + try { + if (typeof cw.help_context_set_locally == 'undefined') { + var help_params = { + 'protocol' : cw.location.protocol, + 'hostname' : cw.location.hostname, + 'port' : cw.location.port, + 'pathname' : cw.location.pathname, + 'src' : '' + }; + obj.set_help_context(help_params); + } else if (typeof cw.default_focus == 'function') { + cw.default_focus(); + } + } catch(E) { + obj.error.sdump('D_ERROR', 'main.menu, set_tab, onload: ' + E); } - } catch(E) { - obj.error.sdump('D_ERROR', 'main.menu, set_tab, onload: ' + E); - } - try { - if (typeof params.on_tab_load == 'function') { - params.on_tab_load(cw); + try { + if (typeof params.on_tab_load == 'function') { + params.on_tab_load(cw); + } + } catch(E) { + obj.error.sdump('D_ERROR', 'main.menu, set_tab, onload #2: ' + E); } - } catch(E) { - obj.error.sdump('D_ERROR', 'main.menu, set_tab, onload #2: ' + E); - } - }, - false - ); - } catch(E) { - this.error.sdump('D_ERROR', 'main.menu: ' + E); - } + }, + false + ); + } catch(E) { + this.error.sdump('D_ERROR', 'main.menu: ' + E); + } + frame.removeEventListener('load', setContentParams, true); + }; + frame.addEventListener('load', setContentParams, true); + frame.setAttribute('src',url); } } catch(E) { this.error.sdump('D_ERROR', 'main.menu:2: ' + E); diff --git a/Open-ILS/xul/staff_client/server/cat/bibs_abreast.js b/Open-ILS/xul/staff_client/server/cat/bibs_abreast.js index eaf58bc4fd..9cfc57e09b 100644 --- a/Open-ILS/xul/staff_client/server/cat/bibs_abreast.js +++ b/Open-ILS/xul/staff_client/server/cat/bibs_abreast.js @@ -121,8 +121,9 @@ function render_bib(record_id) { function render_bib_brief(new_node,record_id) { // iframe var bib_brief = util.widgets.find_descendants_by_name(new_node,'bib_brief')[0]; + var setXulG = function() { get_contentWindow(bib_brief).xulG = { 'docid' : record_id }; bib_brief.removeEventListener('load', setXulG, true); }; + bib_brief.addEventListener('load', setXulG, true); bib_brief.setAttribute('src', urls.XUL_BIB_BRIEF_VERTICAL); - get_contentWindow(bib_brief).xulG = { 'docid' : record_id }; } function set_view_pane(deck,record_id) { diff --git a/Open-ILS/xul/staff_client/server/cat/marc_new.xul b/Open-ILS/xul/staff_client/server/cat/marc_new.xul index ae5d3d2317..ea6fc7f66e 100644 --- a/Open-ILS/xul/staff_client/server/cat/marc_new.xul +++ b/Open-ILS/xul/staff_client/server/cat/marc_new.xul @@ -155,8 +155,9 @@ var marc_editor = document.createElement('iframe'); $('marc_editor_box').appendChild(marc_editor); marc_editor.setAttribute('flex','1'); + var setXulG = function() { get_contentWindow(marc_editor).xulG = params; marc_editor.removeEventListener('load', setXulG, true); }; + marc_editor.addEventListener('load', setXulG, true); marc_editor.setAttribute('src',url); - get_contentWindow(marc_editor).xulG = params; /* hide template widgets */ $('actions').hidden = true; diff --git a/Open-ILS/xul/staff_client/server/cat/volume_copy_creator.js b/Open-ILS/xul/staff_client/server/cat/volume_copy_creator.js index 0b16308cd7..a54c11dd31 100644 --- a/Open-ILS/xul/staff_client/server/cat/volume_copy_creator.js +++ b/Open-ILS/xul/staff_client/server/cat/volume_copy_creator.js @@ -195,9 +195,10 @@ function my_init() { } else { while(sb.firstChild) sb.removeChild(sb.lastChild); var summary = document.createElement('iframe'); sb.appendChild(summary); + var setXulG = function() { get_contentWindow(summary).xulG = { 'docid' : g.doc_id }; summary.removeEventListener('load', setXulG, true);}; + summary.addEventListener('load', setXulG, true); summary.setAttribute('src',urls.XUL_BIB_BRIEF); summary.setAttribute('flex','1'); - get_contentWindow(summary).xulG = { 'docid' : g.doc_id }; } /***********************************************************************************************************/ diff --git a/Open-ILS/xul/staff_client/server/cat/volume_copy_editor.js b/Open-ILS/xul/staff_client/server/cat/volume_copy_editor.js index b9bf6a7016..b60df9bb0f 100644 --- a/Open-ILS/xul/staff_client/server/cat/volume_copy_editor.js +++ b/Open-ILS/xul/staff_client/server/cat/volume_copy_editor.js @@ -146,9 +146,10 @@ function on_volume_pane_load() { var sb = document.getElementById('summary_box'); while(sb.firstChild) sb.removeChild(sb.lastChild); var summary = document.createElement('iframe'); sb.appendChild(summary); + var setXulG = function() { get_contentWindow(summary).xulG = { 'docid' : f_content.g.doc_id }; summary.removeEventListener('load', setXulG, true);}; + summary.addEventListener('load', setXulG, true); summary.setAttribute('src',urls.XUL_BIB_BRIEF); summary.setAttribute('flex','1'); - get_contentWindow(summary).xulG = { 'docid' : f_content.g.doc_id }; dump('f_content.g.doc_id = ' + f_content.g.doc_id + '\n'); } catch(E) { alert('Error in volume_copy_editor.js, on_volume_pane_load(): ' + E); diff --git a/Open-ILS/xul/staff_client/server/circ/circ_summary.xul b/Open-ILS/xul/staff_client/server/circ/circ_summary.xul index 26c6e071cb..71883edb83 100644 --- a/Open-ILS/xul/staff_client/server/circ/circ_summary.xul +++ b/Open-ILS/xul/staff_client/server/circ/circ_summary.xul @@ -59,14 +59,16 @@ var tv = $('top_vbox'); while(tv.firstChild) tv.removeChild(tv.lastChild); var top = document.createElement('iframe'); tv.appendChild(top); + var setTopXulG = function() { get_contentWindow(top).xulG = { 'docid' : g.callnumber.record() }; top.removeEventListener('load', setTopXulG, true);}; + top.addEventListener('load', setTopXulG, true); top.setAttribute('src',urls.XUL_BIB_BRIEF); top.setAttribute('flex','1'); - get_contentWindow(top).xulG = { 'docid' : g.callnumber.record() }; var mv = $('mid_vbox'); while(mv.firstChild) mv.removeChild(mv.lastChild); var mid = document.createElement('iframe'); mv.appendChild(mid); + var setMidXulG = function() { get_contentWindow(mid).xulG = { 'copy_id' : g.copy.id(), 'new_tab' : xulG.new_tab, 'url_prefix' : xulG.url_prefix }; mid.removeEventListener('load', setMidXulG, true);}; + mid.addEventListener('load', setMidXulG, true); mid.setAttribute('src',urls.XUL_COPY_SUMMARY); mid.setAttribute('flex','1'); - get_contentWindow(mid).xulG = { 'copy_id' : g.copy.id(), 'new_tab' : xulG.new_tab, 'url_prefix' : xulG.url_prefix }; show_circs(); @@ -91,8 +93,9 @@ 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() }; iframe.removeEventListener('load', setXulG, true);}; + iframe.addEventListener('load', setXulG, true); iframe.setAttribute('src', urls.XUL_CIRC_BRIEF); // + '?circ_id=' + g.circs[j].id() ); - get_contentWindow(iframe).xulG = { 'circ_id' : g.circs[j].id() }; } } catch(E) { g.error.standard_unexpected_error_alert('error showing circs',E); diff --git a/Open-ILS/xul/staff_client/server/circ/copy_details.xul b/Open-ILS/xul/staff_client/server/circ/copy_details.xul index 3cc45c2049..a75626165b 100644 --- a/Open-ILS/xul/staff_client/server/circ/copy_details.xul +++ b/Open-ILS/xul/staff_client/server/circ/copy_details.xul @@ -82,16 +82,18 @@ var tb = $('top_box'); while (tb.firstChild) tb.removeChild(tb.lastChild); var top = document.createElement('iframe'); tb.appendChild(top); + var setTopXulG = function() { get_contentWindow(top).xulG = { 'docid' : g.callnumber.record() }; top.removeEventListener('load', setTopXulG, true);}; + top.addEventListener('load', setTopXulG, true); top.setAttribute('src',urls.XUL_BIB_BRIEF); top.setAttribute('flex','1'); - get_contentWindow(top).xulG = { 'docid' : g.callnumber.record() }; //g.data.temp_copy = g.copy; g.data.stash('temp_copy'); //g.data.temp_callnumber = g.callnumber; g.data.stash('temp_callnumber'); var ib = $('item_summary_box'); while(ib.firstChild) ib.removeChild(ib.lastChild); var item_summary = document.createElement('iframe'); ib.appendChild(item_summary); + var setItemXulG = function() { get_contentWindow(item_summary).xulG = { 'copy' : g.copy, 'callnumber' : g.callnumber, 'new_tab' : xulG.new_tab, 'url_prefix' : xulG.url_prefix }; item_summary.removeEventListener('load', setItemXulG, true);}; + item_summary.addEventListener('load', setItemXulG, true); item_summary.setAttribute('src',urls.XUL_COPY_SUMMARY); item_summary.setAttribute('flex','1'); - get_contentWindow(item_summary).xulG = { 'copy' : g.copy, 'callnumber' : g.callnumber, 'new_tab' : xulG.new_tab, 'url_prefix' : xulG.url_prefix }; $('r_last').disabled = true; if (g.circ) { @@ -99,9 +101,10 @@ g.data.temp_circ = g.circ; g.data.stash('temp_circ'); var cb = $('circ_box'); while(cb.firstChild) cb.removeChild(cb.lastChild); var circ_frame = document.createElement('iframe'); cb.appendChild(circ_frame); + var setCircXulG = function() { get_contentWindow(circ_frame).xulG = { 'no_border' : 1 }; circ_frame.removeEventListener('load', setCircXulG, true);}; + circ_frame.addEventListener('load', setCircXulG, true); circ_frame.setAttribute('src',urls.XUL_CIRC_BRIEF); circ_frame.setAttribute('flex','1'); - get_contentWindow(circ_frame).xulG = { 'no_border' : 1 }; if (g.circ.checkin_time()) { $('circ_caption').setAttribute('label', $('circStrings').getString('staff.circ.copy_details.last_circ')); } else { diff --git a/Open-ILS/xul/staff_client/server/patron/bill_details.js b/Open-ILS/xul/staff_client/server/patron/bill_details.js index 52c4e061ff..7ae4fecc70 100644 --- a/Open-ILS/xul/staff_client/server/patron/bill_details.js +++ b/Open-ILS/xul/staff_client/server/patron/bill_details.js @@ -88,9 +88,10 @@ function retrieve_circ() { var csb = $('copy_summary_vbox'); while (csb.firstChild) csb.removeChild(csb.lastChild); var copy_summary = document.createElement('iframe'); csb.appendChild(copy_summary); + var setXulG = function() { get_contentWindow(copy_summary).xulG = { 'circ' : r_circ, 'copy_id' : r_circ.target_copy(), 'new_tab' : xulG.new_tab, 'url_prefix' : xulG.url_prefix }; copy_summary.removeEventListener('load', setXulG, true);}; + copy_summary.addEventListener('load', setXulG, true); copy_summary.setAttribute('src',urls.XUL_COPY_SUMMARY); // + '?copy_id=' + r_circ.target_copy()); copy_summary.setAttribute('flex','1'); - get_contentWindow(copy_summary).xulG = { 'circ' : r_circ, 'copy_id' : r_circ.target_copy(), 'new_tab' : xulG.new_tab, 'url_prefix' : xulG.url_prefix }; g.network.simple_request( 'MODS_SLIM_RECORD_RETRIEVE_VIA_COPY.authoritative', diff --git a/Open-ILS/xul/staff_client/server/patron/hold_details.js b/Open-ILS/xul/staff_client/server/patron/hold_details.js index be349113a2..39c84b4fe6 100644 --- a/Open-ILS/xul/staff_client/server/patron/hold_details.js +++ b/Open-ILS/xul/staff_client/server/patron/hold_details.js @@ -50,9 +50,10 @@ function fetch_and_render_all(do_not_refresh_parent_interface) { } else { x.hidden = false; var bib_brief = document.createElement('iframe'); x.appendChild(bib_brief); + var setXulG = function() { get_contentWindow(bib_brief).xulG = { 'docid' : g.blob.mvr.doc_id() }; bib_brief.removeEventListener('load', setXulG, true);}; + bib_brief.addEventListener('load', setXulG, true); bib_brief.setAttribute('flex',1); bib_brief.setAttribute('src',urls.XUL_BIB_BRIEF); - get_contentWindow(bib_brief).xulG = { 'docid' : g.blob.mvr.doc_id() }; } retrieve_notes(); render_notes();