From 0e06c711fe06322a44f8a019d63027c92201463a Mon Sep 17 00:00:00 2001 From: Jason Etheridge <jason@esilibrary.com> Date: Thu, 22 Mar 2012 00:12:34 -0400 Subject: [PATCH] utility functions for Javascript Shell win_list() returns an array of "eg_main" chrome windows get_tab() takes two forms: get_tab(chrome_window,tab_index) get_tab(tab_index) The latter invocation assumes the first chrome window returned by win_list(). get_tab returns an object with the keys 'name' and 'content', pointing to the tab label and the tab panel -> iframe -> contentWindow, respectively. So let's say you had a patron account open in tab 1, and the Javascript Shell open in tab 2. In the shell, you could do: var o = get_tab(1); o.name might contain something like 1 Patron: Circulator, Ima and you could do this to refresh that interface: o.content.g.patron.refresh_all() Signed-off-by: Jason Etheridge <jason@esilibrary.com> Signed-off-by: Thomas Berezansky <tsbere@mvlc.org> --- .../xul/staff_client/chrome/content/util/shell.js | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/Open-ILS/xul/staff_client/chrome/content/util/shell.js b/Open-ILS/xul/staff_client/chrome/content/util/shell.js index eadc2285de..7dda6e380a 100644 --- a/Open-ILS/xul/staff_client/chrome/content/util/shell.js +++ b/Open-ILS/xul/staff_client/chrome/content/util/shell.js @@ -9,6 +9,38 @@ _out, tooManyMatches = null, lastError = null; +function win_list() { + var list = []; + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); + var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]. + getService(Components.interfaces.nsIWindowMediator); + var enumerator = wm.getEnumerator('eg_menu'); + while(enumerator.hasMoreElements()) { + targetwindow = enumerator.getNext(); + list.push(targetwindow); + } + return list; +} + +function get_tab(a,b) { + + var win; + var idx; + + if (typeof b == 'undefined') { + idx = a; + win = win_list()[0]; + } else { + win = a; + idx = b; + } + + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); + var tabs = win.document.getElementById('main_tabs'); + var panels = win.document.getElementById('main_panels'); + return { 'name' : tabs.childNodes[idx].getAttribute('label'), 'content' : panels.childNodes[idx].firstChild.contentWindow }; +} + function refocus() { _in.blur(); // Needed for Mozilla to scroll correctly. -- 2.11.0