-
Notifications
You must be signed in to change notification settings - Fork 5
Capture Zimbra events inside a Zimlet
Zimlets can register listeners that are provided via zimletEventEmitter. The following events are supported:
- LOGOUT
- ONSEND
New events will be added to Zimbra soon, this guide will be updated when that happens.
The LOGOUT
event is fired when the user clicks the Logout
menu item. It can be used to trigger a log-out in non Single Log Out aware 3rd party application.
The ONSEND
event is fired when the user clicks the Send
button when sending an email. It can be used for email error checks, such as a forgotten attachment reminder, or do a check in a 3rd party application for compliance validation.
Here is an example of how a Zimlet registers a listener for a logout event.
import { zimletEventEmitter } from '@zimbra-client/util';
import { ZIMBRA_ZIMLET_EVENTS } from '@zimbra-client/constants';
const onLogoutHandler = () => { /** Do something */ };
zimletEventEmitter.on(ZIMBRA_ZIMLET_EVENTS.LOGOUT, onLogoutHandler);
There can be two types of handlers.
- Handler doing synchronous tasks like - calculating something, displaying toast, or updating view/state Here is an example of this kind of handler:
import { zimletEventEmitter } from '@zimbra-client/util';
import { ZIMBRA_ZIMLET_EVENTS } from '@zimbra-client/constants';
const onLogoutHandler = () => { /** Display toast message */ };
zimletEventEmitter.on(ZIMBRA_ZIMLET_EVENTS.LOGOUT, onLogoutHandler);
- Handler doing asynchronous tasks like - invoke an API call or display dialog to confirm the action with the user. Here is an example of this kind of handler:
import { zimletEventEmitter } from '@zimbra-client/util';
import { ZIMBRA_ZIMLET_EVENTS } from '@zimbra-client/constants';
const onLogoutHandler = () => new Promise((resolve, reject) => {
if (window.confirm("Do you really want to logout?")) {
resolve();
} else {
reject();
}
});
zimletEventEmitter.on(ZIMBRA_ZIMLET_EVENTS.LOGOUT, onLogoutHandler, true); //the 3rd argument makes the handler asynchronous
To remove a listener you can use zimletEventEmitter.off
like this:
zimletEventEmitter.off(ZIMBRA_ZIMLET_EVENTS.LOGOUT, onLogoutHandler);
- Home
- Client Tool
- Getting Started
- Creating Your Zimlet
- Zimlet Design Patterns
- Advanced