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
Results
of the Border Layout widget and enable the east-slot (set the
icon and choosing the