Events Package - AFS

AFS Integration Guide

Product
AFS
AFS_Version
7.9
Category
Reference Guide

This package aims to provide tools to work with application events. All existing application events can be accessed in one place, in one way. This package is available in:

AFSWidget.sdk.events

Some events are currently supported. The list can be consulted in AFSWidget.sdk.events.types and is shown below. In the future, this list can receive new additions.

[
"*",
"before-reply-dispatch",
"after-reply-dispatch",
"login",
"logout",
"book-added",
"book-updated",
"book-deleted",
"search-added",
"search-updated",
"search-deleted",
"bookmark-added",
"bookmark-updated",
"bookmark-deleted"
]

  • The wildcard event '*' allows to be notified of any occurring event.
  • The '*-reply-dispatch' event family is related to an AFS search and allows to be notified before or after widgets handle a new response.
  • The 'login' and 'logout' events are raised after a new CKS authentication state.
  • The '*-added', '*-updated' and '*-deleted' event families notify status of managed CKS objects.

To be notified upon new events, a on() function is provided and allows to attach a listener.

Here are some examples.

function onAppReady()
{
AFSWidget.sdk.events.on('login', function(eventName, data){
sayHello(data.firstName + ' ' + data.lastName);
});

AFSWidget.sdk.events.on('*', function(eventName, data){
if (eventName == "login") {
sayHello(data.firstName + ' ' + data.lastName);
}
else if (eventName == "logout") {
sayGoodbye(); // here data is undefined
}
});
}

Be sure the SDK is available and ready to use before making calls to it. See 'appReadyCallback' in SDK configuration.

Each handler receives two parameters. The first is the event name (not useful in most cases), the second contains data associated to the event if it makes sense. The content of these data is not detailed here since it depends on the event. Use the browser console and/or debugger to inspect the passed JSON objects.

Many handlers can be attached to a same event.

All events raised by the application are registered in the AFSWidget.sdk.events.history array. This array can be consulted and cleared as wanted.