Class: EntityModel

Drupal.quickedit. EntityModel

new Drupal.quickedit.EntityModel()

Extends

Members

staticDrupal.quickedit.EntityModel.statesArray.<string>

Sequence of all possible states an entity can be in during quickediting.

defaultsobject

elHTMLElement

The DOM element that represents this entity.

It may seem bizarre to have a DOM element in a Backbone Model, but we need to be able to map entities in the DOM to EntityModels in memory.

entityIDstring

An entity ID, of the form <entity type>/<entity ID>

Example
"node/1"

entityInstanceIDnumber

An entity instance ID.

The first instance of a specific entity (i.e. with a given entity ID) is assigned 0, the second 1, and so on.

A FieldCollection for all fields of the entity.

See:

fieldsInTempStoreArray.<string>

IDs of fields whose new values have been stored in PrivateTempStore.

We must store this on the EntityModel as well (even though it already is on the FieldModel) because when a field is rerendered, its FieldModel is destroyed and this allows us to transition it back to the proper state.

idstring

The unique ID of this entity instance on the page, of the form <entity type>/<entity ID>[entity instance ID]

Example
"node/1[0]"

inTempStorebool

Whether one or more fields are already been stored in PrivateTempStore.

isActivebool

Indicates whether this entity is currently being edited in-place.

isCommittingbool

Whether the request to the server has been made to commit this entity.

Used to prevent multiple such requests.

isDirtybool

Indicates whether a "Save" button is necessary or not.

Whether one or more fields have already been stored in PrivateTempStore or the field that's currently being edited is in the 'changed' or a later state.

labelstring

The label of the entity.

reloadbool

A flag the tells the application that this EntityModel must be reloaded in order to restore the original values to its fields in the client.

statestring

The current processing state of an entity.

Methods

staticDrupal.quickedit.EntityModel.followsStateSequence(from, to){bool}

Indicates whether the 'from' state comes before the 'to' state.

Name Type Description
from string

One of Drupal.quickedit.EntityModel.states.

to string

One of Drupal.quickedit.EntityModel.states.

Returns:
Type Description
bool Whether the 'from' state comes before the 'to' state.

_acceptStateChange(from, to, context){bool}

Checks if a state change can be accepted.

Name Type Description
from string

From state.

to string

To state.

context object

Context for the check.

Name Type Description
reason string

The reason for the state change.

confirming bool

Whether context is confirming or not.

See:
Returns:
Type Description
bool Whether the state change is accepted or not.

_fieldsHaveAcceptableStates(acceptedFieldStates){bool}

Checks if fields have acceptable states.

Name Type Description
acceptedFieldStates Array

An array of acceptable field states to check for.

See:
Returns:
Type Description
bool Whether the fields have an acceptable state.

_updateInTempStoreAttributes(entityModel, fieldModel)

Updates a Field and Entity model's "inTempStore" when appropriate.

Helper function.

Name Type Description
entityModel Drupal.quickedit.EntityModel

The model of the entity for which a field's state attribute has changed.

fieldModel Drupal.quickedit.FieldModel

The model of the field whose state attribute has changed.

See:

Destroys the entity model.

Name Type Description
options object

Options for the entity model.

fieldStateChange(fieldModel, state)

Reacts to state changes in this entity's fields.

Name Type Description
fieldModel Drupal.quickedit.FieldModel

The model of the field whose state attribute changed.

state string

The state of the associated field. One of Drupal.quickedit.FieldModel.states.

Fires an AJAX request to the REST save URL for an entity.

Name Type Description
options object

An object of options that contains:

Name Type Description
success function optional

A function to invoke if the entity is successfully saved.

Set a value on the model

Name Type Description
key object | string

The key to set a value for.

val *

The value to set.

options object optional

Options for the model.

Returns:
Type Description
* The result of Backbone.Model.prototype.set with the specified parameters.

stateChange(entityModel, state, options)

Updates FieldModels' states when an EntityModel change occurs.

Name Type Description
entityModel Drupal.quickedit.EntityModel

The entity model

state string

The state of the associated entity. One of Drupal.quickedit.EntityModel.states.

options object

Options for the entity model.

validate(attrs, options){string}

Validate the entity model.

Name Type Description
attrs object

The attributes changes in the save or set call.

options object

An object with the following option:

Name Type Description
reason string optional

A string that conveys a particular reason to allow for an exceptional state change.

accept-field-states Array

An array of strings that represent field states that the entities must be in to validate. For example, if accept-field-states is ['candidate', 'highlighted'], then all the fields of the entity must be in either of these two states for the save or set call to validate and proceed.

Returns:
Type Description
string A string to say something about the state of the entity model.