TaskSuite class

A “wrapper” class for a task page. It creates instances of task classes. You can redefine this class (for example, if you need to display a shared element on the page with tasks or get more control over tasks, like custom keyboard shortcuts).

The main purpose of the TaskSuite class is to render tasks on the page (the #render() method). It is also used for collecting responses (getSolutions()), validating them (validate(solutions)) and managing keyboard shortcuts (focusNextTask(), onKey(key) and so on).

The base class for TaskSuite is available in the window.TolokaTaskSuite global variable.

Methods:

constructor(options)
Constructor for the base class of the task page. Parameters:
  • options.task — Array of Task models.
  • options.specs — Parameters for input and output data and the task interface. See the task_spec object format.
  • options.assignmentId — IDs of tasks on the page.
  • options.workspaceOptions — Sandbox initialization parameters {{isReadOnly: boolean}}
  • options.TaskClass — Array of classes for the task you create.
  • options.solutions — Array of Solution responses. Can be empty.
getOptions()

Returns the parameters passed to the constructor() method.

getWorkspaceOptions()

Returns the sandbox initialization parameters passed to the constructor() method.

getTasks()

Returns an array of Task initialized task models.

getTasksIndexed()
Returns tasks indexed by their IDs: "<taskId>": Task, …
getSolutions()

Returns an array of Solution responses.

getProxyUrl(path)
Returns the full URL for accessing data on the proxy server. Parameter:
  • path — Relative file path.
getDOMElement()

Returns the DOM element of the page styles.

getStyleDOMElement()

Returns the DOM element of the page (it is empty before rendering, and after rendering it is initialized and contains the interface).

validate(solutions)
Validates responses according to output data parameters. Returns a promise with an array of SolutionValidationError errors if the responses are incorrect, or null. Parameter:
  • solutions — Array of the performer's task responses. If omitted, the current values are used (getSolutions()).
initHotkeys()
Hotkey handler initializer:
  • Sets the focus to the previous task when the left arrow or up arrow is pressed.
  • Sets the focus to the next task when the right arrow or down arrow is pressed.
  • Passes the pressed keys to the active task.
  • Sets the focus on the first task.
focusTask(index)
Sets the focus on the task by the index. Parameter:
  • index — Task index on the page.
focusNextTask()
Sets the focus on the next task.
focusPreviousTask()
Sets the focus on the previous task.
onKey(key)
Passes the pressed key to the active task.
render()

Creates a DOM representation of the task page: renders all tasks on the page. Calls render() in the Task class for each task. Calls onRender(). Returns this.

destroy()
Destroys all tasks on the page. Releases resources, services, and event handlers used in the global space. Calls onDestroy().
onRender()
Called after page rendering (render()). All manipulations with the DOM element of a task should be performed here.
onDestroy()
Called after the page is destroyed (destroy()). The best method for releasing memory, deleting global event handlers and DOM elements, and so on.
onValidationFail(errors)
Called if the validation failed. Contains error descriptions in the parameter. Parameter: