Creating an AngularJS Widget
In Backoffice Framework, the ZK framework is used by default, however it is not obligatory and you can use any other JavaScript framework. In this document, you can see an example of creating an HTML widget using AngularJS directives.
Context
The widget you are going create in this tutorial should be able to communicate with the Advanced Search Widget and the Advanced Search Engine Widget. Let's call the widget Angular Sample Widget and define it in the extension called angularCNG.
Creating Extension
To create AngularJS widget, you need a backoffice-based extension.
Context
At first, we need to create our custom backoffice-based extension:
Procedure
Defining Widget Dependencies
As it was decided to write this widget using AngularJS, you need to define a proper dependency in your extension.
Procedure
angularCNG/backoffice/resources/cng/js/js-libraries.xml
<libraries xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://www.hybris.com/schema/cockpitng/libraries.xsd">
<library>
<name>angular</name>
</library>
</libraries>
Creating Widget Definition
Start creating an AngularJS widget with its definition.
Procedure
angularCNG/backoffice/resources/widgets/angularwidget/definition.xml
<widget-definition xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.hybris.com/schema/cockpitng/widget-definition.xsd" id="example.cng.angular.widgets.angularwidget"> <name>Angular Sample Widget</name> <description>Sample widget using AngularJS</description> <defaultTitle>AngularJS Sample Widget</defaultTitle> <author>hybris</author> <version>1.0</version> <view src="angularwidget.html" /> <keywords> <keyword>AngularJS</keyword> </keywords> <sockets> <input id="input" type="java.lang.Object" /> <output id="output" type="<T>" /> </sockets> </widget-definition>
Defining Widget View
AngularJS widget needs to have a view defined.
Context
-
a view file, including HTML code:
angularCNG/backoffice/resources/widgets/angularwidget/angularwidget.html -
a script file, including some general-purpose methods, a controller, and a socket listener:
angularCNG/backoffice/resources/widgets/angularwidget/angularwidget.js
Procedure
Testing
To test the newly created widget, you need to deploy it to the application.
Procedure
- Append the new extension into the localextensions.xml and run ant all in the <HYBRIS_BIN_DIR>/ platform directory in the command prompt. Then start the server (by calling hybrisserver.bat or hybrisserver.sh).
- To test whether our new widget works as intended, open Backoffice in the Application Orchestrator mode (by pressing F4 on Windows or fn + F4 on Unix system).
- Open widgets settings
of the Border Layout widget and enable the east-slot (set the eastDisabled configuration property to false): - Add the newly created widget to the right slot of the Border Layout widget by pressing
icon and choosing the Angular Sample Widget from the list. - Exit Application Orchestrator mode to see the result.
- In the symbolic widgets view, change the connection between Advanced Search widget and the Advanced Search Engine widget - it should be passed through the Angular Sample Widget (the simplest way to achieve that is to remove the existing connections between the Advanced Search and the Advanced Search Engine and to create a new one).