ClientDocumentMixin

ClientDocumentMixin

A mixin which extends each Document definition with specialized client-side behaviors. This mixin defines the client-side interface for database operations and common document behaviors.

Extends

Members

apps :Object.<Application>

See:
  • Document#render

A collection of Application instances which should be re-rendered whenever this document is updated. The keys of this object are the application ids and the values are Application instances. Each Application in this object will have its render method called by Document#render.

Type:

collection :Collection

Return a reference to the parent Collection instance which contains this Document.

Type:

compendium :CompendiumCollection

A reference to the Compendium Collection which contains this Document, if any, otherwise undefined.

Type:

folder :Folder|null

Return a reference to the Folder to which this Document belongs, if any.

Type:
Example

A Document may belong to a Folder

let folder = game.folders.contents[0];
let actor = await Actor.create({name: "New Actor", folder: folder.id});
console.log(actor.data.folder); // folder.id;
console.log(actor.folder); // folder;

hasPlayerOwner :boolean

Test whether this Document is owned by any non-Gamemaster User.

Type:
  • boolean

isOwner :boolean

A boolean indicator for whether or not the current game User has ownership rights for this Document. Different Document types may have more specialized rules for what constitutes ownership.

Type:
  • boolean

limited :boolean

A boolean indicator for whether the current game User has exactly LIMITED visibility (and no greater).

Type:
  • boolean

Return a string which creates a dynamic link to this Document instance.

permission :number

Return the permission level that the current game User has over this Document. See the CONST.DOCUMENT_PERMISSION_LEVELS object for an enumeration of these levels.

Type:
  • number
Example
game.user.id; // "dkasjkkj23kjf"
actor.data.permission; // {default: 1, "dkasjkkj23kjf": 2};
actor.permission; // 2

sheet :FormApplication|null

Lazily obtain a FormApplication instance used to configure this Document, or null if no sheet is available.

Type:

uuid :string

A Universally Unique Identifier (uuid) for this Document instance.

Type:
  • string

visible :boolean

A boolean indicator for whether or not the current game User has at least limited visibility for this Document. Different Document types may have more specialized rules for what determines visibility.

Type:
  • boolean

Methods

(async, static) createDialog(data, contextopt) → {Promise.<(Document|null)>}

Present a Dialog form to create a new Document of this type. Choose a name and a type from a select menu of types.

Parameters:
Name Type Attributes Default Description
data object

Initial data with which to populate the creation form

context object <optional>
{}

Additional context options or dialog positioning options

Returns:

A Promise which resolves to the created Document, or null if the dialog was closed.

Type
Promise.<(Document|null)>

(async, static) fromDropData(data, optionsopt) → {Promise.<(Document|null)>}

A helper function to handle obtaining the relevant Document from dropped data provided via a DataTransfer event. The dropped data could have:

  1. A compendium pack and entry id
  2. A World Document _id
  3. A data object explicitly provided
Parameters:
Name Type Attributes Default Description
data object

The data object extracted from a DataTransfer event

options object <optional>
{}

Additional options which configure data retrieval

Properties
Name Type Attributes Default Description
importWorld boolean <optional>
false

Import the provided document data into the World, if it is not already a World-level Document reference

Returns:

The Document data that should be handled by the drop handler

Type
Promise.<(Document|null)>

_initialize()

See:

_onCreate()

See:

_onCreateEmbeddedDocuments(embeddedName, documents, result, options, userId)

Follow-up actions taken after a set of embedded Documents in this parent Document are created.

Parameters:
Name Type Description
embeddedName string

The name of the embedded Document type

documents Array.<Document>

An Array of created Documents

result Array.<object>

An Array of created data objects

options object

Options which modified the creation operation

userId string

The ID of the User who triggered the operation

_onDelete()

See:

_onDeleteEmbeddedDocuments(embeddedName, documents, result, options, userId)

Follow-up actions taken after a set of embedded Documents in this parent Document are deleted.

Parameters:
Name Type Description
embeddedName string

The name of the embedded Document type

documents Array.<Document>

An Array of deleted Documents

