LP#1086458: add way to clean up persist_helper event listeners
authorGalen Charlton <gmc@esilibrary.com>
Thu, 24 Jan 2013 17:02:57 +0000 (12:02 -0500)
committerBen Shum <bshum@biblio.org>
Mon, 4 Mar 2013 19:49:33 +0000 (14:49 -0500)
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Signed-off-by: Ben Shum <bshum@biblio.org>
Open-ILS/xul/staff_client/chrome/content/OpenILS/global_util.js

index 615108f..f7abba4 100644 (file)
             } else {
                 base_key_suffix = '';
             }
+            window.persist_helper_event_listeners = new EventListenerList();
 
             function gen_event_handler(etype,node) {
                 return function(ev) {
                     }
                 }
                 if (cmd_el) {
-                    cmd_el.addEventListener(
+                    window.persist_helper_event_listeners.add(cmd_el, 
                         'command',
                         gen_event_handler('command',cmd_el),
                         false
                     );
-                    cmd_el.addEventListener(
+                    window.persist_helper_event_listeners.add(cmd_el, 
                         'oils_persist',
                         gen_oils_persist_handler( base_key, nodes[i] ),
                         false
                         }
                     }
                     for (var j = 0; j < event_types.length; j++) {
-                        node.addEventListener(
+                        window.persist_helper_event_listeners.add(node, 
                             event_types[j],
                             gen_event_handler(event_types[j],node),
                             false
                         );
                     }
-                    node.addEventListener(
+                    window.persist_helper_event_listeners.add(node, 
                         'oils_persist',
                         gen_oils_persist_handler( base_key, node ),
                         false
         }
     }
 
+    function persist_helper_cleanup() {
+        try {
+            window.persist_helper_event_listeners.removeAll();
+        } catch(E) {
+            alert('Error in persist_helper_cleanup(): ' + E);
+        }
+    }
+
     function getKeys(o) {
         var keys = [];
         for (var k in o) keys.push(k);