Class: EntityModel

Drupal.quickedit.EntityModel()

Extends

Members

(static) states :Array.<string>

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

Type:
  • Array.<string>
Source:

defaults :object

Type:
  • object
Source:

el :HTMLElement

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.

Type:
  • HTMLElement
Source:

entityID :string

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

Type:
  • string
Source:
Example
"node/1"

entityInstanceID :number

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.

Type:
  • number
Source:

fields :Drupal.quickedit.FieldCollection

A FieldCollection for all fields of the entity.

Type:
Source:
See:

fieldsInTempStore :Array.<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.

Type:
  • Array.<string>
Source:

id :string

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

Type:
  • string
Source:
Example
"node/1[0]"

inTempStore :bool

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

Type:
  • bool
Source:

isActive :bool

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

Type:
  • bool
Source:

isCommitting :bool

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

Used to prevent multiple such requests.

Type:
  • bool
Source:

isDirty :bool

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.

Type:
  • bool
Source:

label :string

The label of the entity.

Type:
  • string
Source:

reload :bool

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.

Type:
  • bool
Source:

state :string

The current processing state of an entity.

Type:
  • string
Source:

Methods

(static) followsStateSequence(from, to) → {bool}

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

Parameters:
Name Type Description
from string

One of Drupal.quickedit.EntityModel.states.

to string

One of Drupal.quickedit.EntityModel.states.

Source:
Returns:

Whether the 'from' state comes before the 'to' state.

Type
bool

_acceptStateChange(from, to, context) → {bool}

Checks if a state change can be accepted.

Parameters:
Name Type Description
from string

From state.

to string

To state.

context object

Context for the check.

Properties
Name Type Description
reason string

The reason for the state change.

confirming bool

Whether context is confirming or not.

Source:
See:
Returns:

Whether the state change is accepted or not.

Type
bool

_fieldsHaveAcceptableStates(acceptedFieldStates) → {bool}

Checks if fields have acceptable states.

Parameters:
Name Type Description
acceptedFieldStates Array

An array of acceptable field states to check for.

Source:
See:
Returns:

Whether the fields have an acceptable state.

Type
bool

_updateInTempStoreAttributes(entityModel, fieldModel)

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

Helper function.

Parameters:
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.

Source:
See:

destroy(options)

Destroys the entity model.

Parameters:
Name Type Description
options object

Options for the entity model.

Source:

fieldStateChange(fieldModel, state)

Reacts to state changes in this entity's fields.

Parameters:
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.

Source:

save(options)

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

Parameters:
Name Type Description
options object

An object of options that contains:

Properties
Name Type Attributes Description
success function <optional>

A function to invoke if the entity is successfully saved.

Source:

set(key, val, optionsopt) → {*}

Set a value on the model

Parameters:
Name Type Attributes Description
key object | string

The key to set a value for.

val *

The value to set.

options object <optional>

Options for the model.

Inherited From:
Source:
Returns:

The result of Backbone.Model.prototype.set with the specified parameters.

Type
*

stateChange(entityModel, state, options)

Updates FieldModels' states when an EntityModel change occurs.

Parameters:
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.

Source:

sync()

{@inheritdoc}

Source:

validate(attrs, options) → {string}

Validate the entity model.

Parameters:
Name Type Description
attrs object

The attributes changes in the save or set call.

options object

An object with the following option:

Properties
Name Type Attributes 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.

Source:
Returns:

A string to say something about the state of the entity model.

Type
string