Backoffice Framework API Documentation for AngularJS

In the Backoffice Framework, the ZK Framework is used by default, although it is not obligatory and could be replaced with some other framework. This document describes how to integrate widgets written in AngularJS with the Backoffice Framework.

Dependencies

To inform Backoffice Framework that an extension requires AngularJS, add a dependency to the extension/backoffice/resources/js /js-libraries.xml:

<library>
    <name>angular</name>
</library>

This dependency brings the AngularJS in version 1.3.16.

Adapter

By default, Backoffice Framework configuration allows for automatic injection of an adapter class for AngularJS. You may reconfigure Backoffice Framework so that it uses another adapter and/or extends the one that is assigned by default (see also the Adapter section in the Backoffice Framework API Documentation for Javascript).

Constructors

The default Angular adapter exposes the constructors listed below:

Method

Parameters

Description

<constructor>

Constructs a new adapter.

Constructor creates an instance of Backoffice Framework adapter assigned to a widget root (see the constructor description in the Backoffice Framework Integration section of the Backoffice Framework API Documentation for Javascript), registers a new Angular module with the provided name (if not yet registered) and all its directives.

moduleName

Name of the AngularJS module that is to be registered for a widget.

Widget is actually registered as concatenation of a container id and a provided value: id_moduleName.

<constructor>

Constructs a new adapter.

Constructor creates an instance of Backoffice Framework adapter assigned to the provided DOM element, registers a new Angular module with the provided name (if not yet registered) and all its directives.

moduleName

Name of the AngularJS module that is to be registered for a widget.

Widget is actually registered as concatenation of a container id and the provided value: id_moduleName

domElement

Any widget HTML element or JQuery object or any widget HTML element id.

Methods

Additionally, the general-purpose methods are exposed:

Method

Parameters

Description

cng

Gets a Backoffice Framework adapter.

controller

Registers a new empty controller in the module.

Method searches for the closest ng-controller attribute to the widget root and assigns an empty controller with it (see the <constructor>description in the Backoffice Framework Integration section of the Backoffice Framework API Documentation for Javascript).

Method returns the current adapter instance to allow using it as a chain of commands (that is, adapter.controller(...).initData(...).controller(...).initData(...)).

controller

Registers a new controller in the module.

Method searches for the closest ng-controller attribute to the widget root and assigns a controller with it (see the <constructor>description in the Backoffice Framework Integration section of the Backoffice Framework API Documentation for Javascript).

Method returns the current adapter instance to allow using it as a chain of commands (i.e. adapter.controller(...).initData(...).controller(...).initData(...)).

controller

AngularJS controller to be registered (for more information, see the AngularJS DocumentationInformation published on non-SAP site).

controller

Registers a new controller in the module.

Method searches for the closest ng-controller attribute to the widget root and registers a controller with it (see the <constructor>description in the Backoffice Framework Integration section of the Backoffice Framework API Documentation for Javascript).

Method returns the current adapter instance to allow using it as a chain of commands (that is, adapter.controller(...).initData(...).controller(...).initData(...)).

controller

AngularJS controller to be registered (for more information, see the AngularJS DocumentationInformation published on non-SAP site).

services

Array of services that are used by the controller (by default: [ "$scope" ]).

controller

Registers a new controller in the module.

Method searches for the closest ng-controller attribute to the element provided and registers a controller with it (see the <constructor>description in the Backoffice Framework Integration section of the Backoffice Framework API Documentation for Javascript).

Method returns the current adapter instance to allow using it as a chain of commands (that is, adapter.controller(...).initData(...).controller(...).initData(...)).

dom

HTML element, JQuery object, or the id of an element which should be taken as a controller root.

controller

AngularJS controller to be registered (for more information, see the AngularJS documentation: the AngularJS DocumentationInformation published on non-SAP site).

services

Array of services that are used by the controller (by default: [ "$scope" ]).

initData

Specifies values that should be injected into the controller scope.

