LP#1086458: add more event listener tracking
authorGalen Charlton <gmc@esilibrary.com>
Thu, 24 Jan 2013 17:27:34 +0000 (12:27 -0500)
committerBen Shum <bshum@biblio.org>
Mon, 4 Mar 2013 19:49:33 +0000 (14:49 -0500)
util.list and util.controller now have cleanup()
methods that can be invoked to unregister the event
listeners they create.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Signed-off-by: Ben Shum <bshum@biblio.org>
Open-ILS/xul/staff_client/chrome/content/util/controller.js
Open-ILS/xul/staff_client/chrome/content/util/list.js

index facecfa..3174b23 100644 (file)
@@ -16,6 +16,7 @@ util.controller.prototype = {
 
         if (typeof params.control_map == 'undefined') throw('util.controller.init: No control_map');
 
+        this.event_listeners = new EventListenerList();
         this.control_map = params.control_map;
         this.window_knows_me_by = params.window_knows_me_by;
         this.render_list = [];
@@ -38,7 +39,7 @@ util.controller.prototype = {
                                 cmd.setAttribute(ev_type, s);
                                 this.cmds[i] = this.control_map[i][1];
                             break;
-                            default: cmd.addEventListener(ev_type,this.control_map[i][1],false);
+                            default: this.event_listeners.add(cmd, ev_type,this.control_map[i][1],false);
                         }
                     }
                 }
@@ -47,6 +48,11 @@ util.controller.prototype = {
         }
     },
 
