new EditableRootCollection(eventHandlers)
Creates a new asynchronous editable root collection instance.
The name of the model type available as: <instance>.constructor.modelType, returns 'EditableRootCollection'.
Parameters:
Name | Type | Argument | Description |
---|---|---|---|
eventHandlers |
bo.shared.EventHandlerList |
<optional> |
The event handlers of the instance. |
Fires:
- EditableRootCollection#event:preCreate
- EditableRootCollection#event:postCreate
- EditableRootCollection#event:preFetch
- EditableRootCollection#event:postFetch
- EditableRootCollection#event:preInsert
- EditableRootCollection#event:postInsert
- EditableRootCollection#event:preUpdate
- EditableRootCollection#event:postUpdate
- EditableRootCollection#event:preRemove
- EditableRootCollection#event:postRemove
- EditableRootCollection#event:preSave
- EditableRootCollection#event:postSave
Throws:
Extends
Members
-
<readonly> $modelName :string
-
The name of the model.
Type:
- string
-
<readonly> count :number
-
The count of the child objects in the collection.
Type:
- number
Methods
-
<static> create(eventHandlers, callback)
-
Creates a new editable business object collection.
Parameters:
Name Type Argument Description eventHandlers
bo.shared.EventHandlerList <optional>
The event handlers of the instance.
callback
external.cbDataPortal Returns a new editable business object collection.
Throws:
-
Argument error: The event handlers must be an EventHandlerList object or null.
-
Authorization error: The user has no permission to execute the action.
-
Data portal error: Creating the business object collection has failed.
-
-
<static> fetch(filter, method, eventHandlers, callback)
-
Retrieves an editable business object collection from the repository.
Parameters:
Name Type Argument Description filter
* <optional>
The filter criteria.
method
string <optional>
An alternative fetch method of the data access object.
eventHandlers
bo.shared.EventHandlerList <optional>
The event handlers of the instance.
callback
external.cbDataPortal Returns the required editable business object collection.
Throws:
-
Argument error: The method must be a string or null.
-
Argument error: The event handlers must be an EventHandlerList object or null.
-
Authorization error: The user has no permission to execute the action.
-
Data portal error: Fetching the business object collection has failed.
-
-
at(index) → {EditableChildModel}
-
Gets a collection item at a specific position.
Parameters:
Name Type Description index
number The index of the required item in the collection.
Returns:
The required collection item.
- Type
- EditableChildModel
-
checkRules()
-
Executes all the validation rules of the business object, including the ones of its child objects.
-
<protected> childHasChanged()
-
Notes that a child object has changed.
This method is called by child objects. -
<protected> create(callback)
-
Initializes a newly created business object collection.
This method is called by a factory method with the same name.Parameters:
Name Type Description callback
external.cbDataPortal Returns a new editable business object collection.
Throws:
-
Argument error: The callback must be a function.
-
Authorization error: The user has no permission to execute the action.
-
Data portal error: Creating the business object collection has failed.
-
-
create(index, callback)
-
Creates a new item and adds it to the collection at the specified index.
Parameters:
Name Type Description index
number The index of the new item.
callback
external.cbDataPortal Returns the newly created business object of the collection.
-
every(callback) → {boolean}
-
Tests whether all items in the collection pass the test implemented by the provided function.
Parameters:
Name Type Description callback
external.cbCollectionItem Function to test for each collection item.
Returns:
True when callback returns truthy value for each item, otherwise false.
- Type
- boolean
-
<protected> fetch(filter, method, callback)
-
Initializes a business object collection to be retrieved from the repository.
This method is called by a factory method with the same name.Parameters:
Name Type Argument Description filter
* <optional>
The filter criteria.
method
string <optional>
An alternative fetch method of the data access object.
callback
external.cbDataPortal Returns the required editable business object collection.
Throws:
-
Argument error: The method must be a string or null.
-
Argument error: The callback must be a function.
-
Authorization error: The user has no permission to execute the action.
-
Data portal error: Fetching the business object collection has failed.
-
-
filter(callback) → {Array.<EditableChildModel>}
-
Creates a new array with all collection items that pass the test implemented by the provided function.
Parameters:
Name Type Description callback
external.cbCollectionItem Function to test for each collection item.
Returns:
The new array of collection items.
- Type
- Array.<EditableChildModel>
-
forEach(callback)
-
Executes a provided function once per collection item.
Parameters:
Name Type Description callback
external.cbCollectionItem Function that produces an item of the new collection.
-
fromCto(cto, callback)
-
Rebuilds the business object collection from a plain object array sent by the client.
Parameters:
Name Type Description cto
object The client transfer object.
callback
external.cbFromCto Returns the eventual error.
-
getBrokenRules(namespace) → {bo.rules.BrokenRulesOutput}
-
Gets the broken rules of the business object.
Parameters:
Name Type Argument Description namespace
string <optional>
The namespace of the message keys when messages are localizable.
Returns:
The broken rules of the business object.
-
getModelState() → {string}
-
Gets the state of the collection. Valid states are: pristine, created, changed, markedForRemoval and removed.
Returns:
The state of the collection.
- Type
- string
-
getResponse(message, namespace) → {bo.rules.BrokenRulesResponse}
-
Gets the response to send to the client in case of broken rules.
Parameters:
Name Type Argument Description message
string <optional>
Human-readable description of the reason of the failure.
namespace
string <optional>
The namespace of the message keys when messages are localizable.
Returns:
The broken rules response to send to the client.
-
isDeleted() → {boolean}
-
Indicates whether the business object collection will be deleted from the repository, i.e. its state is markedForRemoval.
Returns:
True when the business object collection will be deleted, otherwise false.
- Type
- boolean
-
isDirty() → {boolean}
-
Indicates whether the business object collection itself or any of its child objects differs the one that is stored in the repository, i.e. its state is created, changed or markedForRemoval.
Returns:
True when the business object collection has been changed, otherwise false.
- Type
- boolean
-
isNew() → {boolean}
-
Indicates whether the business object collection has been created newly and not has been yet saved, i.e. its state is created.
Returns:
True when the business object collection is new, otherwise false.
- Type
- boolean
-
isSavable() → {boolean}
-
Indicates whether the business object collection can be saved to the repository, i.e. it has ben changed and is valid, and the user has permission to save it.
Returns:
True when the user can save the business object collection, otherwise false.
- Type
- boolean
-
isSelfDirty() → {boolean}
-
Indicates whether the business object collection itself, ignoring its child objects, differs the one that is stored in the repository.
Returns:
True when the business object collection itself has been changed, otherwise false.
- Type
- boolean
-
isValid() → {boolean}
-
Indicates whether all validation rules of all business objects of the collection succeeds. A valid business object collection may have broken rules with severity of success, information and warning.
Returns:
True when the business object collection is valid, otherwise false.
- Type
- boolean
-
map(callback) → {Array.<*>}
-
Creates a new array with the results of calling a provided function on every item in this collection.
Parameters:
Name Type Description callback
external.cbCollectionItem Function to test for each collection item.
Returns:
The new array of callback results.
- Type
- Array.<*>
-
remove()
-
Marks the business object collection to be deleted from the repository on next save.
-
save(callback)
-
Saves the changes of the business object collection to the repository.
Parameters:
Name Type Description callback
external.cbDataPortal Returns the business object collection with the new state after the save.
Throws:
-
Argument error: The callback must be a function.
-
Authorization error: The user has no permission to execute the action.
-
Data portal error: Inserting the business object collection has failed.
-
Data portal error: Updating the business object collection has failed.
-
Data portal error: Deleting the business object collection has failed.
-
-
some(callback) → {boolean}
-
Tests whether some item in the collection pass the test implemented by the provided function.
Parameters:
Name Type Description callback
external.cbCollectionItem Function to test for each collection item.
Returns:
True when callback returns truthy value for some item, otherwise false.
- Type
- boolean
-
sort(fnCompare) → {Array.<EditableChildModel>}
-
Sorts the items of the collection in place and returns the collection.
Parameters:
Name Type Argument Description fnCompare
external.cbCompare <optional>
Function that defines the sort order. If omitted, the collection is sorted according to each character's Unicode code point value, according to the string conversion of each item.
Returns:
The sorted collection.
- Type
- Array.<EditableChildModel>
-
toCto() → {object}
-
Transforms the business object collection to a plain object array to send to the client.
Returns:
The client transfer object.
- Type
- object
Events
-
postCreate
-
The event arises after the business object collection has been initialized in the repository.
Parameters:
Name Type Description eventArgs
bo.shared.DataPortalEventArgs Data portal event arguments.
newObject
EditableRootCollection The instance of the collection after the data portal action.
-
postFetch
-
The event arises after the collection instance has been retrieved from the repository.
Parameters:
Name Type Description eventArgs
bo.shared.DataPortalEventArgs Data portal event arguments.
newObject
EditableRootCollection The collection instance after the data portal action.
-
postInsert
-
The event arises after the business object collection has been created in the repository.
Parameters:
Name Type Description eventArgs
bo.shared.DataPortalEventArgs Data portal event arguments.
newObject
EditableRootCollection The instance of the collection after the data portal action.
-
postRemove
-
The event arises after the business object collection has been removed from the repository.
Parameters:
Name Type Description eventArgs
bo.shared.DataPortalEventArgs Data portal event arguments.
newObject
EditableRootCollection The instance of the collection after the data portal action.
-
postSave
-
The event arises after the business object collection has been saved in the repository. The event is preceded by a postInsert, postUpdate or postRemove event depending on the state of the business object collection.
Parameters:
Name Type Description eventArgs
bo.shared.DataPortalEventArgs Data portal event arguments.
newObject
EditableRootCollection The instance of the collection after the data portal action.
-
postUpdate
-
The event arises after the business object collection has been updated in the repository.
Parameters:
Name Type Description eventArgs
bo.shared.DataPortalEventArgs Data portal event arguments.
newObject
EditableRootCollection The instance of the collection after the data portal action.
-
preCreate
-
The event arises before the business object collection will be initialized in the repository.
Parameters:
Name Type Description eventArgs
bo.shared.DataPortalEventArgs Data portal event arguments.
oldObject
EditableRootCollection The instance of the collection before the data portal action.
-
preFetch
-
The event arises before the collection instance will be retrieved from the repository.
Parameters:
Name Type Description eventArgs
bo.shared.DataPortalEventArgs Data portal event arguments.
oldObject
EditableRootCollection The collection instance before the data portal action.
-
preInsert
-
The event arises before the business object collection will be created in the repository.
Parameters:
Name Type Description eventArgs
bo.shared.DataPortalEventArgs Data portal event arguments.
oldObject
EditableRootCollection The instance of the collection before the data portal action.
-
preRemove
-
The event arises before the business object collection will be removed from the repository.
Parameters:
Name Type Description eventArgs
bo.shared.DataPortalEventArgs Data portal event arguments.
oldObject
EditableRootCollection The instance of the collection before the data portal action.
-
preSave
-
The event arises before the business object collection will be saved in the repository. The event is followed by a preInsert, preUpdate or preRemove event depending on the state of the business object collection.
Parameters:
Name Type Description eventArgs
bo.shared.DataPortalEventArgs Data portal event arguments.
oldObject
EditableRootCollection The instance of the collection before the data portal action.
-
preUpdate
-
The event arises before the business object collection will be updated in the repository.
Parameters:
Name Type Description eventArgs
bo.shared.DataPortalEventArgs Data portal event arguments.
oldObject
EditableRootCollection The instance of the collection before the data portal action.