[open-ils-commits] r14330 - trunk/Open-ILS/xul/staff_client/chrome/content/OpenILS (phasefx)
svn at svn.open-ils.org
svn at svn.open-ils.org
Fri Oct 9 14:18:18 EDT 2009
Author: phasefx
Date: 2009-10-09 14:18:14 -0400 (Fri, 09 Oct 2009)
New Revision: 14330
Modified:
trunk/Open-ILS/xul/staff_client/chrome/content/OpenILS/global_util.js
Log:
If an element under the sway of persist_helper makes use of @command, poke the corresponding <command> 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:
<checkbox id="foo" oils_persist="checked" command="cmd_foo" />
Modified: trunk/Open-ILS/xul/staff_client/chrome/content/OpenILS/global_util.js
===================================================================
--- trunk/Open-ILS/xul/staff_client/chrome/content/OpenILS/global_util.js 2009-10-09 15:29:18 UTC (rev 14329)
+++ trunk/Open-ILS/xul/staff_client/chrome/content/OpenILS/global_util.js 2009-10-09 18:18:14 UTC (rev 14330)
@@ -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 <command>\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.
}
More information about the open-ils-commits
mailing list