From: Jason Etheridge Date: Mon, 28 Feb 2011 04:59:52 +0000 (-0500) Subject: provide an easy override to xul_param() modal_xulG behavior, for windows that are... X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=af232642379812aecdd511a8da2ad5ec895321c9;p=evergreen%2Fequinox.git provide an easy override to xul_param() modal_xulG behavior, for windows that are no longer strictly modal Some background, a little code documentation: The utility function xul_param() was a quick attempt at abstracting away different mechanisms of passing data to content windows, rather than taking the "hard" route of re-factoring and standardizing on one scheme right away. CGI-style query params were one early mechanism for pure data, but defeated caching and the now deprecated @persist mechanism in XUL (which would tie persisted data to the entire URL). "xulG" was an experiment that caught on for injecting data (and references to external functions) directly into a window. For example: var w = window.open('test.html'); w.xulG = { 'foo' : 'bar' }; Another mechanism for data sharing is a hack involving a singleton Mozilla XPCOM (cross-platform component) implemented with Javascript. XPCOM is supposed to be accessed strictly through a defined interface, but if implemented with Javascript, external code can reach into the underlying implementation. The hack uses this fact and bypasses the IDL and stores arbitrary Javascript in the same scope as the implementation. This Javascript can be shared across different windows/users of the XPCOM. We've wrapped this in a JSAN library that you can use like so: JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.stash_retrieve(); data.foo = 'bar'; data.stash('foo'); One problem with xulG is that it would not work with modal windows: var w = window.open('test.html','_blank','modal'); // this blocks until the window is closed w.xulG = { 'foo' : 'bar' }; // making this line impotent OpenILS.data was used on ad-hoc basis for some modal windows, using such keys as "temporary_barcodes". This was usually okay because of common workflows and the nature of modal windows locking up the rest of an interface, however, the staff client could support multiple "top-level" windows, which could each spawn independent modal windows, rendering such keys non-unique. Another JSAN library was constructed, util.window, which could pass data for non-modal windows using xulG, and construct a local xulG for modal windows by passing data through OpenILS.data with a (not much better, I see now) key based on the window (location.pathname + location.search + location.hash). JSAN.use('util.window); var win = new util.window(); var w = win.open('test.html','title','chrome',{'foo':'bar'}); // or var returned_xulG = win.open('test.html','title','chrome,modal',{'foo':'bar'}); Use of xul_param() in a modal window created thus would setup the local xulG (and return the data for the specified key). The update_modal_xulG() function would set things up using OpenILS.data for util.window to pass data back from the modal window to the calling code upon window closure. Now I'm at a point where I have a wrapper interface embedding two separate interfaces that can potentially share a common xulG and communicate through it. However, one of the sub-interfaces used to be modal, and its use of xul_param wipes out its reference to the shared xulG. So once again, trying to change the least code at a time (at the risk of making things even less comprehensible), this change allows the presence of xulG.not_modal to disable the use of OpenILS.data and the vivication of a new xulG when using xul_param(). --- diff --git a/Open-ILS/xul/staff_client/chrome/content/OpenILS/global_util.js b/Open-ILS/xul/staff_client/chrome/content/OpenILS/global_util.js index 364d573121..befb693aec 100644 --- a/Open-ILS/xul/staff_client/chrome/content/OpenILS/global_util.js +++ b/Open-ILS/xul/staff_client/chrome/content/OpenILS/global_util.js @@ -413,6 +413,12 @@ function update_modal_xulG(v) { try { + if (typeof xulG != "undefined" && xulG.not_modal) { + xulG = v; + xulG.not_modal = true; + return; + } + JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'}); var key = location.pathname + location.search + location.hash; if (typeof data.modal_xulG_stack != 'undefined' && typeof data.modal_xulG_stack[key] != 'undefined') { @@ -453,11 +459,15 @@ } if (typeof _params.no_xulG == 'undefined') { if (typeof _params.modal_xulG != 'undefined') { - JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'}); - var key = location.pathname + location.search + location.hash; - //dump('xul_param, considering modal key = ' + key + '\n'); - if (typeof data.modal_xulG_stack != 'undefined' && typeof data.modal_xulG_stack[key] != 'undefined') { - xulG = data.modal_xulG_stack[key][ data.modal_xulG_stack[key].length - 1 ]; + if (typeof xulG != 'undefined' && xulG.not_modal) { + // for interfaces that used to be modal but aren't now, do nothing + } else { + JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'}); + var key = location.pathname + location.search + location.hash; + //dump('xul_param, considering modal key = ' + key + '\n'); + if (typeof data.modal_xulG_stack != 'undefined' && typeof data.modal_xulG_stack[key] != 'undefined') { + xulG = data.modal_xulG_stack[key][ data.modal_xulG_stack[key].length - 1 ]; + } } } if (typeof xulG == 'object' && typeof xulG[ param_name ] != 'undefined') {