From acc46547d50e87de06adaf28ba0b6fee349b6a40 Mon Sep 17 00:00:00 2001 From: phasefx Date: Fri, 9 Oct 2009 18:18:14 +0000 Subject: [PATCH] If an element under the sway of persist_helper makes use of @command, poke the corresponding with an event if needed, and add a special event listener to it for monitoring the state of the original element. So basically, this will work now: git-svn-id: svn://svn.open-ils.org/ILS/trunk@14330 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../chrome/content/OpenILS/global_util.js | 88 ++++++++++++++++------ 1 file changed, 63 insertions(+), 25 deletions(-) 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 04bec66f14..48a518665f 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 @@ -65,39 +65,77 @@ if (value) nodes[i].setAttribute( attribute_list[j], value ); } if ( (nodes[i].nodeName == 'checkbox' || nodes[i].nodeName == 'menuitem') && attribute_list.indexOf('checked') > -1) { + var cmd = nodes[i].getAttribute('command'); + var cmd_el = document.getElementById(cmd); if (nodes[i].disabled == false && nodes[i].hidden == false) { var no_poke = nodes[i].getAttribute('oils_persist_no_poke'); if (no_poke && no_poke == 'true') { // Timing issue for some checkboxes; don't poke them with an event + dump('\tpersist_helper: not poking element with key = ' + key + '\n'); } else { - var evt = document.createEvent("Events"); - evt.initEvent( 'command', true, true ); - nodes[i].dispatchEvent(evt); + if (cmd_el) { + dump('\tpersist_helper: poking @command element for element with key = ' + key + '\n'); + var evt = document.createEvent("Events"); + evt.initEvent( 'command', true, true ); + cmd_el.dispatchEvent(evt); + } else { + dump('\tpersist_helper: poking element with key = ' + key + '\n'); + var evt = document.createEvent("Events"); + evt.initEvent( 'command', true, true ); + nodes[i].dispatchEvent(evt); + } } } - nodes[i].addEventListener( - 'command', - function(bk) { - return function(ev) { - try { - netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); - var key = bk + 'checked'; - var value; - if (ev.target.nodeName == 'checkbox') { - value = ev.target.checked; - } else { - value = ev.target.getAttribute('checked'); // menuitem with type="checkbox" + if (cmd_el) { + cmd_el.addEventListener( + 'command', + function (bk,explicit_original_node) { + return function(ev) { + try { + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); + if (ev.explicitOriginalTarget != explicit_original_node) return; + var key = bk + 'checked'; + var value; + if (ev.explicitOriginalTarget.nodeName == 'checkbox') { + value = ev.explicitOriginalTarget.checked; + } else { + value = ev.explicitOriginalTarget.getAttribute('checked'); // menuitem with type="checkbox" + } + ev.explicitOriginalTarget.setAttribute( 'checked', value ); + prefs.setCharPref( key, value ); + dump('persist_helper: setting key = ' + key + ' value = ' + value + ' for checkbox/menuitem via \n'); + } catch(E) { + alert('Error in persist_helper(), checkbox/menuitem -> command, command event listener: ' + E); } - ev.target.setAttribute( 'checked', value ); - prefs.setCharPref( key, value ); - dump('persist_helper: setting key = ' + key + ' value = ' + value + ' for checkbox/menuitem\n'); - } catch(E) { - alert('Error in persist_helper(), checkbox/menuitem command event listener: ' + E); - } - }; - }(base_key), - false - ); + }; + }( base_key, nodes[i] ), + false + ); + } else { + nodes[i].addEventListener( + 'command', + function(bk) { + return function(ev) { + try { + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); + var key = bk + 'checked'; + var value; + if (ev.target.nodeName == 'checkbox') { + value = ev.target.checked; + } else { + value = ev.target.getAttribute('checked'); // menuitem with type="checkbox" + } + ev.target.setAttribute( 'checked', value ); + prefs.setCharPref( key, value ); + dump('persist_helper: setting key = ' + key + ' value = ' + value + ' for checkbox/menuitem\n'); + } catch(E) { + alert('Error in persist_helper(), checkbox/menuitem command event listener: ' + E); + } + }; + }(base_key), + false + ); + } } // TODO: Need to add event listeners for window resizing, splitter repositioning, grippy state, etc. } -- 2.11.0