Document toolboxDocument toolbox

Events subscriptions


 

Introduction

Subscribing to general application events through PageBus should be fairly safe and easy to do. 

 

Subscribe to events like this:

HD.PageBus.subscribe('*.*.entity.select', this.onEntitySelect, this);

 

Inline example for testing:

var myHandler = function(subject, data) { console.log(data) }; HD.PageBus.subscribe('*.*.user.spot.select', this.myHandler, this);

 

A raw entity will be returned. Easiest way to get currently selected objects, would be to use high level EmbededApi call: HD.EmbededApi.getSelectedObjects();

Otherwise raw entity ID must be looked up against links store. The links store will present internal object ID with information about default link. 

That data can be then converted to external ID.

 

Events

Object entities

*.*.entity.select
*.*.entity.update
*.*.entity.create

Vector entities / spots

*.*.user.spot.select

HD.PageBus.subscribe('*.*.user.spot.select', function(event, data) { console.log(data); });

Returned data contains information both about the vector entity and a default linked object to that spot, if any.

For more information, a docSvgView object is provided for further interaction.

Object {entityId: "ENT-1976", entity: g#ENT-1976, docSvgView: constructor, targetObject: Object} -> docSvgView:constructor -> entity:g#ENT-1976 -> entityId:"ENT-1976" -> targetObject:Object -> classId:"108" -> isDefault:false -> objectId:"5194"



Key Events

Basic support for key events is added:

  • ui.docview.key.Delete

  • ui.docview.key.Enter

  • ui.docview.key.Escape



  • ui.docview.key

Use specific key subscription or for all keys, subscribe to generic "key" event.

In the handler function 

function(subject, data)

data object will contain :

  • SvgView

  • event

To obtain object selection after event (in embedded scenario), call HD.EmbededApi.getSelectedObjects();

Viewer Events

  • ui.docview.document.load

  • ui.docview.document.clear 

  • ui.docview.document.ready  


 Document "load" will only be fired on actual document load and will not be fired when only object context was changed.

Context change happens when the same document is used to show another object, e.g. Room. Instead, you might want to use 'ready' event, unless you are interested in actual load event. 



 

Using pagebus events

 

Function 

Comment 

Function 

Comment 

PageBus.publish

Publish a message on a topic. If there is an event cache for this topic, a copy of the message will also be saved in the event cache. 

PageBus.subscribe

Subscribe to a topic. With certain parameters, also creates a cache for the specified topic. 

PageBus.unsubscribe

Cancel a subscription created by subscribe().

PageBus.query

not available

Query the cache for events matching the specified topic.

PageBus.store

not available

 If there is a cache for the specified topic, publish to update it. Otherwise throw an exception so that the caller knows that the topic is not cache-enabled.

System Ready Event

Since 3.7

System ready event is fired when the main interface loads. When navigating to another module, e.g. System Administration, the event will be fired again when going back to main interface. 

Access to this information is available in the following way:

  1. Make sure HD.EmbeddedApi is available (exists)

  2. Call 

     

Arguments are:

  1. Callback function

  2. Context for callback

  3. any additional arguments that will be passed on to callback function (variable, object etc)

The callback will be always called, either imminently if the system is already in Ready state, or later is the system is still initializing. 

 

To clear all System Ready subscriptions, call this function without arguments:

To list current subscribers:



If you do not want to provide callback function, you can call this function that will check current state: