The task interface configuration guide describes the features of the HTML/JS/CSS editor. You can also try creating a task interface in Template Builder.
The Task
base class is responsible for the task interface. This class is available in the global variable window.TolokaTask
.
Methods:
Implements the logic for removing the focus from the task and calls the onBlur() method.
The task UI constructor.
Parameters:
options.task
— The Task model.
options.specs
— Parameters for input and output data and the task interface.
options.workspaceOptions
— Toloker's workspace initialization parameters.
Releases resources, services, and event handlers used in the global space. Calls onDestroy().
Implements the logic for setting the focus on the task by calling the onFocus() method.
Returns a link to an instance of the TolokaAssignment
class. After that, you can access all its properties and methods.
Returns the DOM element of the task.
Returns an object with a set of parameters passed to the constructor() method during initialization.
Returns a complete URL to access the data on the proxy server. Parameter:
path
— the relative path to the file.Returns the saved state of the task (object).
Retrieves the saved state of the task from the browser's local storage using the TASK_STATE:{assignmentId}:{taskId}
key.
Returns the Solution task responses.
Returns a DOM element for task styles that is added to document.head
when rendering.
Returns the Task task model.
Returns the object received by the template engine before compiling the task template.
The method is available in toloka-handlebars-templates. It returns a set of fields and their values passed to the task input: return this.getTask().input_values
.
The method allows you to process the existing values or pass new custom parameters to the template engine. For example, you can pass strings for localizing a template and use the same project for English-speaking and Spanish-speaking Tolokers.
Returns the Toloker's workspace initialization parameters passed to the constructor()
method.
Hides a global error (only if the toloka-handlebars-templates library is connected).
Contains the current task's id
.
Called after removing the focus.
Called after the task is destroyed (destroy()). The best method for releasing memory, deleting global event handlers and DOM elements, and so on.
Called after setting the focus.
Passes the pressed key. Parameter:
key
— Alphanumeric character pressed on the keyboard. Can be used as a shortcut.Called after the task is put on pause.
Called after the task is rendered (render()). All manipulations with the DOM element of a task should be performed here.
Called after the task is resumed.
Called when the Toloker's response validation fails. Parameter:
errors
— Validation errors in the Toloker's response SolutionValidationError.Pauses task completion. Saves the intermediate state of the task in the browser's local storage (saveState
) and calls the onPause
method.
Makes a GET or POST request through a proxy.
Parameters:
path
— the path for the request (string).
options
— the request parameters (object). More information in the Jquery Ajax parameter description.
Returns the promise
object.
Some features are not supported (for example, timeouts and custom headers).
Forms the DOM representation of the task interface. Calls onRender(). Returns this
.
Resumes task completion. Retrieves the saved state of the task from the browser's local storage. Restores responses from it and re-executes the requests in the file and webview services that were not completed before. Calls onResume
.
Checks assignmentId
to make sure that the task is working in Toloker mode and not in preview mode. Receives a set of responses and unprocessed requests in the file and webview services. Saves them in the browser's local storage with the TASK_STATE:{assignmentId}:{taskId}
key using the storage service.
Sets the responses. Parameter:
solution
— The Toloker's response to the task (Solution).Writes the required value in the specified field. Parameters:
fieldName
— A field (string) in the output specification, to which the value is passed.
value
— The value of the type set for fieldName
in the project specification.
Updates the output specification by writing the passed object with responses in it. Calls saveState
to save intermediate results in the browser's local storage. Parameter:
outputValues
— Object with responses.Forcibly shows a global error in the task (only if the toloka-handlebars-templates library is connected). Parameters:
message
— Error text (string).Template engine for the task. In the task's HTML interface, it replaces occurrences such as ${fieldX}
with the corresponding value and the fieldX
key from the data
parameter. Returns the task's HTML interface as a string. Parameter:
data
— Object with data to insert in the template.Validates responses according to output data parameters. Returns SolutionValidationError if the responses are invalid, otherwise null
. Parameter:
solution
— The Toloker's response to the task. If omitted, the current one is used (getSolution()).Last updated: February 15, 2023