Client-side Scripting
Client-side scripting is done in sandboxed limited JavaScript. There are two places where JavaScript code is executed: exec nodes and input node onchange handlers.
All of the client-side script blocks must define a single self-contained function with the following signature:
function(model, context, api) {
/* ... */
}
model- the current Domain Entity this field belongs to or the parent Domain Entity in case ofexecnodescontext- current configuration stateapi- API object (see below)
All of these variables can easily be inspected by using console.log.
API object
The client-side API object provides the following methods:
api.getRef(ref: ModelRef): ModelInstance | null- lookup Domain Entity instance by reference object
api.getNode(): Node- get current scene-graph node
api.setModelValue(modelId: string, modelName: string, fieldName: string, value: any)- Causes a change delta in client-side just like editing a field would.
- Please note that all changes made in a client-side function are committed only after the function has returned.
Node object
The user interface of Konfoo is made up of Nodes that are arranged in a tree structure that is almost identical to the one you describe in the form definition file.
The Node object returned by api.getNode() provides the following interface:
isEnabled(): boolean- Returns the enabled state of the Node
setEnabled(enabled: boolean)- Sets the Node's enabled state. Nodes that are disabled are not displayed. This is useful for conditionally hiding nodes.
isLeaf(): boolean- Return
truewhen this Node contains no sub-nodes
- Return
getType(): NodeType- Returns Node type. Can be one of the following:
'MODEL''INPUT''EXEC''META''GROUP'
getModel(): Model- Returns the Model instance bound to this Node
getParent(): Node | null- Returns the parent Node of this Node or
nullif the Node is already the root node of the user interface scene hierarchy.
- Returns the parent Node of this Node or
getSubnodes(): Node[]- Returns a list of sub-nodes of the given Node.
findSubnode(metaKey: string, value: any): Node | null- Returns the first match of a direct sub-node of the given Node by matching the given metadata key to the given value.
- Returns
nullif no match was found.
findNeighbour(metaKey: string, value: any): Node | null- Returns the first match of neighbouring Node of the given Node by matching the given metadata key to the given value. This is equivalent of
node.getParent().findSubnode(...). - Returns
nullif no match was found.
- Returns the first match of neighbouring Node of the given Node by matching the given metadata key to the given value. This is equivalent of
getMetadata(key: string)- Returns a metadata value for a given key.
setMetadata(key: string, value: any)- Sets a metadata value for a given key.
Model object
The Model object is a client-side definition of the underlying Konfoo Domain Entity. This should be treated as read-only, any changes to Model state are not persisted in any way. This is Javascript though and you can do as you wish.