result Array.<object>

An Array of document IDs being deleted

options object

Options which modified the deletion operation

userId string

The ID of the User who triggered the operation

_onUpdate()

See:

_onUpdateEmbeddedDocuments(embeddedName, documents, result, options, userId)

Follow-up actions taken after a set of embedded Documents in this parent Document are updated.

Parameters:
Name Type Description
embeddedName string

The name of the embedded Document type

documents Array.<Document>

An Array of updated Documents

result Array.<object>

An Array of incremental data objects

options object

Options which modified the update operation

userId string

The ID of the User who triggered the operation

_preCreateEmbeddedDocuments(embeddedName, result, options, userId)

Preliminary actions taken before a set of embedded Documents in this parent Document are created.

Parameters:
Name Type Description
embeddedName string

The name of the embedded Document type

result Array.<object>

An Array of created data objects

options object

Options which modified the creation operation

userId string

The ID of the User who triggered the operation

_preDeleteEmbeddedDocuments(embeddedName, result, options, userId)

Preliminary actions taken before a set of embedded Documents in this parent Document are deleted.

Parameters:
Name Type Description
embeddedName string

The name of the embedded Document type

result Array.<object>

An Array of document IDs being deleted

options object

Options which modified the deletion operation

userId string

The ID of the User who triggered the operation

_preUpdateEmbeddedDocuments(embeddedName, result, options, userId)

Preliminary actions taken before a set of embedded Documents in this parent Document are updated.

Parameters:
Name Type Description
embeddedName string

The name of the embedded Document type

result Array.<object>

An Array of incremental data objects

options object

Options which modified the update operation

userId string

The ID of the User who triggered the operation

exportToJSON(optionsopt)

Export document data to a JSON file which can be saved by the client and later imported into a different session.

Parameters:
Name Type Attributes Description
options object <optional>

Additional options passed to the ClientDocumentMixin#toCompendium method

(async) importFromJSON(json) → {Promise.<Document>}

Update this Document using a provided JSON string.

Parameters:
Name Type Description
json string

JSON data string

Returns:

The updated Document

Type
Promise.<Document>

(async) importFromJSONDialog() → {Promise.<void>}

Render an import dialog for updating the data related to this Document through an exported JSON file

Returns:
Type
Promise.<void>

prepareBaseData()

Prepare data related to this Document itself, before any embedded Documents or derived data is computed.

prepareData()

Prepare data for the Document. Begin by resetting the prepared data back to its source state. Next prepare any embedded Documents and compute any derived data elements.

prepareDerivedData()

Apply transformations or derivations to the values of the source data object. Compute data fields whose values are not stored to the database.

prepareEmbeddedDocuments()

Prepare all embedded Document instances which exist within this primary Document.

render(forceopt, contextopt)

See:

Render all of the Application instances which are connected to this document by calling their respective

Parameters:
Name Type Attributes Default Description
force boolean <optional>
false

Force rendering

context object <optional>
{}

Optional context

(async) sortRelative(optionsopt) → {Promise.<Document>}

Determine the sort order for this Document by positioning it relative a target sibling. See SortingHelper.performIntegerSort for more details

Parameters:
Name Type Attributes Description
options object <optional>

Sorting options provided to SortingHelper.performIntegerSort

Returns:

The Document after it has been re-sorted

Type
Promise.<Document>

toCompendium(packopt, optionsopt) → {object}

Transform the Document data to be stored in a Compendium pack. Remove any features of the data which are world-specific.

Parameters:
Name Type Attributes Description
pack CompendiumCollection <optional>

A specific pack being exported to

options object <optional>

Additional options which modify how the document is converted

Properties
Name Type Attributes Default Description
clearFlags boolean <optional>
false

Clear the flags object

clearSort boolean <optional>
true

Clear the currently assigned folder and sort order

clearPermissions boolean <optional>
true

Clear document permissions

clearState boolean <optional>
true

Clear fields which store document state

keepId boolean <optional>
false

Retain the current Document id

Returns:

A data object of cleaned data suitable for compendium import

Type
object