+    'cleanup' : function() {
+        var obj = this;
+        obj.event_listeners.removeAll();
+    },
+
     'render' : function(id,param) {
         for (var i in this.render_list) {
             try {
index e9bf29a..8166016 100644 (file)
@@ -36,6 +36,7 @@ util.list.prototype = {
 
         var obj = this;
         obj.scratch_data = {};
+        obj.event_listeners = new EventListenerList();
 
         // If set, save and restore columns as if the tree/list id was the value of columns_saved_under
         obj.columns_saved_under = params.columns_saved_under;
@@ -128,7 +129,8 @@ util.list.prototype = {
                 treecols.appendChild(treecol);
 
                 if (this.columns[i].type == 'checkbox') {
-                    treecol.addEventListener(
+                    obj.event_listeners.add(
+                        treecol,
                         'click',
                         function(ev) {
                             setTimeout(
@@ -143,7 +145,8 @@ util.list.prototype = {
                         false
                     );
                 } else {
-                    treecol.addEventListener(
+                    obj.event_listeners.add(
+                        treecol,
                         'sort_first_asc',
                         function(ev) {
                             dump('sort_first_asc\n');
@@ -157,7 +160,8 @@ util.list.prototype = {
                         },
                         false
                     );
-                    treecol.addEventListener(
+                    obj.event_listeners.add(
+                        treecol,
                         'sort_first_desc',
                         function(ev) {
                             dump('sort_first_desc\n');
@@ -171,7 +175,8 @@ util.list.prototype = {
                         },
                         false
                     );
-                    treecol.addEventListener(
+                    obj.event_listeners.add(
+                        treecol,
                         'sort_next_asc',
                         function(ev) {
                             dump('sort_next_asc\n');
@@ -184,7 +189,8 @@ util.list.prototype = {
                         },
                         false
                     );
-                    treecol.addEventListener(
+                    obj.event_listeners.add(
+                        treecol,
                         'sort_next_desc',
                         function(ev) {
                             dump('sort_next_desc\n');
@@ -198,7 +204,8 @@ util.list.prototype = {
                         false
                     );
 
-                    treecol.addEventListener(
+                    obj.event_listeners.add(
+                        treecol,
                         'click', 
                         function(ev) {
                             if (ev.button == 2 /* context menu click */ || ev.target.getAttribute('no_sort')) {
@@ -233,7 +240,8 @@ util.list.prototype = {
                         false
                     );
 
-                    treecol.addEventListener(
+                    obj.event_listeners.add(
+                        treecol,
                         'sort',
                         function(ev) {
                             if (!obj.first_sort) {
@@ -281,7 +289,8 @@ util.list.prototype = {
         if (typeof params.on_checkbox_toggle == 'function') {
             this.on_checkbox_toggle = params.on_checkbox_toggle;
         }
-        this.node.addEventListener(
+        obj.event_listeners.add(
+            this.node,
             'select',
             function(ev) {
                 if (typeof params.on_select == 'function') {
@@ -296,14 +305,16 @@ util.list.prototype = {
             false
         );
         if (typeof params.on_click == 'function') {
-            this.node.addEventListener(
+            obj.event_listeners.add(
+                this.node,
                 'click',
                 params.on_click,
                 false
             );
         }
         if (typeof params.on_dblclick == 'function') {
-            this.node.addEventListener(
+            obj.event_listeners.add(
+                this.node,
                 'dblclick',
                 params.on_dblclick,
                 false
@@ -311,23 +322,27 @@ util.list.prototype = {
         }
 
         /*
-        this.node.addEventListener(
+        obj.event_listeners.add(
+            this.node,
             'mousemove',
             function(ev) { obj.detect_visible(); },
             false
         );
         */
-        this.node.addEventListener(
+        obj.event_listeners.add(
+            this.node,
             'keypress',
             function(ev) { obj.auto_retrieve(); },
             false
         );
-        this.node.addEventListener(
+        obj.event_listeners.add(
+            this.node,
             'click',
             function(ev) { obj.auto_retrieve(); },
             false
         );
-        window.addEventListener(
+        obj.event_listeners.add(
+            window,
             'resize',
             function(ev) { obj.auto_retrieve(); },
             false
@@ -345,7 +360,7 @@ util.list.prototype = {
         slider.addEventListener('command',function(){alert('slider command');},false);
         slider.addEventListener('scroll',function(){alert('slider scroll');},false);
         */
-        this.node.addEventListener('scroll',function(){ obj.auto_retrieve(); },false);
+        obj.event_listeners.add(this.node, 'scroll',function(){ obj.auto_retrieve(); },false);
 
         this.restores_columns(params);
     },
@@ -372,6 +387,11 @@ util.list.prototype = {
         }
     },
 
+    'cleanup' : function () {
+        var obj = this;
+        obj.event_listeners.removeAll();
+    },
+
     'save_columns' : function (params) {
         var obj = this;
         if (obj.data.hash.aous['gui.disable_local_save_columns']) {
@@ -628,7 +648,8 @@ util.list.prototype = {
         obj.put_retrieving_label(treerow);
 
         if (typeof params.retrieve_row == 'function' || typeof this.retrieve_row == 'function') {
-            treerow.addEventListener(
+            obj.event_listeners.add(
+                treerow,
                 'flesh',
                 function() {
 
@@ -692,7 +713,8 @@ util.list.prototype = {
                 }
             }
         } else {
-            treerow.addEventListener(
+            obj.event_listeners.add(
+                treerow,
                 'flesh',
                 function() {
                     //dump('fleshing anon\n');
@@ -790,7 +812,8 @@ util.list.prototype = {
 
             s += 'found a retrieve_row function\n';
 
-            treerow.addEventListener(
+            obj.event_listeners.add(
+                treerow,
                 'flesh',
                 function() {
 
@@ -858,7 +881,8 @@ util.list.prototype = {
 
             s += 'did not find a retrieve_row function\n';
 
-            treerow.addEventListener(
+            obj.event_listeners.add(
+                treerow,
                 'flesh',
                 function() {
                     //dump('fleshing anon\n');
@@ -1917,7 +1941,8 @@ util.list.prototype = {
         try {
             var x = document.getElementById(obj.node.id + '_clipfield');
             if (x) {
-                x.addEventListener(
+                obj.event_listeners.add(
+                    x,
                     'command',
                     function() {
                         obj.clipboard(params);
@@ -1930,7 +1955,8 @@ util.list.prototype = {
             }
             x = document.getElementById(obj.node.id + '_csv_to_clipboard');
             if (x) {
-                x.addEventListener(
+                obj.event_listeners.add(
+                    x,
                     'command',
                     function() {
                         obj.dump_csv_to_clipboard(params);
@@ -1943,7 +1969,8 @@ util.list.prototype = {
             }
             x = document.getElementById(obj.node.id + '_csv_to_printer');
             if (x) {
-                x.addEventListener(
+                obj.event_listeners.add(
+                    x,
                     'command',
                     function() {
                         obj.dump_csv_to_printer(params);
@@ -1956,7 +1983,8 @@ util.list.prototype = {
             }
             x = document.getElementById(obj.node.id + '_extended_to_printer');
             if (x) {
-                x.addEventListener(
+                obj.event_listeners.add(
+                    x,
                     'command',
                     function() {
                         obj.dump_extended_format_to_printer(params);
@@ -1970,7 +1998,8 @@ util.list.prototype = {
 
             x = document.getElementById(obj.node.id + '_csv_to_file');
             if (x) {
-                x.addEventListener(
+                obj.event_listeners.add(
+                    x,
                     'command',
                     function() {
                         obj.dump_csv_to_file(params);
@@ -1983,7 +2012,8 @@ util.list.prototype = {
             }
             x = document.getElementById(obj.node.id + '_save_columns');
             if (x) {
-                x.addEventListener(
+                obj.event_listeners.add(
+                    x,
                     'command',
                     function() {
                         obj.save_columns(params);