LP#1086458: clean up after event listeners in circ/patron interface
authorGalen Charlton <gmc@esilibrary.com>
Sat, 19 Jan 2013 05:46:32 +0000 (00:46 -0500)
committerBen Shum <bshum@biblio.org>
Mon, 4 Mar 2013 19:49:33 +0000 (14:49 -0500)
Upon window unload, now removes event listeners, both ones explicitly
created by the page JavsScript as well as ones created by
util.list, util.controller, and persist_helper().

The same approach of defining cleanup fnctions used by unload
events can be applied to the rest of the staff client, but
this patch focuses on circulation first.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Signed-off-by: Ben Shum <bshum@biblio.org>
48 files changed:
Open-ILS/xul/staff_client/server/circ/checkout.js
Open-ILS/xul/staff_client/server/circ/checkout.xul
Open-ILS/xul/staff_client/server/locale/en-US/patron.properties
Open-ILS/xul/staff_client/server/patron/barcode_entry.xul
Open-ILS/xul/staff_client/server/patron/bill2.js
Open-ILS/xul/staff_client/server/patron/bill2.xul
Open-ILS/xul/staff_client/server/patron/bill_cc_info.xul
Open-ILS/xul/staff_client/server/patron/bill_check_info.xul
Open-ILS/xul/staff_client/server/patron/bill_details.js
Open-ILS/xul/staff_client/server/patron/bill_details.xul
Open-ILS/xul/staff_client/server/patron/bill_history.js
Open-ILS/xul/staff_client/server/patron/bill_history.xul
Open-ILS/xul/staff_client/server/patron/bill_wizard.js
Open-ILS/xul/staff_client/server/patron/bill_wizard.xul
Open-ILS/xul/staff_client/server/patron/display.js
Open-ILS/xul/staff_client/server/patron/display.xul
Open-ILS/xul/staff_client/server/patron/display_horiz.xul
Open-ILS/xul/staff_client/server/patron/edit_standing_penalty.js
Open-ILS/xul/staff_client/server/patron/edit_standing_penalty.xul
Open-ILS/xul/staff_client/server/patron/hold_cancel.js
Open-ILS/xul/staff_client/server/patron/hold_cancel.xul
Open-ILS/xul/staff_client/server/patron/hold_details.js
Open-ILS/xul/staff_client/server/patron/hold_details.xul
Open-ILS/xul/staff_client/server/patron/holds.js
Open-ILS/xul/staff_client/server/patron/holds.xul
Open-ILS/xul/staff_client/server/patron/info_group.js
Open-ILS/xul/staff_client/server/patron/info_group.xul
Open-ILS/xul/staff_client/server/patron/info_notes.xul
Open-ILS/xul/staff_client/server/patron/info_stat_cats.xul
Open-ILS/xul/staff_client/server/patron/info_surveys.xul
Open-ILS/xul/staff_client/server/patron/items.js
Open-ILS/xul/staff_client/server/patron/items.xul
Open-ILS/xul/staff_client/server/patron/new_standing_penalty.js
Open-ILS/xul/staff_client/server/patron/new_standing_penalty.xul
Open-ILS/xul/staff_client/server/patron/place_hold.js
Open-ILS/xul/staff_client/server/patron/place_hold.xul
Open-ILS/xul/staff_client/server/patron/search_form.js
Open-ILS/xul/staff_client/server/patron/search_form.xul
Open-ILS/xul/staff_client/server/patron/search_form_horiz.xul
Open-ILS/xul/staff_client/server/patron/search_result.js
Open-ILS/xul/staff_client/server/patron/search_result.xul
Open-ILS/xul/staff_client/server/patron/staged.js
Open-ILS/xul/staff_client/server/patron/staged.xul
Open-ILS/xul/staff_client/server/patron/standing_penalties.js
Open-ILS/xul/staff_client/server/patron/standing_penalties.xul
Open-ILS/xul/staff_client/server/patron/summary.js
Open-ILS/xul/staff_client/server/patron/summary.xul
Open-ILS/xul/staff_client/server/patron/user_buckets.xul

