Page tree
Skip to end of metadata
Go to start of metadata

When creating new objects and screens the developer can set individual events in attributes using the Object Designer

but there are cases where you would like logic to execute for every object of the same type. For this scenario the developers can use the framework global hooks.

Besides the object types also other components like the DESKTOP are made available via the Global Framework Hooks.

The Framework Hooks are composed out of the namespaces added on the akioma.swat.GlobalHooks object,

for eg. "akioma.swat.GlobalHooks.WINDOW.CLOSE" which holds the information: for what object and for what event.

Also for setting up event listeners the akioma.swat.GlobalEmitter object is made available. The object has methods for adding and removing event listeners: on, off, once, emit.


Some examples of using Global Framework Hooks:

Window Close Hook Sample
/**
 * Event listener called after a window close event operation
 * @param {akioma.swat.Window} windowControl Window object closed
 */
akioma.swat.GlobalEmitter.on( akioma.swat.GlobalHooks.WINDOW.CLOSE, ( windowControl : akioma.swat.Window ) => {
  const taskbarObject = akioma.swat.MasterLayout.getBaseLayoutObject().getFirstChildByType( "grouptaskbar" ) as akioma.swat.Taskbar;

  taskbarObject.removeItem( windowControl.controller.opt.id );
} );
Desktop AfterToggle Hook Sample
/**
 * Listener on desktop toggle mode to enable/disable header Taskbar
 * @param {boolean} isDesktopMode Desktop state
 */
akioma.swat.GlobalEmitter.on( akioma.swat.GlobalHooks.DESKTOP.AFTER_TOGGLE, ( isDesktopMode : boolean ) => {
  const taskbarObject = akioma.swat.MasterLayout.getBaseLayoutObject().getFirstChildByType( "grouptaskbar" ) as akioma.swat.Taskbar;

  if ( !taskbarObject )
    return;

  if ( isDesktopMode )
    taskbarObject.enable();
  else
    taskbarObject.disable();
} );
DataSource AfterSave Hook Sample
/**
 * Event listener called on an after save changes on a dataSource/businessEntity,
 * used for updating the group title after a dataSource saveChanges operation
 * @param {akioma.swat.DataSource} dataSource Datasource object
 */
akioma.swat.GlobalEmitter.on( akioma.swat.GlobalHooks.DATASOURCE.AFTER_SAVE_CHANGES, async ( dataSource : akioma.swat.DataSource ) => {
  const containerControl = dataSource.container?.controller;
  const primaryDataSource = containerControl.dynObject?.getLink( "PRIMARYSDO:TARGET" );

  if ( containerControl?.view !== "window" || !primaryDataSource )
    return;

  const TaskbarObject = akioma.swat.MasterLayout.getBaseLayoutObject().getFirstChildByType( "grouptaskbar" ) as akioma.swat.Taskbar;

  const primaryDataSourceControl = primaryDataSource.controller;
  const SelfHdl = primaryDataSource.getValue( "selfhdl" );

  const res = await akioma.getRelatedPersonByUniqueKey( SelfHdl );
  const resArray = res.split( "|" );
  const parentId = resArray[ 0 ];
  const title = resArray[ 1 ];
  let groupData;
  if (parentId) {
    groupData = {
      id: parentId,
      title
    };
  } else {
    const shortTemplate = containerControl.opt.titleShort || containerControl.opt.TITLE;
    const titleShortTemplateCompiled = primaryDataSourceControl.getRecordDescription(shortTemplate);
    groupData = {
      id : TaskbarObject.getActiveGroupId(),
      title : titleShortTemplateCompiled
    };
  }
  TaskbarObject.updateGroup( groupData );
} );
  • No labels