Classes

MaestroError

Maestro-specifc error class. This'll include category, optional error code, a human and a system message.

EventEmitter

Simple event dispatcher(emitter) to implement a pub/sub.

DataSourceBinder

Holds a connection between data and the DOM elements and manages the form submissions.

Constants

maestro : DataSourceBinder

The global pre-configured data source binder that should be used by the templates.

MaestroError

Maestro-specifc error class. This'll include category, optional error code, a human and a system message.

Kind: global class

new MaestroError(userMessage, systemMessage, core, category, innerException, extra)

Param Type Description
userMessage string A message that is good to be displayed to an end user.
systemMessage string A message for a technical person, perhaps a more specific and technical message.
core string A general purpose error code.
category string A category for the error.
innerException object linked exception related for this error.
extra object Arbitrary extra object.

maestroError.toObject()

Get a javascript object representing the error, good for serialization.

Kind: instance method of MaestroError

EventEmitter

Simple event dispatcher(emitter) to implement a pub/sub.

Kind: global class

eventEmitter.dispatch(type, sender, args)

Dispatch an event with its sender and parameters.

Kind: instance method of EventEmitter

Param Type Description
type string The name of the event.
sender object The sender of the event.
args object Optional event args for this event.

eventEmitter.addConsumer(type, consumer)

Subscribe to an event.

Kind: instance method of EventEmitter

Param Type Description
type string the name of the event to subscribe to.
consumer function a callback method. It'll receive (event) and every event has "sender", "type" and "args".

DataSourceBinder

Holds a connection between data and the DOM elements and manages the form submissions.

Kind: global class

new DataSourceBinder(referenceId, assignmentId, prefillData)

Param Type Description
referenceId string The reference ID for this question. This'll be provided to the handler so they can submit the data.
assignmentId string Optional assignment ID for this assignment (when preloading data for modification).
prefillData object Optional initial data mostly for prefilling the DOM elements.

dataSourceBinder.ignoreEmptyValues

Whether or not to ignore keys whose values are empty arrays, objects or strings.

Kind: instance property of DataSourceBinder
Default: false

dataSourceBinder.autoInstallData

Whether or not to install prefill data automatically after DOM elements are loaded.

Kind: instance property of DataSourceBinder
Default: true

dataSourceBinder.autoInstallOnForms

Whether or not to set maestro as the handler for form submissions automatically after DOM elements are loaded.

Kind: instance property of DataSourceBinder
Default: true

dataSourceBinder.locked

Gets or sets whether maestro.submit() is locked.

Kind: instance property of DataSourceBinder

dataSourceBinder.referenceId

Get the reference ID for this question.

Kind: instance property of DataSourceBinder
Read only: true

dataSourceBinder.assignmentId

Get the assignment ID for this assignment (if one is available).

Kind: instance property of DataSourceBinder
Read only: true

dataSourceBinder.inEditMode

Returns whether or not this data source binder is in edit mode (pre-existing data and an assignment id).

Kind: instance property of DataSourceBinder
Read only: true

dataSourceBinder.data

Get the current data. This gets updated after form submissions and calls to collect() method.

Kind: instance property of DataSourceBinder
Read only: true

dataSourceBinder.handler

Gets or sets the current submit handler for this binder.

Kind: instance property of DataSourceBinder

dataSourceBinder.on(event, cb)

Kind: instance method of DataSourceBinder

Param Type Description
event string The event to subscribe to.
cb function The callback method.

dataSourceBinder.scan(element, root, currentObj, visitedNodes)

Looks through all DOM elements and fill the provided currentObj with collected values. This method gets access to the root data in case absolute key paths are used. currentObj needs to be the object inside the root object where the relative key paths are going to be starting from.

Kind: instance method of DataSourceBinder

Param Type Description
element DOM The root dom element to start the search from. Use document to search from the top.
root object The root object.
currentObj object The current object that will used for relative key paths. This MUST exist in the root object. When starting from root, set currentObj to null.
visitedNodes Set The set of already visited nodes. These nodes will get ignored.

Example

let root = {
  'user': {}
};
let currentObj = root.user;
// In the example above, keypath "info" would be relative to currentObj so user.info in root would get set.
// However, ".info" would be an absolute keypath and it would set "info" in the root object.

dataSourceBinder.collect()

Search the DOM elements and collect all the data. This method replaces the existing data. Emits "data_ready" event

Kind: instance method of DataSourceBinder

dataSourceBinder.submit()

Try to collect and submit the data to the appropriate service. A supporting handler should exist for this to work. To catch errors and try again, set a delegate. Emits "fail" and "success" events.

Kind: instance method of DataSourceBinder

dataSourceBinder.installOnForms()

Scan the DOM elements and replace the action with maestro form handler. Ignoring any form that has 'dignore="1"' on it.

Kind: instance method of DataSourceBinder

dataSourceBinder.installData()

Scan the DOM elements and install the existing data on the elements. Emits "data_installation" event upon success.

Kind: instance method of DataSourceBinder

DataSourceBinder.resolve(obj, parts)

Return the value in the obj given the key path.

Kind: static method of DataSourceBinder

Param Type Description
obj object The object to search from.
parts list this is a list of strings for each part. For example, for key path a.b.c, ['a', 'b', 'c'] needs to be passed.

DataSourceBinder.updateValue(obj, key, value, action)

Sets the value for the given key path in the provided object.

Kind: static method of DataSourceBinder

Param Type Description
obj object The target object, where the new value is going to live in.
key string The key path for the object. e.x. "user.info.name"
value any The value to be set.
action string The action to use for inserting this new object. "set" will replace any existing item. "append" will use an array and append the provided value.

maestro : DataSourceBinder

The global pre-configured data source binder that should be used by the templates.

Kind: global constant
Example

maestro.on("fail", ev => console.log(ev.args.error));
maestro.on("data_ready", ev => console.log(ev.args));
maestro.collect();  // to collect the data so maestro.data is available.
maestro.submit()  // to manually post the data, this'll make a call to collection() method.