index 9b6089c..a1231a5 100644 (file)
@@ -16,6 +16,7 @@ circ.checkout.prototype = {
 
         var obj = this;
 
+        obj.event_listeners = new EventListenerList();
         obj.patron_id = params.patron_id;
 
         obj.auto_override_events = [];
@@ -87,7 +88,7 @@ circ.checkout.prototype = {
                                 e.appendChild( ml );
                                 ml.setAttribute('id','checkout_menulist');
                                 ml.setAttribute('accesskey','');
-                                ml.addEventListener(
+                                obj.event_listeners.add(ml,
                                     'command',
                                     function(ev) {
                                         var tb = obj.controller.view.checkout_barcode_entry_textbox;
@@ -269,6 +270,12 @@ circ.checkout.prototype = {
 
     },
 
+    'cleanup' : function() {
+        var obj = this;
+        obj.controller.cleanup();
+        obj.event_listeners.removeAll();
+    },
+
     'check_disable' : function() {
         var obj = this;
         try {
index 75c8a55..c1ba2ee 100644 (file)
@@ -21,6 +21,7 @@
 
 <window id="checkout_win" 
     onload="try { my_init(); font_helper(); persist_helper(); } catch(E) { alert(E); }"
+    onunload="try { my_cleanup(); persist_helper_cleanup(); } catch(E) { alert(E); }"
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 
     <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
             }
         }
 
+        function my_cleanup() {
+            try {
+                g.checkout.cleanup();
+            } catch(E) {
+                try {
+                    g.error.standard_unexpected_error_alert('circ/checkout.xul',E);
+                } catch(F) {
+                    dump('FIXME: circ/checkout.xul -> ' + E + ' -> ' + F + '\n');
+                }
+            }
+        }
+
         function default_focus() {
             try {
                 var x = document.getElementById('checkout_barcode_entry_textbox');
index 567a40c..cee408d 100644 (file)
@@ -14,6 +14,7 @@ staff.patron.bill_interface.payment_pending.column_header=Payment Pending
 staff.patron.bill_cc_info.need_cc_number=You must provide a credit card number
 staff.patron.bill_cc_info.need_approval_code=You must provide an approval code or an imprint slip number
 staff.patron.bill_details.my_init.error=bill_details.xul, my_init:
+staff.patron.bill_details.my_cleanup.error=bill_details.xul, my_cleanup:
 staff.patron.bill_details.handle_edit_bill_note.note_dialog.title=Replacement Note
 staff.patron.bill_details.handle_edit_bill_note.note_dialog.prompt=Enter new note:
 staff.patron.bill_details.handle_edit_bill_note.failure=Note for selected bills not likely updated.
index bd8f077..d2e2405 100644 (file)
@@ -19,6 +19,7 @@
 
 <window id="patron_barcode_entry_win" 
     onload="try { my_init(); font_helper(); persist_helper(); } catch(E) { alert(E); }"
+    onunload="try { my_cleanup(); persist_helper_cleanup(); } catch(E) { alert(E); }"
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 
     <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
@@ -42,7 +43,8 @@
                 JSAN.use('OpenILS.data'); g.data = new OpenILS.data(); g.data.init({'via':'stash'});
 
                 var tb = document.getElementById('barcode_tb');
-                tb.addEventListener(
+                window.barcode_entry_event_listeners = new EventListenerList();
+                window.barcode_entry_event_listeners.add(tb, 
                     'keypress',
                     function(ev) {
                         if (ev.keyCode == 13 || ev.keyCode == 77) {
             }
         }
 
+        function my_cleanup() {
+            try {
+                window.barcode_entry_event_listeners.removeAll();
+            } catch(E) {
+                var err_msg = $("commonStrings").getFormattedString('common.exception', ['patron/barcode_entry.xul', E]);
+                try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
+                alert(err_msg);
+            }
+        }
+
         function submit() {
             var tb;
             try {
index 83bf51c..10d6748 100644 (file)
@@ -14,6 +14,7 @@ function my_init() {
         g.data.voided_billings = []; g.data.stash('voided_billings');
 
         g.error.sdump('D_TRACE','my_init() for bill2.xul');
+        window.bill_event_listeners = new EventListenerList();
 
         document.title = $("patronStrings").getString('staff.patron.bill_history.my_init.current_bills');
 
@@ -63,45 +64,56 @@ function my_init() {
     }
 }
 
+function my_cleanup() {
+    try {
+        window.bill_event_listeners.removeAll();
+        g.bill_list.cleanup();
+    } catch(E) {
+        var err_msg = $("commonStrings").getFormattedString('common.exception', ['patron/bill2.xul', E]);
+        try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
+        alert(err_msg);
+    }
+}
+
 function event_listeners() {
     try {
-        $('details').addEventListener(
+        window.bill_event_listeners.add($('details'), 
             'command',
             handle_details,
             false
         );
 
-        $('add').addEventListener(
+        window.bill_event_listeners.add($('add'), 
             'command',
             handle_add,
             false
         );
 
-        $('voidall').addEventListener(
+        window.bill_event_listeners.add($('voidall'), 
             'command',
             handle_void_all,
             false
         );
 
-        $('refund').addEventListener(
+        window.bill_event_listeners.add($('refund'), 
             'command',
             handle_refund,
             false
         );
 
-        $('opac').addEventListener(
+        window.bill_event_listeners.add($('opac'), 
             'command',
             handle_opac,
             false
         );
 
-        $('copy_details').addEventListener(
+        window.bill_event_listeners.add($('copy_details'), 
             'command',
             handle_copy_details,
             false
         );
 
-        $('payment').addEventListener(
+        window.bill_event_listeners.add($('payment'), 
             'change',
             function(ev) {
                 if ($('payment_type').value == 'credit_payment') {
@@ -120,13 +132,13 @@ function event_listeners() {
             false
         );
 
-        $('payment').addEventListener(
+        window.bill_event_listeners.add($('payment'), 
             'focus',
             function(ev) { ev.target.select(); },
             false
         );
 
-        $('payment').addEventListener(
+        window.bill_event_listeners.add($('payment'), 
             'keypress',
             function(ev) {
                 if (! (ev.keyCode == 13 /* enter */ || ev.keyCode == 77 /* mac enter */) ) { return; }
@@ -136,7 +148,7 @@ function event_listeners() {
             false
         );
 
-        $('bill_patron_btn').addEventListener(
+        window.bill_event_listeners.add($('bill_patron_btn'), 
             'command',
             function() {
                 JSAN.use('util.window'); var win = new util.window();
@@ -154,7 +166,7 @@ function event_listeners() {
             false
         );
 
-        $('bill_history_btn').addEventListener(
+        window.bill_event_listeners.add($('bill_history_btn'), 
             'command',
             function() {
                 xulG.display_window.g.patron.right_deck.reset_iframe( 
@@ -171,7 +183,7 @@ function event_listeners() {
             false
         );
 
-        $('convert_change_to_credit').addEventListener(
+        window.bill_event_listeners.add($('convert_change_to_credit'), 
             'command',
             function(ev) {
                 if (ev.target.checked) {
@@ -183,7 +195,7 @@ function event_listeners() {
             false
         );
 
-        $('apply_payment_btn').addEventListener(
+        window.bill_event_listeners.add($('apply_payment_btn'), 
             'command',
             function(ev) {
                 try {
index 51167a5..32f0e0b 100644 (file)
@@ -22,6 +22,7 @@
 
 <window id="bill_interface_win" width="700" height="550" oils_persist="sizemode width height" active="true"
     onload="try{ font_helper(); persist_helper(); my_init(); } catch(E) { alert(E); }"
+    onunload="try{ my_cleanup(); persist_helper_cleanup(); } catch(E) { alert(E); }"
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 
     <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
index 3633745..8cb4804 100644 (file)
@@ -21,6 +21,7 @@
 <window id="patron_bill" title="&staff.patron.bill_cc_info.title;"
     orient="vertical" style="overflow: auto" oils_persist="height width sizemode"
     onload="try{info_init(); font_helper(); refresh_fields(); persist_helper(); }catch(E){alert(E);}"
+    onunload="try {  persist_helper_cleanup(); } catch(E) { alert(E) }"
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 
     <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
index 71738ec..373a74b 100644 (file)
@@ -21,6 +21,7 @@
 <window id="patron_bill" title="&staff.patron.bill_check_info.title;"
     orient="vertical" style="overflow: auto" oils_persist="height width sizemode"
     onload="try{info_init(); font_helper(); persist_helper(); }catch(E){alert(E);}"
+    onunload="try{ persist_helper_cleanup(); }catch(E){alert(E);}"
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 
     <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
index 52c4e06..fbb519f 100644 (file)
@@ -215,6 +215,8 @@ function my_init() {
 
         g.mbts_id = xul_param('mbts_id');
 
+        window.bill_details_event_listeners = new EventListenerList();
+
         retrieve_patron();
 
         retrieve_mbts();
@@ -224,19 +226,19 @@ function my_init() {
         retrieve_mb();
         retrieve_mp();
 
-        $('void').addEventListener(
+        window.bill_details_event_listeners.add($('void'), 
             'command',
             handle_void,
             false
         );
 
-        $('edit_bill_note').addEventListener(
+        window.bill_details_event_listeners.add($('edit_bill_note'), 
             'command',
             handle_edit_bill_note,
             false
         );
 
-        $('edit_payment_note').addEventListener(
+        window.bill_details_event_listeners.add($('edit_payment_note'), 
             'command',
             handle_edit_payment_note,
             false
@@ -247,6 +249,16 @@ function my_init() {
     }
 }
 
+function my_cleanup() {
+    try {
+        g.bill_list.cleanup();
+        g.payment_list.cleanup();
+        window.bill_details_event_listeners.removeAll();
+    } catch(E) {
+        try { g.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.bill_details.my_cleanup.error'),E); } catch(F) { alert(E); }
+    }
+}
+
 function handle_edit_bill_note() {
     try {
         var mb_list = util.functional.map_list(g.bill_list_selection, function(o){return g.mb_list[o].id();}); 
index a16d4e7..2454d35 100644 (file)
@@ -22,6 +22,7 @@
 
 <window id="bill_details_win" width="700" height="550" oils_persist="width height sizemode"
     onload="try{ my_init(); font_helper(); persist_helper(); } catch(E) { alert(E); }"
+    onunload="try { my_cleanup(); persist_helper_cleanup(); } catch(E) { alert(E); }"
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 
     <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
index 098a140..e1365cd 100644 (file)
@@ -237,6 +237,7 @@ function my_init() {
         g.funcs = []; g.bill_map = {}; g.payments_map = {};
 
         g.patron_id = xul_param('patron_id');
+        window.bill_history_event_listeners = new EventListenerList();
 
         init_lists();
 
@@ -244,31 +245,31 @@ function my_init() {
 
         retrieve_mbts_for_list();
 
-        $('details').addEventListener(
+        window.bill_history_event_listeners.add($('details'), 
             'command',
             gen_handle_details('bills'),
             false
         );
 
-        $('payments_details').addEventListener(
+        window.bill_history_event_listeners.add($('payments_details'), 
             'command',
             gen_handle_details('payments'),
             false
         );
 
-        $('copy_details').addEventListener(
+        window.bill_history_event_listeners.add($('copy_details'), 
             'command',
             gen_handle_copy_details('bills'),
             false
         );
 
-        $('copy_details_from_payments').addEventListener(
+        window.bill_history_event_listeners.add($('copy_details_from_payments'), 
             'command',
             gen_handle_copy_details('payments'),
             false
         );
 
-        $('add').addEventListener(
+        window.bill_history_event_listeners.add($('add'), 
             'command',
             handle_add,
             false
@@ -284,6 +285,19 @@ function my_init() {
     }
 }
 
+function my_cleanup() {
+    try {
+        g.bill_list.cleanup();
+        g.payments_list.cleanup();
+        window.bill_history_event_listeners.removeAll();
+    } catch(E) {
+        var err_msg = $("commonStrings").getFormattedString('common.exception', ['patron/bill_history.xul', E]);
+        try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
+        alert(err_msg);
+    }
+}
+
+
 function handle_add() {
     if(g.bill_list_selection.length > 1)
         var msg = $("patronStrings").getFormattedString('staff.patron.bill_history.handle_add.message_plural', [g.bill_list_selection]);
index 128ce1d..9671de1 100644 (file)
@@ -22,6 +22,7 @@
 
 <window id="bill_history_win" width="700" height="550" oils_persist="sizemode width height"
     onload="try{ my_init(); font_helper(); persist_helper(); } catch(E) { alert(E); }"
+    onunload="try { my_cleanup(); persist_helper_cleanup(); } catch(E) { alert(E); }"
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 
     <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
index 1dc3147..25ef0a9 100644 (file)
@@ -116,7 +116,8 @@ function patron_bill_init() {
         );
         ml.setAttribute('id','billing_type');
         document.getElementById('menu_placeholder').appendChild(ml);
-        ml.addEventListener(
+        window.bill_wizard_event_listeners = new EventListenerList();
+        window.bill_wizard_event_listeners.add(ml, 
             'command',
             function() {
                 if ( g.OpenILS.data.hash.cbt[ ml.value ] ) {
@@ -155,6 +156,17 @@ function patron_bill_init() {
 
 }
 
+function patron_bill_cleanup() {
+    try {
+        window.bill_wizard_event_listeners.removeAll();
+    } catch(E) {
+        var err_msg = $("commonStrings").getFormattedString('common.exception', ['patron/bill_wizard.xul', E]);
+        try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
+        alert(err_msg);
+    }
+
+}
+
 function patron_bill_finish() {
     try {
         var do_not_process_bill = xul_param('do_not_process_bill');
index 126f021..44cb12a 100644 (file)
@@ -22,6 +22,7 @@
 <window id="patron_bill" title="&staff.patron.bill_wizard.title;"
     orient="vertical" style="overflow: auto" oils_persist="width height sizemode"
     onload="try { patron_bill_init(); font_helper(); persist_helper(); } catch(E) { alert(E); }" width="700" height="550"
+    onunload="try { patron_bill_cleanup(); persist_helper_cleanup(); } catch(E) { alert(E); }"
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 
     <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
index 33fead8..74e53fc 100644 (file)
@@ -24,6 +24,7 @@ patron.display.prototype = {
 
         var obj = this;
 
+        obj.event_listeners = new EventListenerList();
         obj.barcode = params['barcode'];
         obj.id = params['id'];
 
@@ -604,22 +605,22 @@ patron.display.prototype = {
             }
         );
 
-        var x = document.getElementById("PatronNavBar_checkout");
-        x.addEventListener( 'focus', function(xx) { return function() { try { document.getElementById("PatronNavBarScrollbox").ensureElementIsVisible(xx); } catch(E) {}; } }(x), false);
-        var x = document.getElementById("PatronNavBar_refresh");
-        x.addEventListener( 'focus', function(xx) { return function() { try { document.getElementById("PatronNavBarScrollbox").ensureElementIsVisible(xx); } catch(E) {}; } }(x), false);
-        var x = document.getElementById("PatronNavBar_items");
-        x.addEventListener( 'focus', function(xx) { return function() { try { document.getElementById("PatronNavBarScrollbox").ensureElementIsVisible(xx); } catch(E) {}; } }(x), false);
-        var x = document.getElementById("PatronNavBar_holds");
-        x.addEventListener( 'focus', function(xx) { return function() { try { document.getElementById("PatronNavBarScrollbox").ensureElementIsVisible(xx); } catch(E) {}; } }(x), false);
-        var x = document.getElementById("PatronNavBar_other");
-        x.addEventListener( 'focus', function(xx) { return function() { try { document.getElementById("PatronNavBarScrollbox").ensureElementIsVisible(xx); } catch(E) {}; } }(x), false);
-        var x = document.getElementById("PatronNavBar_edit");
-        x.addEventListener( 'focus', function(xx) { return function() { try { document.getElementById("PatronNavBarScrollbox").ensureElementIsVisible(xx); } catch(E) {}; } }(x), false);
-        var x = document.getElementById("PatronNavBar_bills");
-        x.addEventListener( 'focus', function(xx) { return function() { try { document.getElementById("PatronNavBarScrollbox").ensureElementIsVisible(xx); } catch(E) {}; } }(x), false);
-        var x = document.getElementById("PatronNavBar_messages");
-        x.addEventListener( 'focus', function(xx) { return function() { try { document.getElementById("PatronNavBarScrollbox").ensureElementIsVisible(xx); } catch(E) {}; } }(x), false);
+        var make_listener = function(xx) {
+            return function() { 
+                try { document.getElementById("PatronNavBarScrollbox").ensureElementIsVisible(xx); } catch(E) {}; 
+            }
+        };
+
+        
+        var need_focus_listeners = [
+            'PatronNavBar_checkout', 'PatronNavBar_refresh', 'PatronNavBar_items', 'PatronNavBar_holds',
+            'PatronNavBar_other', 'PatronNavBar_edit', 'PatronNavBar_bills', 'PatronNavBar_messages'
+        ];
+        for (var i = 0; i < need_focus_listeners.length; i++) {
+            var elementID = need_focus_listeners[i];
+            var x = document.getElementById(elementID);
+            obj.event_listeners.add(x, 'focus', make_listener(x), false);
+        }
 
         if (obj.barcode || obj.id) {
             if (typeof window.xulG == 'object' && typeof window.xulG.set_tab_name == 'function') {
@@ -685,6 +686,12 @@ patron.display.prototype = {
         }
     },
 
+    'cleanup' : function( params ) {
+        var obj = this;
+        obj.controller.cleanup();
+        obj.event_listeners.removeAll();
+    },
+
     'reset_nav_styling' : function(btn,dont_hide_summary) {
         try {
             if (!dont_hide_summary) { dont_hide_summary = false; }
index e0861db..65a1a74 100644 (file)
@@ -21,6 +21,7 @@
 
 <window id="patron_display_win" 
     onload="try { my_init(); font_helper(); persist_helper(); } catch(E) { alert(E); }"
+    onunload="try { my_cleanup(); persist_helper_cleanup(); } catch(E) { alert(E); }"
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 
     <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
             }
         }
 
+        function my_cleanup() {
+            try {
+                g.patron.cleanup();
+            } catch(E) {
+                var err_msg = $("commonStrings").getFormattedString('common.exception', ['patron/display.xul', E]);
+                try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
+                alert(err_msg);
+            }
+        }
+
         function default_focus() {
             setTimeout(
                 function() {
index 1c53834..52aa0b6 100644 (file)
@@ -21,6 +21,7 @@
 
 <window id="patron_display_win" 
     onload="try { my_init(); font_helper(); persist_helper(); } catch(E) { alert(E); }"
+    onunload="try { my_cleanup(); persist_helper_cleanup(); } catch(E) { alert(E); }"
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 
     <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
             }
         }
 
+        function my_cleanup() {
+            try {
+                g.patron.cleanup();
+            } catch(E) {
+                var err_msg = $("commonStrings").getFormattedString('common.exception', ['patron/display.xul', E]);
+                try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
+                alert(err_msg);
+            }
+        }
+
         function default_focus() {
             setTimeout(
                 function() {
index b2d60fd..0ae197b 100644 (file)
@@ -48,7 +48,8 @@ function edit_penalty_init() {
         }
 
         /* set widget behavior */
-        document.getElementById('csp_menulist').addEventListener(
+        window.edit_standing_penalty_event_listeners = new EventListenerList();
+        window.edit_standing_penalty_event_listeners.add(document.getElementById('csp_menulist'), 
             'command',
             function() {
                 document.getElementById('note_btn').checked = false;
@@ -57,7 +58,7 @@ function edit_penalty_init() {
             },
             false
         );
-        document.getElementById('note_btn').addEventListener(
+        window.edit_standing_penalty_event_listeners.add(document.getElementById('note_btn'), 
             'command', 
             function() { 
                 document.getElementById('csp_menulist').setAttribute('label',''); 
@@ -65,7 +66,7 @@ function edit_penalty_init() {
             }, 
             false
         );
-        document.getElementById('alert_btn').addEventListener(
+        window.edit_standing_penalty_event_listeners.add(document.getElementById('alert_btn'), 
             'command', 
             function() { 
                 document.getElementById('csp_menulist').setAttribute('label',''); 
@@ -73,7 +74,7 @@ function edit_penalty_init() {
             }, 
             false
         );
-        document.getElementById('block_btn').addEventListener(
+        window.edit_standing_penalty_event_listeners.add(document.getElementById('block_btn'), 
             'command', 
             function() { 
                 document.getElementById('csp_menulist').setAttribute('label',''); 
@@ -81,10 +82,10 @@ function edit_penalty_init() {
             }, 
             false
         );
-        document.getElementById('cancel_btn').addEventListener(
+        window.edit_standing_penalty_event_listeners.add(document.getElementById('cancel_btn'), 
             'command', function() { window.close(); }, false
         );
-        document.getElementById('apply_btn').addEventListener(
+        window.edit_standing_penalty_event_listeners.add(document.getElementById('apply_btn'), 
             'command', 
             function() {
                 var note = document.getElementById('note_tb').value;
@@ -113,6 +114,16 @@ function edit_penalty_init() {
 
 }
 
+function edit_penalty_cleanup() {
+    try {
+        window.edit_standing_penalty_event_listeners.removeAll();
+    } catch(E) {
+        var err_prefix = 'standing_penalties.js -> penalty_cleanup() : ';
+        if (error) error.standard_unexpected_error_alert(err_prefix,E); else alert(err_prefix + E);
+    }
+
+}
+
 function build_penalty_menu() {
     try {
 
index d27c001..771ae57 100644 (file)
@@ -19,6 +19,7 @@
 
 <window id="edit_penalty_win" 
     onload="try { edit_penalty_init(); font_helper(); persist_helper(); } catch(E) { alert(E); }"
+    onunload="try { edit_penalty_cleanup(); persist_helper_cleanup(); } catch(E) { alert(E); }"
     oils_persist="height width sizemode"
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
     title="&staff.patron_display.edit_penalty_dialog.title;">
index 4adbcc1..2f24eaf 100644 (file)
@@ -25,10 +25,11 @@ function hold_cancel_init() {
         build_cancel_reason_menu();
 
         /* set widget behavior */
-        document.getElementById('cancel_btn').addEventListener(
+        window.hold_cancel_event_listeners = new EventListenerList();
+        window.hold_cancel_event_listeners.add(document.getElementById('cancel_btn'), 
             'command', function() { window.close(); }, false
         );
-        document.getElementById('apply_btn').addEventListener(
+        window.hold_cancel_event_listeners.add(document.getElementById('apply_btn'), 
             'command', 
             function() {
                 var note = document.getElementById('note_tb').value;
@@ -49,6 +50,16 @@ function hold_cancel_init() {
 
 }
 
+function hold_cancel_cleanup() {
+    try {
+        window.hold_cancel_event_listeners.removeAll();
+    } catch(E) {
+        var err_prefix = 'hold_cancel.js -> hold_cancel_cleanup() : ';
+        if (error) error.standard_unexpected_error_alert(err_prefix,E); else alert(err_prefix + E);
+    }
+
+}
+
 function build_cancel_reason_menu() {
     try {
 
index fb3830c..d2da173 100644 (file)
@@ -19,6 +19,7 @@
 
 <window id="hold_cancel_win" 
     onload="try { hold_cancel_init(); font_helper(); persist_helper(); } catch(E) { alert(E); }"
+    onunload="try { hold_cancel_cleanup(); persist_helper_cleanup(); } catch(E) { alert(E); }"
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
     title="&staff.hold_list.cancel_hold_dialog.title;">
 
index be34911..f583094 100644 (file)
@@ -29,6 +29,14 @@ function my_init() {
     }
 }
 
+function my_cleanup() {
+    try {
+        g.list.cleanup();
+    } catch(E) {
+        try { g.error.standard_unexpected_error_alert('/xul/server/patron/hold_notices.xul',E); } catch(E) { alert('FIXME: ' + js2JSON(E)); }
+    }
+}
+
 function fetch_and_render_all(do_not_refresh_parent_interface) {
     try {
         if (!xulG.ahr_id) { return; }
index 779b798..245a061 100644 (file)
@@ -20,6 +20,7 @@
 
 <window id="hold_notices_win" width="700" height="550" oils_persist="sizemode width height"
     onload="try{ my_init(); font_helper(); persist_helper(); } catch(E) { alert(E); }" title="&staff.patron.hold_notices.title;"
+    onunload="try { my_cleanup(); persist_helper_cleanup(); } catch(E) { alert(E); }"
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 
     <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
index 9b15aef..eaa29c4 100644 (file)
@@ -41,6 +41,7 @@ patron.holds.prototype = {
         var obj = this;
 
         dojo.require("openils.Util");
+        obj.event_listeners = new EventListenerList();
 
         obj.patron_id = params['patron_id'];
         obj.patron_barcode = params['patron_barcode'];
@@ -1632,6 +1633,13 @@ patron.holds.prototype = {
 
     },
 
+    'cleanup' : function() {
+        var obj = this;
+        obj.controller.cleanup();
+        obj.list.cleanup();
+        obj.event_listeners.removeAll();
+    },
+
     'determine_hold_interface_type' : function() {
         var obj = this;
         if (obj.patron_id) { /*************************************************** PATRON ******************************/
@@ -1825,7 +1833,7 @@ patron.holds.prototype = {
                 var ml = util.widgets.make_menulist( list_data[0], obj.data.list.au[0].ws_ou() );
                 ml.setAttribute('id','lib_menu');
                 x.appendChild( ml );
-                ml.addEventListener(
+                obj.event_listeners.add(ml, 
                     'command',
                     function(ev) {
                         obj.filter_lib = ev.target.value;
index f7f03fc..47eb367 100644 (file)
@@ -21,6 +21,7 @@
 
 <window id="holds_win" active="true" 
     onload="try { font_helper(); persist_helper(); my_init(); } catch(E) { alert(E); }"
+    onunload="try { my_cleanup(); persist_helper_cleanup(); } catch(E) { alert(E); }"
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 
     <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
             }
         }
 
+        function my_cleanup() {
+            try {
+                g.holds.cleanup();
+            } catch(E) {
+                var err_msg = $("commonStrings").getFormattedString('common.exception', ['patron/holds.xul', E]);
+                try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
+                alert(err_msg);
+            }
+        }
+
         function default_focus() { try { document.getElementById('holds_print').focus(); } catch(E) { } }
 
     ]]>
index 60f754f..a9407ce 100644 (file)
@@ -29,6 +29,16 @@ function my_init() {
     }
 }
 
+function my_cleanup() {
+    try {
+        list.cleanup();
+    } catch(E) {
+        var err_msg = $("commonStrings").getFormattedString('common.exception', ['patron/info_group.xul', E]);
+        try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
+        alert(err_msg);
+    }
+}
+
 function retrieve_money_summaries() {
     try {
         JSAN.use('util.money');
index 9e8777e..388efa2 100644 (file)
@@ -20,6 +20,7 @@
 
 <window id="patron_info_group_win" width="700" height="550" active="true"
     onload="try{ my_init(); font_helper(); persist_helper(); } catch(E) { alert(E); }"
+    onunload="try { my_cleanup(); persist_helper_cleanup(); } catch(E) { alert(E); }"
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 
     <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
index 133eec5..ab45e78 100644 (file)
@@ -20,6 +20,7 @@
 
 <window id="patron_info_win" width="700" height="550"
     onload="try{ my_init(); font_helper(); persist_helper(); } catch(E) { alert(E); }"
+    onunload="try { my_cleanup(); persist_helper_cleanup(); } catch(E) { alert(E); }"
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 
     <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
@@ -54,6 +55,8 @@
 
                 g.new_note = false;
 
+                g.info_notes_event_listeners = new EventListenerList();
+
                 refresh();
 
             } catch(E) {
             }
         }
 
+        function my_cleanup() {
+            try {
+                g.info_notes_event_listeners.removeAll();
+            } catch(E) {
+                var err_msg = $("commonStrings").getFormattedString('common.exception', ['patron/info_notes.xul', E]);
+                try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
+                alert(err_msg);
+            }
+        }
+
         function refresh() {
             retrieve_notes(); render_notes();
         }
                 btn1.setAttribute('label',$("patronStrings").getString('staff.patron.info_notes.render_notes.btn1.delete_note.label'));
                 btn1.setAttribute('image',"/xul/server/skin/media/images/up_arrow.gif");
 
-                btn1.addEventListener(
+                g.info_notes_event_listeners.add(btn1, 
                     'command',
                     function(id){ 
                         return function() { 
                     btn2.setAttribute('label',$("patronStrings").getString('staff.patron.info_notes.render_notes.btn2.print_note.label'));
                     btn2.setAttribute('image',"/xul/server/skin/media/images/up_arrow.gif");
 
-                    btn2.addEventListener(
+                    g.info_notes_event_listeners.add(btn2, 
                         'command',
                         function(id){ return function() { 
                             try {
index 4318313..400aa67 100644 (file)
@@ -20,6 +20,7 @@
 
 <window id="patron_info_stat_cats_win" width="700" height="550"
     onload="try{ my_init(); font_helper(); persist_helper(); } catch(E) { alert(E); }"
+    onunload="try{  persist_helper_cleanup(); } catch(E) { alert(E); }"
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 
     <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
index 66231c3..c0fb29b 100644 (file)
@@ -20,6 +20,7 @@
 
 <window id="patron_info_surveys_win" width="700" height="550"
     onload="try{ my_init(); font_helper(); persist_helper(); } catch(E) { alert(E); }"
+    onunload="try{ persist_helper_cleanup(); } catch(E) { alert(E); }"
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 
     <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
index 65e36b7..64d244d 100644 (file)
@@ -225,6 +225,12 @@ patron.items.prototype = {
         obj.controller.view.cmd_show_catalog2.setAttribute('disabled','true');
     },
 
+    'cleanup' : function() {
+        var obj = this;
+        obj.list.cleanup();
+        obj.list2.cleanup();
+    },
+
     'show_noncats' : function() {
         var obj = this; var checkout = {};
         try {
index 6faf415..0c7c537 100644 (file)
@@ -21,6 +21,7 @@
 
 <window id="items_win" active="true" 
     onload="try { my_init(); font_helper(); persist_helper(); } catch(E) { alert(E); }"
+    onunload="try { my_cleanup(); persist_helper_cleanup(); } catch(E) { alert(E); }"
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 
     <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
             }
         }
 
+        function my_cleanup() {
+            try {
+                g.items.cleanup();
+            } catch(E) {
+                var err_msg = $("commonStrings").getFormattedString('common.exception', ['patron/items.xul', E]);
+                try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
+                alert(err_msg);
+            }
+        }
+
         function default_focus() { try { var x = document.getElementById('noncat'); x.focus(); } catch(E) { try { g.error.sdump('D_ERROR','item.xul, default_focus: ' + E); } catch(F) { dump(E); } } }
 
     ]]>
index ddfd645..73c40cb 100644 (file)
@@ -30,7 +30,8 @@ function new_penalty_init() {
         }
 
         /* set widget behavior */
-        document.getElementById('csp_menulist').addEventListener(
+        window.new_standing_penalty_event_listeners = new EventListenerList();
+        window.new_standing_penalty_event_listeners.add(document.getElementById('csp_menulist'), 
             'command',
             function() {
                 document.getElementById('note_btn').checked = false;
@@ -39,7 +40,7 @@ function new_penalty_init() {
             },
             false
         );
-        document.getElementById('note_btn').addEventListener(
+        window.new_standing_penalty_event_listeners.add(document.getElementById('note_btn'), 
             'command', 
             function() { 
                 document.getElementById('csp_menulist').setAttribute('label',''); 
@@ -47,7 +48,7 @@ function new_penalty_init() {
             }, 
             false
         );
-        document.getElementById('alert_btn').addEventListener(
+        window.new_standing_penalty_event_listeners.add(document.getElementById('alert_btn'), 
             'command', 
             function() { 
                 document.getElementById('csp_menulist').setAttribute('label',''); 
@@ -55,7 +56,7 @@ function new_penalty_init() {
             }, 
             false
         );
-        document.getElementById('block_btn').addEventListener(
+        window.new_standing_penalty_event_listeners.add(document.getElementById('block_btn'), 
             'command', 
             function() { 
                 document.getElementById('csp_menulist').setAttribute('label',''); 
@@ -63,10 +64,10 @@ function new_penalty_init() {
             }, 
             false
         );
-        document.getElementById('cancel_btn').addEventListener(
+        window.new_standing_penalty_event_listeners.add(document.getElementById('cancel_btn'), 
             'command', function() { window.close(); }, false
         );
-        document.getElementById('apply_btn').addEventListener(
+        window.new_standing_penalty_event_listeners.add(document.getElementById('apply_btn'), 
             'command', 
             function() {
                 var note = document.getElementById('note_tb').value;
@@ -96,6 +97,16 @@ function new_penalty_init() {
 
 }
 
+function new_penalty_cleanup() {
+    try {
+        window.new_standing_penalty_event_listeners.removeAll();
+    } catch(E) {
+        var err_prefix = 'standing_penalties.js -> penalty_cleanup() : ';
+        if (error) error.standard_unexpected_error_alert(err_prefix,E); else alert(err_prefix + E);
+    }
+
+}
+
 function build_penalty_menu() {
     try {
 
index 7e9271b..cef7264 100644 (file)
@@ -19,6 +19,7 @@
 
 <window id="new_penalty_win" 
     onload="try { new_penalty_init(); font_helper(); persist_helper(); } catch(E) { alert(E); }"
+    onunload="try { new_penalty_cleanup(); persist_helper_cleanup(); } catch(E) { alert(E); }"
     oils_persist="height width sizemode"
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
     title="&staff.patron_display.apply_penalty_dialog.title;">
index 4dd8423..62049e7 100644 (file)
@@ -20,7 +20,8 @@ function my_init() {
         populate_hold_usr_textbox();
         populate_pickup_lib_menu();
 
-        $('request_btn').addEventListener(
+        window.place_hold_event_listeners = new EventListenerList();
+        window.place_hold_event_listeners.add($('request_btn'), 
             'command',
             function(ev) {
                 make_request(copy_ids,false);
@@ -35,6 +36,14 @@ function my_init() {
     }
 }
 
+function my_cleanup() {
+    try {
+        window.place_hold_event_listeners.removeAll();
+    } catch(E) {
+        alert('Error in place_hold.js, my_init(): ' + E);
+    }
+}
+
 function make_request(copy_ids,override) {
     try {
 
@@ -134,7 +143,7 @@ function handle_failures(failures,failed_targets) {
                 )
             );
             addCSSClass(err_msg,'click_link');
-            err_msg.addEventListener(
+            window.place_hold_event_listeners.add(err_msg, 
                 'click',
                 function(copy_ids) {
                     return function(ev) {
@@ -156,7 +165,7 @@ function handle_failures(failures,failed_targets) {
             );
             err_box.appendChild(retry_btn);
 
-            retry_btn.addEventListener(
+            window.place_hold_event_listeners.add(retry_btn, 
                 'command',
                 function(copy_ids) {
                     return function(ev) {
@@ -177,7 +186,7 @@ function handle_failures(failures,failed_targets) {
             );
             err_box.appendChild(override_btn);
 
-            override_btn.addEventListener(
+            window.place_hold_event_listeners.add(override_btn, 
                 'command',
                 function(copy_ids) {
                     return function(ev) {
@@ -200,13 +209,13 @@ function handle_failures(failures,failed_targets) {
 function set_remaining_event_listeners() {
     try {
 
-        $('hold_type_menu').addEventListener(
+        window.place_hold_event_listeners.add($('hold_type_menu'), 
             'command',
             function(ev) { oils_lock_page(); },
             false
         );
 
-        $('cancel_btn').addEventListener(
+        window.place_hold_event_listeners.add($('cancel_btn'), 
             'command',
             function(ev) { xulG.close_tab(); },
             false
@@ -231,7 +240,7 @@ function populate_hold_usr_textbox() {
         'value',
         patron.util.format_name(au_obj)
     );
-    $('hold_usr_textbox').addEventListener(
+    window.place_hold_event_listeners.add($('hold_usr_textbox'), 
         'change',
         function(ev) {
             try {
@@ -288,7 +297,7 @@ function populate_pickup_lib_menu() {
 
         $('pickup_lib_menu_placeholder').appendChild(ml);
 
-        ml.addEventListener(
+        window.place_hold_event_listeners.add(ml, 
             'command',
             function(ev) { oils_lock_page(); },
             false
index afa0a55..21c59b2 100644 (file)
@@ -19,6 +19,7 @@
 
 <window id="place_hold_win" 
     onload="try{my_init();font_helper();persist_helper();}catch(E){alert(E);}"
+    onunload="try { my_cleanup(); persist_helper_cleanup(); } catch(E) { alert(E); }"
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 
     <!-- /////////////////////////////////////////////////////////////////// -->
index 7f58952..5fadf55 100644 (file)
@@ -13,6 +13,7 @@ patron.search_form.prototype = {
     'init' : function( params ) {
 
         var obj = this;
+        obj.event_listeners = new EventListenerList();
 
         // The bulk of params.query is getting parsed/rendered by obj.controller.init below, and will be reconstituted from possibly modified XUL elements upon Submit.
         // But we're going to let search_limit and search_sort be configurable now by those spawning this interface, and let's assume there are no corresponding widgets for now.  
@@ -251,7 +252,7 @@ patron.search_form.prototype = {
         obj.controller.render();
         var nl = document.getElementsByTagName('textbox');
         for (var i = 0; i < nl.length; i++) {
-            nl[i].addEventListener('keypress',function(ev){
+            obj.event_listeners.add(nl[i], 'keypress', function(ev) {
                 if (ev.target.tagName != 'textbox') return;
                 if (ev.keyCode == 13 /* enter */ || ev.keyCode == 77 /* enter on a mac */) setTimeout( function() { obj.submit(); }, 0);
             },false);
@@ -273,7 +274,7 @@ patron.search_form.prototype = {
                 }
             )
         );
-        ml.addEventListener('command', function() {
+        obj.event_listeners.add(ml, 'command', function() {
                 ml.parentNode.setAttribute('value',ml.value);
                 var file = new util.file('patron_search_prefs.'+obj.OpenILS.data.server_unadorned);
                 util.widgets.save_attributes(file, { 'search_depth_ml' : [ 'value' ], 'inactive' : [ 'value' ] });
@@ -291,7 +292,7 @@ patron.search_form.prototype = {
         }
 
         var cb = obj.controller.view.inactive;
-        cb.addEventListener('command',function() { 
+        obj.event_listeners.add(cb, 'command',function() {
                 cb.setAttribute('value',cb.checked ? "true" : "false");
                 var file = new util.file('patron_search_prefs.'+obj.OpenILS.data.server_unadorned);
                 util.widgets.save_attributes(file, { 'search_depth_ml' : [ 'value' ], 'inactive' : [ 'value' ] });
@@ -315,7 +316,7 @@ patron.search_form.prototype = {
                     }
                 )
             );
-            profile_ml.addEventListener('command', function() {
+            obj.event_listeners.add(profile_ml, 'command', function() {
                     profile_ml.parentNode.setAttribute('value', profile_ml.value);
                 }, false
             );
@@ -331,6 +332,12 @@ patron.search_form.prototype = {
         }
     },
 
+    'cleanup' : function() {
+        var obj = this;
+        obj.controller.cleanup();
+        obj.event_listeners.removeAll();    
+    }, 
+
     'on_submit' : function(q) {
         var msg = 'Query = ' + q;
         this.error.sdump('D_PATRON', msg);
index 43a4fde..7822469 100644 (file)
@@ -21,6 +21,7 @@
 
 <window id="patron_search_form_win" 
     onload="try { my_init(); font_helper(); persist_helper(); } catch(E) { alert(E); }"
+    onunload="try { my_cleanup(); persist_helper_cleanup(); } catch(E) { alert(E); }"
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 
     <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
             }
         }
         
+        function my_cleanup() {
+            try {
+                g.search_form.cleanup();
+            } catch(E) {
+                var err_msg = $("commonStrings").getFormattedString('common.exception', ['patron/search_form.xul', E]);
+                try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
+                alert(err_msg);
+            }
+        }
+
         function default_focus() {
             setTimeout(
                 function() {
index 4e8f6af..ed0655b 100644 (file)
@@ -21,6 +21,7 @@
 
 <window id="patron_search_form_win" 
     onload="try { my_init(); font_helper(); persist_helper(); } catch(E) { alert(E); }"
+    onunload="try { my_cleanup(); persist_helper_cleanup(); } catch(E) { alert(E); }"
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 
     <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
                 alert(err_msg);
             }
         }
+
+        function my_cleanup() {
+            try {
+                g.search_form.cleanup();
+            } catch(E) {
+                var err_msg = $("commonStrings").getFormattedString('common.exception', ['patron/search_form.xul', E]);
+                try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
+                alert(err_msg);
+            }
+        }
         
         function default_focus() {
             setTimeout(
index e9e5f4a..8a77a71 100644 (file)
@@ -73,6 +73,25 @@ patron.search_result.prototype = {
             },'mailing_')
         );
 
+        obj.dblclick_handler = function(ev) {
+            JSAN.use('util.functional');
+            var sel = obj.list.retrieve_selection();
+            var list = util.functional.map_list(
+                sel,
+                function(o) { return o.getAttribute('retrieve_id'); }
+            );
+            obj.controller.view.cmd_sel_clip.setAttribute('disabled', list.length < 1 );
+            if (typeof obj.on_dblclick == 'function') {
+                obj.on_dblclick(list);
+            }
+            if (typeof window.xulG == 'object' && typeof window.xulG.on_dblclick == 'function') {
+                obj.error.sdump('D_PATRON','patron.search_result: Calling external .on_dblclick()\n');
+                window.xulG.on_dblclick(list);
+            } else {
+                obj.error.sdump('D_PATRON','patron.search_result: No external .on_dblclick()\n');
+            }
+        };
+
         obj.list.init(
             {
                 'columns' : columns,
@@ -101,24 +120,7 @@ patron.search_result.prototype = {
                         }
                     );
                 },
-                'on_dblclick' : function(ev) {
-                    JSAN.use('util.functional');
-                    var sel = obj.list.retrieve_selection();
-                    var list = util.functional.map_list(
-                        sel,
-                        function(o) { return o.getAttribute('retrieve_id'); }
-                    );
-                    obj.controller.view.cmd_sel_clip.setAttribute('disabled', list.length < 1 );
-                    if (typeof obj.on_dblclick == 'function') {
-                        obj.on_dblclick(list);
-                    }
-                    if (typeof window.xulG == 'object' && typeof window.xulG.on_dblclick == 'function') {
-                        obj.error.sdump('D_PATRON','patron.search_result: Calling external .on_dblclick()\n');
-                        window.xulG.on_dblclick(list);
-                    } else {
-                        obj.error.sdump('D_PATRON','patron.search_result: No external .on_dblclick()\n');
-                    }
-                },
+                'on_dblclick' : obj.dblclick_handler,
                 'on_select' : function(ev) {
                     JSAN.use('util.functional');
                     var sel = obj.list.retrieve_selection();
@@ -184,6 +186,12 @@ patron.search_result.prototype = {
         if (obj.query) obj.search(obj.query);
     },
 
+    'cleanup' : function( params ) {
+        var obj = this;
+        obj.controller.cleanup();
+        obj.list.cleanup();
+    },
+
     'search' : function(query) {
         var obj = this;
         var search_hash = {};
index 9546380..658eafc 100644 (file)
@@ -21,6 +21,7 @@
 
 <window id="patron_search_result_win" 
     onload="try { my_init(); font_helper(); persist_helper(); } catch(E) { alert(E); }"
+    onunload="try { my_cleanup(); persist_helper_cleanup(); } catch(E) { alert(E); }"
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 
     <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
             }
         }
 
+        function my_cleanup() {
+            try {
+                g.search_result.cleanup();
+            } catch(E) {
+                var err_msg = $("commonStrings").getFormattedString('common.exception', ['patron/search_result.xul', E]);
+                try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
+                alert(err_msg);
+            }
+        }
+
     ]]>
     </script>
 
index 45e1567..246a57d 100644 (file)
@@ -33,13 +33,14 @@ function staged_init() {
 
         dojo.require('openils.Util');
 
+        window.staged_event_listeners = new EventListenerList();
         populate_lib_menu();
         init_list();
         $('list_actions').appendChild( list.render_list_actions() );
         list.set_list_actions();
-        $('cmd_cancel').addEventListener('command', gen_event_handler('cancel'), false);
-        $('cmd_load').addEventListener('command', gen_event_handler('load'), false);
-        $('cmd_reload').addEventListener('command', function() { populate_list(); }, false);
+        window.staged_event_listeners.add($('cmd_cancel'), 'command', gen_event_handler('cancel'), false);
+        window.staged_event_listeners.add($('cmd_load'), 'command', gen_event_handler('load'), false);
+        window.staged_event_listeners.add($('cmd_reload'), 'command', function() { populate_list(); }, false);
         populate_list();
         default_focus();
 
@@ -49,6 +50,16 @@ function staged_init() {
     }
 }
 
+function staged_cleanup() {
+    try {
+        list.cleanup();
+        window.staged_event_listeners.removeAll();
+    } catch(E) {
+        var err_prefix = 'staged.js -> staged_cleanup() : ';
+        if (error) error.standard_unexpected_error_alert(err_prefix,E); else alert(err_prefix + E);
+    }
+}
+
 function populate_lib_menu() {
     try {
         JSAN.use('util.widgets');
@@ -64,7 +75,7 @@ function populate_lib_menu() {
             var ml = util.widgets.make_menulist( list_data[0], menu_lib );
             ml.setAttribute('id','lib_menu');
             x.appendChild( ml );
-            ml.addEventListener(
+            window.staged_event_listeners.add(ml, 
                 'command',
                 function(ev) {
                     menu_lib = ev.target.value;
index f7fb70f..18b3140 100644 (file)
@@ -18,6 +18,7 @@
 <?xul-overlay href="/xul/server/OpenILS/util_overlay.xul"?>
 
 <window id="staged_win" onload="try { font_helper(); persist_helper(); staged_init(); } catch(E) { alert(E); }"
+    onunload="try { staged_cleanup(); persist_helper_cleanup(); } catch(E) { alert(E); }"
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 
     <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
index d36edf4..7b9f714 100644 (file)
@@ -28,12 +28,13 @@ function penalty_init() {
 
         init_list();
         init_archived_list();
+        window.standing_penalties_event_listeners = new EventListenerList();
         document.getElementById('date1').year = document.getElementById('date1').year - 1;
-        document.getElementById('cmd_apply_penalty').addEventListener('command', handle_apply_penalty, false);
-        document.getElementById('cmd_remove_penalty').addEventListener('command', handle_remove_penalty, false);
-        document.getElementById('cmd_edit_penalty').addEventListener('command', handle_edit_penalty, false);
-        document.getElementById('cmd_archive_penalty').addEventListener('command', handle_archive_penalty, false);
-        document.getElementById('cmd_retrieve_archived_penalties').addEventListener('command', handle_retrieve_archived_penalties, false);
+        window.standing_penalties_event_listeners.add(document.getElementById('cmd_apply_penalty'), 'command', handle_apply_penalty, false);
+        window.standing_penalties_event_listeners.add(document.getElementById('cmd_remove_penalty'), 'command', handle_remove_penalty, false);
+        window.standing_penalties_event_listeners.add(document.getElementById('cmd_edit_penalty'), 'command', handle_edit_penalty, false);
+        window.standing_penalties_event_listeners.add(document.getElementById('cmd_archive_penalty'), 'command', handle_archive_penalty, false);
+        window.standing_penalties_event_listeners.add(document.getElementById('cmd_retrieve_archived_penalties'), 'command', handle_retrieve_archived_penalties, false);
         populate_list();
         default_focus();
 
@@ -43,6 +44,17 @@ function penalty_init() {
     }
 }
 
+function penalty_cleanup() {
+    try {
+        window.standing_penalties_event_listeners.removeAll();
+        list.cleanup();
+        archived_list.cleanup();
+    } catch(E) {
+        var err_prefix = 'standing_penalties.js -> penalty_cleanup() : ';
+        if (error) error.standard_unexpected_error_alert(err_prefix,E); else alert(err_prefix + E);
+    }
+}
+
 function init_list() {
     try {
 
index a1b5d90..5571298 100644 (file)
@@ -18,6 +18,7 @@
 <?xul-overlay href="/xul/server/OpenILS/util_overlay.xul"?>
 
 <window id="penalty_win" onload="try { penalty_init(); font_helper(); persist_helper(); } catch(E) { alert(E); }"
+    onunload="try { penalty_cleanup(); persist_helper_cleanup(); } catch(E) { alert(E); }"
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 
     <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
index 0b65cc4..6b73ff9 100644 (file)
@@ -19,6 +19,7 @@ patron.summary.prototype = {
     'init' : function( params ) {
 
         var obj = this;
+        obj.event_listeners = new EventListenerList();
 
         obj.barcode = params['barcode'];
         obj.id = params['id'];
@@ -901,7 +902,7 @@ patron.summary.prototype = {
             var caption = document.getElementById("PatronSummaryContact_caption");
             var arrow = document.getAnonymousNodes(caption)[0];
             var gb_content = document.getAnonymousNodes(caption.parentNode)[1];
-            arrow.addEventListener(
+            obj.event_listeners.add(arrow,
                 'click',
                 function() {
                     setTimeout(
@@ -930,6 +931,14 @@ patron.summary.prototype = {
         }
     },
 
+    'cleanup' : function() {
+        var obj = this;
+        if (typeof obj.group_list != 'undefined') obj.group_list.cleanup();
+        if (typeof obj.stat_cat_list != 'undefined') obj.stat_cat_list.cleanup();
+        obj.controller.cleanup();
+        obj.event_listeners.removeAll();
+    },
+
     'retrieve' : function() {
 
         try {
index cee959b..6990028 100644 (file)
@@ -20,7 +20,8 @@
 <?xul-overlay href="/xul/server/OpenILS/util_overlay.xul"?>
 
 <window id="patron_summary_win" 
-    onload="try { font_helper(); my_init(); persist_helper(); } catch(E) { alert(E); }" onunload="try { observer.unregister(); } catch(E) { alert(E); }"
+    onload="try { font_helper(); my_init(); persist_helper(); } catch(E) { alert(E); }" 
+    onunload="try { my_cleanup(); persist_helper_cleanup(); } catch(E) { alert(E); }"
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 
     <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
             }
         }
 
+        function my_cleanup() {
+            try {
+                observer.unregister();
+                g.summary.cleanup();
+            } catch(E) {
+                var err_msg = $("commonStrings").getFormattedString('common.exception', ['patron/summary.xul:my_init()', E]);
+                try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
+                alert(err_msg);
+            }
+        }
+
         function export_address(ev) {
             var action = ev.originalTarget.id;
             var a;
index 18eb8b6..d534d77 100644 (file)
@@ -19,6 +19,7 @@
 
 <window id="example_template_win" 
     onload="try { my_init(); font_helper(); persist_helper(); } catch(E) { alert(E); }"
+    onunload="try { persist_helper_cleanup(); } catch(E) { alert(E); }"
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 
     <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->