Configurable Widgets
Widgets can be configurable. This means that a portion of your widget can be changed at runtime through configuration, allowing it to, for example, use different data, look slightly different, or perform a different navigation.
An example would be a widget containing a list of your 10 latest orders. Through configuration, you could add a property that filters this list based on the order total to only show orders with an order total greater than $1000.
The idea is that through configuration, you can have a single Widget class with slightly different data or behavior, without having to completely create a new Widget for this. You can have multiple instances of this Widget in a container, and by using configuration, they’ll look or behave slightly different.
The steps to make a widget configurable are as follows:
- Optionally add new Web Properties to your widget to be used for configuration.
- Mark which properties are configurable:
- Use
OnGetConfigurablePropsfor this in the Widget. Add yourtWidgetConfigPropto the ByRef Array. - Use
CreateConfigurablePropfunction for convenience to get you started, passing the Object handle and Property to make configurable. - Use the
(Widget(Self))instruction if your property exists in the Widget root. - Attach a
cWebWidgetConfigurationWizardto your Widget: - Set
phoConfigWizardto acWebWidgetConfigurationWizardimplementation. - You can build your own custom wizard or use the provided
cWebWidgetConfigurationWizardStandard. - Optionally manipulate a widget’s configurable state through
pbAllowConfigurationand the augmentableOnDetermineConfigurableStateevent.
To build a custom cWebWidgetConfigurationWizard:
- Create an object (or class if you want to create multiple instances) that’s a subclass of
cWebWidgetConfigurationWizard. - The wizard is basically a dialog with some interface logic in there. Place any DataDictionaries, Controls, etc., that you need inside.
- Implement the following:
OnPopulateWizard: Comes with atWidgetConfigPropValuearray. Use this to populate your wizard’s controls with the Widget’s current configurable property values.- You can use
ParkPropValueto temporarily store a value for later use. Make sure you remember thesObjNameandsPropNameas these are used as the unique identifiers for retrieving viaRetrieveParkedPropValue. - Use convenience function
GetPropValuefor easier sifting through the array.
- You can use
OnGetConfigValues: Used when closing the wizard. Use this to get the new values from your Wizard’s controls so they can be fed back into the corresponding Widget. Comes with a ByReftWidgetConfigPropValuearray to be filled with the new values.- Use convenience function
SetPropValuefor easier adding of a value to the array. - Make sure the
sObjNameand thesPropNameof the new values match with the existing ones, as this is used to map to the Widget’s configurable property.
- Use convenience function