BILLmanager 6

Topic manager

The topic manager is a global object that keeps track of topic states and events. It allows to perform additional actions after events or state changes occur. For example, to collect information about customer actions in the topic for further analytics.

Manager initialization

Manager object is available in a global window object called ISPDragonManager. This object does not become available immediately. To wait for its creation, it is recommended to monitor the ISPDragonManagerLoaded event, which is triggered when the manager object is ready. The ISPDragonManagerLoaded event data contains the manager object.

To get a manager object, use a template:

function handlerManager(manager) {
    // working with a manager
}

// if the code was executed after creation of the manager, the ISPDragonManager object is available in the `window` object 
if (window.ISPDragonManager) {
    handlerManager(window.ISPDragonManager);
} else {
    // if the manager is not yet created by the time the code is executed, wait until the `ISPDragonManagerLoaded` event is executed
    window.addEventListener('ISPDragonManagerLoaded', event => {
        // the event data contains a manager object
        const manager = event.detail;
        handlerManager(manager);
    });
}

Events

Manager allows to keep track of general events that occur in a topic:

  • http-response — receiving a response to the request;
  • action — performing an action, e.g., clicking on a button;
  • form-submit — successful form submission;
  • form-view-init — form initialization;
  • form-destroy — form closing;
  • form-wizard — switching to or leaving the wizard.

The http-response event type

Happens when an HTTP response is received from the server.

The event object includes the following properties:

Property nameDescriptionValues
responseserver responseobject
requestParamsparameters of the request that was responded to by the serverobject
activeDoc

object corresponding to the root doc tag of the active platform tab. For more details, see the article Custom interface theme

object
activeContextIdid of the current active contextstring

Action event type

Happens at internal topic events:

  • button click;
  • click on an internal link, i.e. a link with the @internal=“yes” attribute.

Depending on the type of event, its objects contain properties:

Button Click event object

Property nameDescriptionValues
actionTypetype of action performed by the userbuttonClick
contextFuncfunction name of the active platform tab where the button was clickedstring
namename of the clicked button. Corresponds to the @name button attributestring
typename of the clicked button. Corresponds to the @type button attributestring
funcname of the clicked button. Corresponds to the @func button attributestring or undefined
activeDocobject corresponding to the root doc tag of the active platform tab. For more details, see the article Custom interface themeobject
activeContextIdid of the current active contextstring

Click on internal link event object

Property nameDescriptionValues
actionTypetype of action performed by the userinternalLink
contextFuncfunction name of the active tab of the platform where the link was clickedstring
paramsobject that contains internal reference parameters specified in the @internal reference attributeobject
activeDocobject corresponding to the root doc tag of the active platform tab. For more details, see the article Custom interface themeobject
activeContextIdid of the current active contextstring

Form-submit event type

Happens when the form is successfully submitted. If the form has not passed validation, the event will not happen.

Property nameDescriptionValues
funcname of the function to which the form was sentstring
paramsthe request parameters with which the form submission occurredobject
responseserver responseobject
activeDocobject corresponding to the root doc tag of the active platform tab. For more details, see the article Custom interface themeobject
activeContextIdid of the current active contextstring

Form-view-init event type

Happens during the initial initialization of the form. After this event, user can interact with DOM elements of the form.

If a doc object is changed within the same form, the form-view-init event will happen again. The event object will contain a new formGroup object and a new contextFunc property.
Property nameDescriptionValues
formIdid of the initialized formstring
contextFuncfunction name of the formstring
formGroup

FormGroup object of the initialized form

FormGroup
formElementHTML element of an initialized formHTMLFormElement
activeDocobject corresponding to the root doc tag of the active platform tab. For more details, see the article Custom interface themeobject
activeContextIdid of the current active contextstring

Form-destroy event type

Happens when the form is closed.

Property nameDescriptionValues
formIdclosed form idstring
contextFuncfunction name of the formstring
activeDocobject corresponding to the root doc tag of the active platform tab. For more details, see the article Custom interface themeobject
activeContextIdid of the current active contextstring

Form-wizard event type

Happens when the user logs in to the Form wizard or leaves the wizard after successfully submitting the form in the last step.

Event object “Opening the first wizard step”

Property nameDescriptionValues
typeevent typestart
funcfunction name of the first wizard stepstring
paramsquery parameters with which the first wizard step was openedobject
activeDocobject corresponding to the root doc tag of the active platform tab. For more details, see the article Custom interface themeobject
activeContextIdid of the current active contextstring

Event object “Successful form submission on the last wizard step”

Property nameDescriptionValues
typeevent typeend
funcname of function to which the form was sentstring
paramsthe parameters of the request the form was sent withobject
activeDocobject corresponding to the root doc tag of the active platform tab. For more details, see the article Custom interface themeobject
activeContextIdid of the current active contextstring

