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:
- Object.<Application>
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:
- Folder | null
Example
A Document may belong to a Folder
let folder = game.folders.entities[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
link
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.ENTITY_PERMISSIONS 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:
- FormApplication | null
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, optionsopt) → {Promise.<Document>}
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 | Description |
---|---|---|---|
data |
object | Initial data with which to populate the creation form |
|
options |
object |
<optional> |
Positioning and sizing options for the resulting dialog |
Returns:
A Promise which resolves to the created Document
- Type
- Promise.<Document>
(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:
- A compendium pack and entry id
- A World Entity _id
- 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
|
Returns:
The Document data that should be handled by the drop handler
- Type
- Promise.<(Document|null)>
_initialize()
_onCreate()
_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()
_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()
_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()
Export entity data to a JSON file which can be saved by the client and later imported into a different session.
(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.
prepareEmbeddedEntities()
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) → {object}
Transform the Document data to be stored in a Compendium pack. Remove any features of the data which are world-specific. This function is asynchronous in case any complex operations are required prior to exporting.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
pack |
CompendiumCollection |
<optional> |
A specific pack being exported to |
Returns:
A data object of cleaned data suitable for compendium import
- Type
- object