From f6186329c190bc8c60fad61bb6850ae025ab2687 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Fri, 8 Oct 2021 14:54:46 -0700 Subject: [PATCH] message_admin - Properly cleanup the `onPreview` listener Use-case: 1. Open the editor a message template (eg `#/edit?id=17&lang=fr_FR`). This renders the edit screen. 2. Click on the "Preview" icon. 3. Close the "Preview" dialog. 4. Change the URL to navigate internally to another template (eg `#/edit?id=17&lang=de_DE`). This renders the edit screen again. 5. Click on the "Preview" icon. Before: * It subsequently opens two copies of the "Preview" dialog (each with slightly different options). Initially, you see one dialog. When that close, you will see the other dialog. * As you proceed through closing the dialogs, you may get console warnings because the dialogs have the same name -- and they consequently trip-up each other. After: * It only opens one copy of the "Preview" dialog. Technical Details: * When rendering the setup screen (`#1`/`#4`), it registers a listener which will handle the "Preview" clicks. But the listener is not properly unregistered. Consequently, old listeners hang around. So the click at step `#5` calls both the old+new listeners, creating two dialogs. --- ext/message_admin/ang/crmMsgadm/Edit.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ext/message_admin/ang/crmMsgadm/Edit.js b/ext/message_admin/ang/crmMsgadm/Edit.js index 7c77d2c727..73ff2be223 100644 --- a/ext/message_admin/ang/crmMsgadm/Edit.js +++ b/ext/message_admin/ang/crmMsgadm/Edit.js @@ -308,9 +308,9 @@ }); } - $rootScope.$on('previewMsgTpl', onPreview); - $rootScope.$on('$destroy', function (){ - $rootScope.$off('previewMsgTpl', onPreview); + var unreg = $rootScope.$on('previewMsgTpl', onPreview); + $scope.$on('$destroy', function (){ + unreg(); }); }); -- 2.25.1