Builds a promotion mechanic type, which is the behaviour behind a promotion such as a prize draw or an instant win. Obtained from promotionMechanicTypeBuilder on the controller mappings. Set the templates used to edit, summarise and show the mechanic to participants, plus the functions that create its metrics and save its details, then call build to register it. Both chained setters and plain bean setters are exported, so either style works from JavaScript.
Group: Builders
Properties
| Property | Returns | Description |
|---|---|---|
| createMetricsFn | String | Name of the function that creates the metrics recorded for promotions using this mechanic. |
| description | String | Description shown to administrators alongside the mechanic name. |
| editTemplate | String | Repository path of the template used to configure a promotion that uses this mechanic. |
| icon | String | Icon class shown beside the mechanic in the promotion editor. Defaults to a generic picture icon. |
| id | String | Unique identifier for the mechanic type, stored against promotions that use it. |
| participantTemplate | String | Repository path of the template shown to a participant taking part in the promotion. |
| saveMechanicDetailsFn | String | Name of the function called to save the mechanic's own settings when a promotion is saved. |
| summaryTemplate | String | Repository path of the template that renders the mechanic's summary in the admin promotion list. |
| supportsWebsite | boolean | Whether promotions using this mechanic can be run on a public website as well as in the admin console. |
| title | String | Human readable name shown when an administrator chooses a mechanic for a promotion. |
Methods
build() · getId() · getTitle() · getIcon() · getDescription() · setDescription(String description) · getEditTemplate() · setEditTemplate(String editTemplate) · getSummaryTemplate() · setSummaryTemplate(String summaryTemplate) · getParticipantTemplate() · setParticipantTemplate(String participantTemplate) · getCreateMetricsFn() · setCreateMetricsFn(String createMetricsFn) · getSaveMechanicDetailsFn() · setSaveMechanicDetailsFn(String saveMechanicDetailsFn) · isSupportsWebsite() · setSupportsWebsite(boolean supportsWebsite) · description(String s) · icon(String s) · editTemplate(String s) · summaryTemplate(String s) · participantTemplate(String s) · createMetricsFn(String s) · saveMechanicDetailsFn(String s) · supportsWebsite(boolean b) · configSchemaFn(String s) · readConfigFn(String s) · saveConfigFn(String s) · supportsConfigUpdate(boolean b)
build()
Returns: RepoAppPromotionMechanicType
Creates the promotion mechanic type from the configured values and registers it against this app. The type is still created and returned once the engine has initialised, but it is no longer registered.
getId()
Returns: String
Unique identifier for the mechanic type, stored against promotions that use it.
getTitle()
Returns: String
Human readable name shown when an administrator chooses a mechanic for a promotion.
getIcon()
Returns: String
Icon class shown beside the mechanic in the promotion editor. Defaults to a generic picture icon.
getDescription()
Returns: String
Description shown to administrators alongside the mechanic name.
setDescription(String description)
Returns: void
Sets the description shown to administrators alongside the mechanic name.
| Parameter | Description |
|---|---|
description | the description text |
getEditTemplate()
Returns: String
Repository path of the template used to configure a promotion that uses this mechanic.
setEditTemplate(String editTemplate)
Returns: void
Sets the repository path of the template used to configure a promotion that uses this mechanic.
| Parameter | Description |
|---|---|
editTemplate | the edit template path |
getSummaryTemplate()
Returns: String
Repository path of the template that renders the mechanic's summary in the admin promotion list.
setSummaryTemplate(String summaryTemplate)
Returns: void
Sets the repository path of the template that renders the mechanic's summary in the admin promotion list.
| Parameter | Description |
|---|---|
summaryTemplate | the summary template path |
getParticipantTemplate()
Returns: String
Repository path of the template shown to a participant taking part in the promotion.
setParticipantTemplate(String participantTemplate)
Returns: void
Sets the repository path of the template shown to a participant taking part in the promotion.
| Parameter | Description |
|---|---|
participantTemplate | the participant template path |
getCreateMetricsFn()
Returns: String
Name of the function that creates the metrics recorded for promotions using this mechanic.
setCreateMetricsFn(String createMetricsFn)
Returns: void
Sets the name of the function that creates the metrics recorded for promotions using this mechanic.
| Parameter | Description |
|---|---|
createMetricsFn | the create metrics function name |
getSaveMechanicDetailsFn()
Returns: String
Name of the function called to save the mechanic's own settings when a promotion is saved.
setSaveMechanicDetailsFn(String saveMechanicDetailsFn)
Returns: void
Sets the name of the function called to save the mechanic's own settings when a promotion is saved.
| Parameter | Description |
|---|---|
saveMechanicDetailsFn | the save details function name |
isSupportsWebsite()
Returns: boolean
Whether promotions using this mechanic can be run on a public website as well as in the admin console.
setSupportsWebsite(boolean supportsWebsite)
Returns: void
Sets whether promotions using this mechanic can be run on a public website.
| Parameter | Description |
|---|---|
supportsWebsite | true if the mechanic supports websites |
description(String s)
Returns: PromotionMechanicTypeBuilder
Sets the description shown to administrators alongside the mechanic name.
| Parameter | Description |
|---|---|
s | the description text |
icon(String s)
Returns: PromotionMechanicTypeBuilder
Sets the icon class shown beside the mechanic in the promotion editor, replacing the default picture icon.
| Parameter | Description |
|---|---|
s | the icon CSS classes |
editTemplate(String s)
Returns: PromotionMechanicTypeBuilder
Sets the repository path of the template used to configure a promotion that uses this mechanic.
| Parameter | Description |
|---|---|
s | the edit template path |
summaryTemplate(String s)
Returns: PromotionMechanicTypeBuilder
Sets the repository path of the template that renders the mechanic's summary in the admin promotion list.
| Parameter | Description |
|---|---|
s | the summary template path |
participantTemplate(String s)
Returns: PromotionMechanicTypeBuilder
Sets the repository path of the template shown to a participant taking part in the promotion.
| Parameter | Description |
|---|---|
s | the participant template path |
createMetricsFn(String s)
Returns: PromotionMechanicTypeBuilder
Sets the name of the function that creates the metrics recorded for promotions using this mechanic.
| Parameter | Description |
|---|---|
s | the create metrics function name |
saveMechanicDetailsFn(String s)
Returns: PromotionMechanicTypeBuilder
Sets the name of the function called to save the mechanic's own settings when a promotion is saved.
| Parameter | Description |
|---|---|
s | the save details function name |
supportsWebsite(boolean b)
Returns: PromotionMechanicTypeBuilder
Sets whether promotions using this mechanic can be run on a public website.
| Parameter | Description |
|---|---|
b | true if the mechanic supports websites |
configSchemaFn(String s)
Returns: PromotionMechanicTypeBuilder
Sets the name of the function returning this mechanic's settings as a JSON Schema, which is what lets a caller that never rendered the edit template - an AI tool, an importer - configure the mechanic. Without it the mechanic can only be set up through its own admin UI. The function takes no arguments and must return the schema as a JSON string, ie JSON.stringify(schema). It is called each time the schema is needed, so an enum may list what the account actually has, for example its points buckets.
| Parameter | Description |
|---|---|
s | the config schema function name |
readConfigFn(String s)
Returns: PromotionMechanicTypeBuilder
Sets the name of the function returning a promotion's current mechanic settings, in the shape the config schema describes. Needed for update as well as review: saving writes every setting from what it is given, so changing one means reading the rest back and passing them through unchanged. The function takes the promotion and must return the settings as a JSON string, ie JSON.stringify(config).
| Parameter | Description |
|---|---|
s | the read config function name |
saveConfigFn(String s)
Returns: PromotionMechanicTypeBuilder
Sets the name of the function saving a mechanic's settings from a configuration object rather than a form post. Only needed where the settings are nested or repeating: leave it unset and the configuration is flattened into form parameters and passed to the save mechanic details function, which is all a mechanic with flat settings needs. The function takes the promotion and the settings as a JSON string, and must return a JsonResult.
| Parameter | Description |
|---|---|
s | the save config function name |
supportsConfigUpdate(boolean b)
Returns: PromotionMechanicTypeBuilder
Sets whether saving over an existing configuration changes it. Several mechanics only ever create their configuration and ignore a second save, so saying so lets a caller offer update where it works and explain itself where it does not, rather than reporting a success that changed nothing.
| Parameter | Description |
|---|---|
b | true if the mechanic can be reconfigured after it has been set up |