Event handling methods

The following are the methods of the manager object that allow to handle topic events.

addListener(eventName, callback) 

Allows to specify a function to execute when the event specified in the first argument happens.

ArgumentDescription

eventName

string with the name of the event to execute the passed function

callback

function called each time when the event with the name set in eventName occurs. The first argument takes an event object

The function returns undefined .

removeListener(eventName, callback) 

Deletes the passed function from the handlers of the event with the name set in eventName. The function will no longer be called when an event with such a name happens.

ArgumentDescription

eventName

string with the name of the event from which the function should be deleted

callback

function to be deleted from the handlers of the event set in eventName

The function returns undefined .

listenToEvent$(eventName) 

Allows to get an object of Observable ,class that is triggered when an event with the name set in eventName occurs.

ArgumentDescription

eventName

string with the name of the event to be watched for

The function returns an Observable class object that sends an event object.

Usage examples

The given examples are executed if there is a global manager object (for more details see “Manager initialization"). 

Below is an example of adding and removing the http-response event handler:

// handler function
const callback = (event) => {
    // handler receives the event object
    console.log('Http-response event object', event);
    // handler removal
    window.ISPDragonManager.removeListener('http-response', callback);
};
//add handler for `http-event`
window.ISPDragonManager.addListener('http-response', callback);

The example below shows a subscription to the Observable object of the action event:

// subscription to the `action` event
window.ISPDragonManager.listenToEvent$('action').subscribe(event => {
    // thread sends an event object
    console.log('Action event object', event);
});

States

The manager allows to retrieve topic states and their changes:

  • active-doc — doc tag of the active platform tab;
  • user-real-level — user level in the panel;
  • active-context-id — id of the current active context.

Active-doc state

The object corresponding to the root doc tag of the active platform tab.

User-real-level state

The user's current level is represented by an integer. Corresponds to the @level attribute from the first doc.path element. This is how the root user level is determined.

Active-context-id state

A string that corresponds to the id of the currently active context. For example, the id of the active tab. Allows to distinguish clearly the elements on the page, if, for example, several identical tabs are open.

Methods of working with the state

Below are the methods of the manager object that allow to work with topic states.

getState(stateName) 

Allows to get the current value of the state specified in stateName synchronously.

ArgumentDescription
stateNamestring with the name of the state to get

The function returns the value of the state.

addWatcher(stateName, watcher) 

Allows to add a function that is called immediately after it is added with the current state value, and with each subsequent change to that value.

ArgumentDescription
stateNamestring with the name of the state to be watched for
watcher

function that takes the state value as its first argument. It is called immediately after calling the addWatcher method and at each subsequent change of the state with the name set in stateName

The function returns undefined .

removeWatcher(stateName, watcher)

Removes the state value change tracking function with the name specified in stateName.

ArgumentDescription
stateNamestring with the state name, from which the function should be deleted
watcher

The function to be removed from the event listeners with the name set in stateName

The function returns undefined .

watchForState$(stateName, options?)

Allows to get an Observable class object that is triggered when the state value with the name set in stateName changes. When subscribed, this Observable sends the current state value immediately. It then returns the state value each time it is changed.

ArgumentDescription
stateNamestring with the name of the state to be watched for

options

object with additional customization options for an Observable class object. The object contains a single property skipFirst?: boolean. If it is set to true, the Observable returns its value only when the state changes and doesn't return the value immediately after subscribing to it

Function returns an object of class Observable that sends a state value.

Usage examples

The given examples are executed if there is a global manager object (for more details see “Manager initialization"). 

The example below shows a synchronous user level retrieval:

// get `user-real-level` state value
const currentUserLevel = window.ISPDragonManager.getState('user-real-level');
console.log(currentUserLevel);

The example below shows how to add and remove a state listener:

// handler function
const callback = (currentDoc) => {
    // the handler receives the state value as the first argument
    console.log('Active-doc state value', currentDoc)
    // handler removal
    window.ISPDragonManager.removeWatcher('active-doc', callback);
};
// adding a handler. When a handler is added, it is invoked immediately. Then it is invoked every time the state changes 
window.ISPDragonManager.addWatcher('active-doc', callback);

The example below shows how to subscribe to a Observable object of user-real-level state:

window.ISPDragonManager.watchForState$('user-real-level').subscribe(userLevel => {
    // user level is displayed in the console immediately after subscribing, and every time the state changes
    console.log(userLevel)
});

When skipFirst: true is set, the thread only sends state values when it changes and doesn't send the value immediately after subscribing to it:

window.ISPDragonManager.watchForState$('user-real-level', { skipFirst: true }).subscribe(userLevel => {
    // user level is displayed in the console only when the state changes
    console.log(userLevel)
});
Useful tips

Related articles: