Task class
The Task
base class is responsible for the task interface. This class is available in the global variable window.TolokaTask
.
Methods:
- constructor(options)
- The task UI constructor. Parameters:
options.task
— The Task task model.options.specs
— Parameters for input and output data and the task interface. See thetask_spec
object format.- options.workspaceOptions — Sandbox initialization parameters {{isReadOnly: boolean}}
- getOptions()
-
Returns the parameters passed to the
constructor()
method. - getWorkspaceOptions()
-
Returns the sandbox initialization parameters passed to the
constructor()
method. - getTask()
-
Returns the
Task
task model. - getSolution()
-
Returns the
Solution
task responses. - getProxyUrl(path)
- Returns the full URL for accessing data on the proxy server. Parameter:
path
— Relative file path.
- setSolution(solution)
- Sets the responses. Parameter:
solution
— The performer's response to the task (Solution
).
- getDOMElement()
-
Returns the DOM element of the task.
- getStyleDOMElement()
-
Returns a DOM element for task styles that is added to
document.head
when rendering. - validate(solution)
- Validates responses according to output data parameters. Returns
SolutionValidationError
if the responses are invalid, otherwisenull
. Parameter:solution
— The performer's response to the task. If omitted, the current one is used (getSolution()
).
- focus()
-
Implements the logic for setting the focus on the task by calling the
onFocus()
method. - blur()
-
Implements the logic for removing the focus from the task and calls the
onBlur()
method. - template(data)
- Template engine for the task. In the task's HTML interface, it replaces occurrences such as
${fieldX}
with the corresponding value and thefieldX
key from thedata
parameter. Returns the task's HTML interface as a string. Parameter:data
— Object with data to insert in the template.
- render()
-
Forms the DOM representation of the task interface. Calls
onRender()
. Returnsthis
. - destroy()
- Releases resources, services, and event handlers used in the global space. Calls
onDestroy()
. - onRender()
- Called after the task is rendered (
render()
). All manipulations with the DOM element of a task should be performed here. - onDestroy()
- Called after the task is destroyed (
destroy()
). The best method for releasing memory, deleting global event handlers and DOM elements, and so on. - onFocus()
- Called after setting the focus.
- onBlur()
- Called after removing the focus.
- onKey(key)
- Passes the pressed key. Parameter:
key
— Alphanumeric character pressed on the keyboard. Can be used as a shortcut.
- onValidationFail(errors)
- Called when the performer's response validation fails. Parameter:
errors
— Validation errors in the performer's responseSolutionValidationError
.