Events Manager

(eventsManager)

Overview

This is the EventsManager where you can register for events that are fired by the servoy for the default events and custom events can be listened to and fired for in code.

The EventType can be a build in one or custom one that are set in the solution/module eventTypes property.

Returned Types

enum,EventType,

Methods Summarized

Type
Name
Summary

Adds a listener for a custom EventType or for one of default event types.

Adds a listener for a custom EventType or for one of default event types.

Calls all listeners for a certain event type Will return a Boolean calculated as logical AND between all listeners return value (default value).

Calls all listeners for a certain event type and for a certain context).

Calls all listeners for a certain event type and certain context.

Calls all listeners for a certain event type (and optionally, for a certain context).

Calls all listeners for a certain event type Will return a Boolean calculated as logical AND between all listeners return value (default value).

Checks if listeners were added for a certain event type (and possibly context)

Removes one or multiple listeners (depending on parameters).

Methods Detailed

addEventListener(eventType, callback)

Adds a listener for a custom EventType or for one of default event types. The custom event is defined on solution eventType property and can be fired using fireEventListeners. The callback first parameter is always a JSEvent object. The source is the context (for default form event types this is 'forms.MyForm') also the formName is set to the form that triggered this for the default events. The data object of the JSEven object is the argument array, those are also given as parameters after the first JSEvent parameter. For default types these are the same arguments then what the forms event function also would get (so that could also containe a JSEvent parameter) For custom types the given arguments in the fireEventListeners call are given as parameters after the JSEvent parameter and as Array in the data object of the JSEvent object

The callback function can look like this:

/**
 * @param {JSEvent} event the event object that is fired
 * @param {Object} arg1 the first argument that is given by the system or the fireEventListeners call
 * @param {Object} arg2 the second argument that is given by the system or the fireEventListeners call
 */
function myCallback(event, arg1, arg2) {}

Parameters

Returns: Function returns the deregister function that can be used to remove the listener.

Sample

var deregister = eventsManager.addEventListener(EventType.myCustomEvent,this.callback);
deregister();

addEventListener(eventType, callback, context)

Adds a listener for a custom EventType or for one of default event types. The custom event is defined on solution eventType property and can be fired using fireEventListeners. When context is specified, the callback will only be called on that context: for custom events, when fireEventListeners is called using same context and for default events when context is the specific form that triggers the default form event. The callback first parameter is always a JSEvent object. The source is the context (for default form event types this is 'forms.MyForm') also the formName is set to the form that triggered this for the default events. The data object of the JSEven object is the argument array, those are also given as parameters after the first JSEvent parameter. For default types these are the same arguments then what the forms event function also would get (so that could also containe a JSEvent parameter) For custom types the given arguments in the fireEventListeners call are given as parameters after the JSEvent parameter and as Array in the data object of the JSEvent object

The callback function can look like this:

/**
 * @param {JSEvent} event the event object that is fired
 * @param {Object} arg1 the first argument that is given by the system or the fireEventListeners call
 * @param {Object} arg2 the second argument that is given by the system or the fireEventListeners call
 */
function myCallback(event, arg1, arg2) {}

Parameters

  • EventType eventType Event type to listen to.

  • Function callback callback to be called.

  • Object context Can be a form, global scope or any string. Will cause callback to only be called on that context.

Returns: Function returns the deregister function that can be used to remove the listener.

Sample

var deregiser = eventsManager.addEventListener(EventType.onShowMethodID,this.callback,forms.myform);
deregiser();

fireEventListeners(eventType)

Calls all listeners for a certain event type Will return a Boolean calculated as logical AND between all listeners return value (default value).

Parameters

  • EventType eventType Event type for listeners to be called.

Returns: Object Boolean value that is a logical AND between all listeners return value.

Sample

eventsManager.fireEventListeners(EventType.myCustomEvent,'mycontext');

fireEventListeners(eventType, context)

Calls all listeners for a certain event type and for a certain context). Will return a Boolean calculated as logical AND between all listeners return value (default value).

Parameters

  • EventType eventType Event type for listeners to be called.

  • Object context Context for listeners to be called. Can be null (any context).

Returns: Object Boolean value that is a logical AND between all listeners return value.

Sample

eventsManager.fireEventListeners(EventType.myCustomEvent,'mycontext');

fireEventListeners(eventType, context, callbackArguments)

Calls all listeners for a certain event type and certain context. Will return a Boolean calculated as logical AND between all listeners return value (default value).

Parameters

  • EventType eventType Event type for listeners to be called.

  • Object context Context for listeners to be called. Can be null (any context).

  • Array callbackArguments Arguments for listener to be called with. Can be null.

Returns: Object Boolean value that is a logical AND between all listeners return value.

Sample

eventsManager.fireEventListeners(EventType.myCustomEvent,'mycontext');

fireEventListeners(eventType, context, callbackArguments, returnValueAggregationType)

Calls all listeners for a certain event type (and optionally, for a certain context). Will return either a Boolean calculated as logical AND between all listeners return value or an Array with all return values.

Parameters

  • EventType eventType Event type for listeners to be called.

  • Object context Context for listeners to be called. Can be null (any context).

  • Array callbackArguments Arguments for listener to be called with. Can be null.

  • enum returnValueAggregationType Return value constant. Should be taken from EVENTS_AGGREGATION_TYPE.

Returns: Object Boolean or Array depending on returnValueAggregationType. Boolean value is a logical AND between all listeners return value and Array contains all return values of the listeners.

Sample

eventsManager.fireEventListeners(EventType.myCustomEvent,'mycontext',null,EVENTS_AGGREGATION_TYPE.RETURN_VALUE_BOOLEAN);

fireEventListeners(eventType, callbackArguments)

Calls all listeners for a certain event type Will return a Boolean calculated as logical AND between all listeners return value (default value).

Parameters

  • EventType eventType Event type for listeners to be called.

  • Array callbackArguments Arguments for listener to be called with. Can be null.

Returns: Object Boolean value that is a logical AND between all listeners return value.

Sample

eventsManager.fireEventListeners(EventType.myCustomEvent,'mycontext');

hasEventListeners(eventType, context)

Checks if listeners were added for a certain event type (and possibly context)

Parameters

  • EventType eventType Event type for listener to check.

  • Object context Context for listener to check. Can be null (any context).

Returns: Boolean Boolean (true) if listeners were added, (false) otherwise

Sample

eventsManager.hasEventListeners(EventType.myCustomEvent,'mycontext');

removeEventListener(eventType, callback, context)

Removes one or multiple listeners (depending on parameters). Only works for custom event listeners that were added using addEventListener.

Parameters

  • EventType eventType Event type for listener to remove. Cannot be null.

  • Function callback callback to be removed. Can be null (any listener).

  • Object context Context for listener to remove. Can be null (any context).

Returns: Boolean true if the deregister was successful

Sample

eventsManager.removeEventListener(EventType.myCustomEvent,this.callback,'mycontext');

Last updated

Was this helpful?