Skip to content

Commit

Permalink
message_admin - Properly cleanup the onPreview listener
Browse files Browse the repository at this point in the history
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`/`civicrm#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 `civicrm#5` calls both the old+new listeners, creating two dialogs.
  • Loading branch information
totten committed Oct 8, 2021
1 parent d2c77bf commit 69bfc1b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions ext/message_admin/ang/crmMsgadm/Edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,9 @@
});

}
$rootScope.$on('previewMsgTpl', onPreview);
$rootScope.$on('$destroy', function (){
$rootScope.$off('previewMsgTpl', onPreview);
var unreg = $rootScope.$on('previewMsgTpl', onPreview);
$scope.$on('$destroy', function (){
unreg();
});
});

Expand Down

0 comments on commit 69bfc1b

Please sign in to comment.