Skip to main content
Pentaho Documentation

Analyzer Event Registration

Overview

Quisque mattis rutrum ligula et pellentesque. Pellentesque massa enim, pulvinar quis quam quis, aliquet dapibus augue. Aliquam feugiat suscipit turpis, nec ultrices dolor adipiscing ut.

Analyzer events are API hooks which allow you to register custom listeners into the inner workings of Analyzer. These locations can range from when Analyzer is initialized to when a cell is clicked. 

Event Registration

Event registration occurs before Analyzer is initialized. Events are registered using the Analyzer API, which has to be required using RequireJS. When triggered, event listeners will execute in the order in which they were registered.

All registered event listeners receive at least three function parameters: e (the event object), cv (global analyzer namespace), and report (the report against which the function is being run).

Example:

require(["analyzer/cv_api"], function(api) {
  api.event.registerInitListener(function(e, cv, report){
	// Perform Action
  });
} 

Stop Immediate Propagation

There may be a time when, under special circumstances, a prior event listener will not want any further listeners to be executed. This can be performed by stopping the immediate propagation on the event chain. The function is attached to the event object (e), which is passed into the listeners.

Example:

api.event.registerInitListener(function(e, cv, report) {
  // Perform Action 1
  e.stopImmediatePropagation();
});
 
api.event.registerInitListener(function(e, cv, report) {
  // Perform Action 2
});

In the above code sample, even though two event listeners have been registered, since the first listener stopped the immediate propagation, the 2nd (and any subsequent) event listener will not be fired.

Prevent Default

All events have a default behavior associated with them and, in some cases, this behavior can be completely prevented. As with stopImmediatePropagation, this is also attached the to the event object (e) and needs to be called within the listener's code block.

Example:

api.event.registerInitListener(function(e, cv, report) {
  // Perform Action
  e.preventDefault();
}); 

Removing Listeners

It is possible to remove listeners once they have been registered.  A register event listener function returns a handler for that event listener which has a remove function attached to it. Calling this function removes the listener from the event chain.

Example:

var initListenerHandler = api.event.registerInitListener(function(e, cv, report) {
  // Perform Action
  e.preventDefault();
});
 
initListenerHandler.remove();

Attaching Event Listener Code

To insert your own custom javascript file, you must modify plugin.xml inside of the analyzer plugin folder. Currently, there is a commented line which is pointed at an example file inside of the plugin's script folder. If you would like to see this file working or see the sample code to change to point to your own javascript file, uncomment that line by deleting the <!-- and --> surrounding the <file> tag. You must restart your server to see these changes.

Example:
<!-- <file context="analyzer">content/analyzer/scripts/api_examples/EventRegistration.js</file> -->

Events

The following are events in Analyzer.

init

The init event occurs after Analyzer's UI has initialized and the report definition (if opening a saved report) has been loaded into the editor.  Once all init handlers have been called, the report will automatically refresh its data so you do not need to call refreshReport in the init handler.

Example:

api.event.registerInitListener(function(e, cv, report) {
  // Perform Action
  // e.stopImmediatePropagation();
});