Builds a points rule type, which decides whether a sales record earns points and how many. Obtained from pointsRuleTypeBuilder on the controller mappings. The include function filters which records the rule applies to, the process function returns the points to award, and the fields are the settings an administrator fills in when adding the rule to a points programme. Call build to register the rule type.
Group: Builders
Methods
build()
Returns: JsPointsRuleType
Creates the points rule type from the configured values and registers it against this app, initialising it against the app's engine. The type is still created and returned once the engine has initialised, but it is no longer registered.
includeFn(String s)
Returns: PointsRuleTypeBuilder
Names the function that decides whether a given sales record is covered by this rule. It is called with the record, the rule parameters, the allocation source and the points recipient, and should return a boolean. When no function is set every record is included.
| Parameter | Description |
|---|---|
s | name of the global JavaScript function that filters records |
processFn(String s)
Returns: PointsRuleTypeBuilder
Names the function that calculates the points to award for a record. It is called with the record, the rule parameters, the allocation source and the points recipient, and should return the number of points.
| Parameter | Description |
|---|---|
s | name of the global JavaScript function that calculates the points |
addField(String name, String title)
Returns: PointsRuleTypeBuilder
Adds a configuration field to the rule with just a name and a title.
| Parameter | Description |
|---|---|
name | name of the field, which is also the key its value is stored under |
title | label shown next to the field |
addField(String name, String text, String title)
Returns: PointsRuleTypeBuilder
Adds a configuration field to the rule with helper text alongside its title.
| Parameter | Description |
|---|---|
name | name of the field, which is also the key its value is stored under |
text | helper text shown with the field |
title | label shown next to the field |
addField(String name, String text, String title, String options)
Returns: PointsRuleTypeBuilder
Adds a configuration field to the rule from a short field definition string, parsed the same way as other app extra fields.
| Parameter | Description |
|---|---|
name | name of the field, which is also the key its value is stored under |
text | helper text shown with the field |
title | label shown next to the field |
options | field definition string giving the type and any options, may be null |
addField(String name, String text, String title, boolean required, List<String> options)
Returns: PointsRuleTypeBuilder
Adds a configuration field to the rule with a fixed list of select options.
| Parameter | Description |
|---|---|
name | name of the field, which is also the key its value is stored under |
text | helper text shown with the field |
title | label shown next to the field |
required | true if the administrator must supply a value |
options | the values offered in the field's drop down |
addFieldWithOptionsFn(String name, String text, String title, boolean required, Supplier optionsFn)
Returns: PointsRuleTypeBuilder
Adds a configuration field whose select options are produced by a supplier function called when the field is rendered, so the options can reflect current account data.
| Parameter | Description |
|---|---|
name | name of the field, which is also the key its value is stored under |
text | helper text shown with the field |
title | label shown next to the field |
required | true if the administrator must supply a value |
optionsFn | supplier called to produce the list of options |