Extension Points: Surf Widgets and Surf Extension Modules
Description:
This tutorial demonstrates how to customize an existing Surf JavaScript Widget by extending the out-of-the-box Documentlist widget so it shows a message every time a filter is changed. In previous versions of Content Services it was only possible to customize JavaScript widgets by copying existing code, modifying it, and then copying it onto the web extensions path. This was not efficient as it created a maintenance burden as the code needed to be managed through changes to the original widget.
Now logic and metadata about widget instantiation has been moved from the FreeMarker templates and moved into the JavaScript controller as this is easier to customize. The metadata is stored as a standardized object structure in the model, which is then processed by a new custom directive in the FreeMarker template to output the JavaScript code necessary to instantiate the specified widgets.
Existing JavaScript controller extension capabilities can be used so that Surf Extension Modules can modify the default metadata object(s) to change the following:
- The name of the JavaScript widget to be instantiated
- The arguments passed when instantiating the widget
- The variable that the instantiated widget is assigned to
- Whether or not i18n messages are set for the widget
- Whether or not additional options are applied to the widget
- The additional options that should be applied to the widget
FreeMarker templates use a common “boiler-plate” structure to ensure consistency across web script rendered components. Updated resource handling features in Surf are used to move all the CSS and JavaScript dependency requests into the template and remove the associated *.head.ftl file. A consistent pattern of <@markup> directives is used throughout the template to further enhance customization options.
The general take away from this tutorial is that most JavaScript Widget customizations that was previously done by changing out-of-the-box JavaScript code, can now be done via Surf Extension Modules and JavaScript object extensions.
Implementation Steps:
Customizing the Documentlist Widget in the Document Library involves the following steps:
- Generate/Use a Share JAR project (either stand-alone or as part of an All-in-One project)
- Create a Surf Extension Module containing the mapping between out-of-the-box widget and custom widget.
- Implement the custom Widget
- Override the documentlist-v2 web script to swap in the custom Widget
- Deploy the Surf Extension Module manually if it is not auto-deployed
Related Information:
This tutorial assumes that you are familiar with the Document Library in Share. Also, familiar yourself with how you can switch between different filters in the Document Library (that is, the navigation menu to the left in the DocLib).
This tutorial assumes you have created a new SDK All-In-One project.
Tutorial implementation steps: