If an element under the sway of persist_helper makes use of @command, poke the corres...
authorphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 9 Oct 2009 18:18:14 +0000 (18:18 +0000)
committerphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 9 Oct 2009 18:18:14 +0000 (18:18 +0000)
So basically, this will work now:

    <checkbox id="foo" oils_persist="checked" command="cmd_foo" />

git-svn-id: svn://svn.open-ils.org/ILS/trunk@14330 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/xul/staff_client/chrome/content/OpenILS/global_util.js

index 04bec66..48a5186 100644 (file)
                     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.
             }