REST Collection Objects
Finesse JavaScript library provides REST collection objects, which is a collection of Finesse REST API objects. For instance, a User is a Finesse JavaScript REST object, and Users is a Finesse JavaScript REST collection object, which can hold multiple User objects.
JavaScript REST Object | JavaScript REST Collection Object |
---|---|
Dialog | Dialogs |
Media | MediaList |
PhoneBook | PhoneBooks |
Queue | Queues |
Team | Teams |
User | Users |
Significance of REST Collection Object
To understand the significance of a REST collection object, consider the example of all the Dialogs associated with a User in a grid.
A Dialog is a JavaScript representation of a call. It can be a regular phone call, a conference, or a silent monitor session. A User object can be composed of many other objects, one of which is the Dialogs object. Note that it is Dialogs and not Dialog. This is because a user can be involved in multiple calls.
In the above example, after the User has successfully loaded, you call the getDialogs()
API of the User object to get the Dialogs collection object and perform certain operations on it before you display it in a grid. Note that we did not explicitly initialize the Dialogs collection object. The getDialogs()
API of the User object did it for us internally.
You do not have to explicitly create the collection objects. All the JavaScript REST objects which are composed of such collection object provides certain APIs which are internally taken care of initializing the objects. You must provide the handlers to control once the collection is loaded, modified, or deleted. The following are some examples of APIs which internally initialize and return respective REST collection objects.
Consider the Dialogs in a grid example to include a feature where the grid updates in real-time if any new dialog shows up or any existing dialog gets removed. REST collection objects also provide multiple handlers. The following example shows two new handlers provided by the collection object onCollectionAdd
and onCollectionDelete
that are triggered when an item is added or removed respectively.
Example—Multiple Handlers
Commonly used REST collection object handlers are:
-
onLoad—Triggers when the collection object is successfully loaded.
-
onCollectionAdd—Triggers when a new item is added to the collection.
-
onCollectionDelete—Triggers when a item is deleted from the collection.
-
onError—Triggers when some error occurs during any of the above operations.