Method searches for the closest ng-controller attribute to the widget root and initializes its scope after the element is fully loaded.

Method returns the current adapter instance to allow using it as a chain of commands (that is, adapter.controller(...).initData(...).controller(...).initData(...)).

injection Map of values to be injected into scope. Values are available in scope by provided keys.

initData

Specifies values that should be injected into the controller scope.

Method searches for the closest ng-controller attribute to the element provided and initializes its scope after the element is fully loaded.

Method returns the current adapter instance to allow using it as a chain of commands (that is, adapter.controller(...).initData(...).controller(...).initData(...)).

dom

Any widget HTML element, JQuery object, or any widget HTML element id.

injection

Map of values to be injected into the scope. Values are available in the scope by the provided keys.

Directives

The adapter defines a few Angular directives that make the integration with Backoffice Framework much easier:

Directive

Type

Description

cngLocal

attribute

Changes the text of the current element to a label that is registered under the provided key. A label is considered to be local (defined in the extension/backoffice/resources/widgets/widget/labels/labels.properties file)

Example

<div cng-local="some.local.label"></div>

cngGlobal

attribute

Changes the text of the current element to a label that is registered under the provided key. A label is considered to be global (defined in the resources/extension-backoffice-lables/labels.properties file)

Example

<div cng-global="some.global.label"></div>

cngSrc

attribute

Appends an attribute src with the value that points to the specified widget source directory. Value of the attribute should be a path to the resource relative to widget root directory.

Example

<img cng-src="images/image.png"></div>

cngResource

attribute

Appends an attribute src with the value that points to the specified global resource directory. The value of the attribute should be an absolute path to the resource.

Example

<script cng-resource="cockpitng/cng/scripts/cockpitNGAdapter.js"></script>

cngEvent

element

Handles various events from Backoffice Framework.

Directive requires following attributes to be also defined in the element:

Attribute

Description

type

Type of event that is to be handled. Accepted values:

  • socket: handles input socket messages
  • model: handles model changes
  • ready: handler is called once - when the widget is fully loaded

handler

Expression to be executed when an event occurs. Some additional values are available depending on the event type:

  • socket:
    • socket: name of the socket, on which a message has been received

    • data: data that has been received
  • model:
    • model: model that has been changed
    • property: name of the value that has been changed (may be null if the whole model has been replaced)
    • value: new value of the property

id

Event filter. Value interpretation depends on the event type:

  • socket: defines a name of the socket (value required)
  • model: defines a name of a value, the changes of which should be registered (value optional)
  • ready: value optional

Example

<cng-event type="socket" id="input" handler="socketInput(socket, data)"></cng-event>
<cng-event type="model" handler="modelChange(model)"></cng-event>
<cng-event type="ready" handler="init()"></cng-event>

Scope

The adapter also introduces variables, that are available on each controller scope:

Method

Description

model

Javascript representation of the widget model

settings

Javascript representation of the widget settings

adapter

Adapters instance

sessionInfo

Session-related information

Supported attributes:

  • String currentUser - displays the name of the logged user
  • Boolean admin - indicates if the current user has admin privileges
  • Locale currentLocale - displays the language the user currently uses
  • Locale[] enabledDataLocales - displays enabled languages
  • AuthorityGroup activeAuthorityGroup - shows the active Authority Group
  • Map<String, Object> customAttributes - exposed session information object can be customized. All the non-standard properties are persisted in the customAttributes map

Custom Attributes in Session Info

It is possible to put custom attributes into sessionInfo variable. When you want to add your custom attributes to the session info, create a class that extends the com.hybris.cockpitng.util.js.JsWidgetSessionInfoDecorator, with the following signature:

JsWidgetSessionDTO decorate(JsWidgetSessionDTO dto)

Then, it has to be registered as in the Spring bean context and populated to extender (abstractJsWidgetSessionInfoCollectorExtender).

Further Steps

For the example of creating widgets using AngularJS, see Creating an AngularJS Widget.