Assignment class

Note

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.

This class manages the task progress, processes the task suite commands for sending responses, skipping or pausing tasks, and more. It also creates an instance of the TaskSuite class.

The Assignment base class is available in the window.TolokaAssignment global variable

Methods:

constructor(options)

Task list base class builder.

Parameters:

  • options.assignment — Assignment task list model.

  • options.specs — Parameters for input and output data and the task interface.

  • options.workspaceOptions — Toloker's workspace initialization parameters.

destroy()

Calls TaskSuite.destroy(), removes all template elements from the DOM, closes the messaging channel, stops hotkey polling and location detection, calls onDestroy.

initHotkeys()

Hotkey handler initializer:

getId()

Returns assignmentId as a string or undefined if you are debugging the task in preview mode or using pool preview.

getOptions()

Returns an object with a set of parameters passed to the constructor() method during initialization.

Example

getSandboxChannel()

Returns the link to an active messaging channel between the parent page and the task frame. If there is no channel, the method creates it.

Example

getTaskSuite()

Returns a link to a TaskSuite instance.

getTaskSuiteContainer()

Returns document.body for the Toloker's workspace.

getWorkspaceOptions()

Returns an object with the Toloker's workspace settings.

The most important settings:

  • agent — The value is FRONTEND for full task versions, ANDROID for the Android app, and so forth.

  • isReadOnly — "Read-only" mode flag (for example, for viewing the history of completed tasks).

  • isReviewMode — Review mode flag (for example, manual review). This setting and isReadOnly are useful if you want to do something like change the template layout in history view mode.

  • language — A two-letter code of the language selected by the Toloker in Toloka settings. It's useful when you want to create multilingual templates.

  • origin — Parent page FQDN.

pause()

Pauses task execution (for example, upon a request:assignment:pause command from the main page), calls onPause.

provideSolutions(strategy)

Collects answers to all tasks (TolokaTaskSuite.getSolutions()), validates them (TolokaTaskSuite.validate()). If validation is successful, calls strategy, otherwise sends an assignment:validation:fail request and an object with a list of errors returned by the validator. Parameter:

  • strategy — A function that sends a message about sending results (assignment:submit), a response array, and an assignmentId to the parent page.
Example

resume()

Continues task execution, calls onResume and start().

skip()

Lets you skip the current task, the same as clicking the Skip button.

start()

Performs all the necessary actions when starting a task suite:

  • Adds the rendered task interface to document.body.

  • Initializes hotkeys for the entire interface (InitHotkeys()).

  • Calls onStart.

submit()

Collects, validates and sends completed tasks by calling provideSolutions.

Example
Contact support

Last updated: February 15, 2023

Introduction
Getting started
Important tips
Useful recommendations
Working with Toloka
Projects
Pools
Tasks
Results
Project analysis
Toloka settings
Task interface
Template Builder
HTML/CSS/JS editor
Help and support
FAQTroubleshootingSupportGlossary