Important

You are browsing the documentation for version 4.1 of OroCommerce, OroCRM and OroPlatform, which is no longer maintained. Read version 5.1 (the latest LTS version) of the Oro documentation to get up-to-date information.

See our Release Process documentation for more information on the currently supported and upcoming releases.

RoutingCollection

RoutingCollection is an abstraction of collection which uses Oro routing system.

It keeps itself in actual state when route or state changes.

Basic usage:

 1 var CommentCollection = RoutingCollection.extend({
 2     routeDefaults: {
 3         routeName: 'oro_api_comment_get_items',
 4         routeQueryParameterNames: ['page', 'limit']
 5     },
 6
 7     stateDefaults: {
 8         page: 1,
 9         limit: 10
10     },
11
12     // provide access to route
13     setPage: function (pageNo) {
14         this._route.set({page: pageNo});
15     }
16 });
17
18 var commentCollection = new CommentCollection([], {
19     routeParameters: {
20         // specify required parameters
21         relationId: 123,
22         relationClass: 'Some_Class'
23     }
24 });
25
26 // load first page (api/rest/latest/relation/Some_Class/123/comment?limit=10&page=1)
27 commentCollection.fetch();
28
29 // load second page (api/rest/latest/relation/Some_Class/123/comment?limit=10&page=2)
30 commentCollection.setPage(2)

Augment: BaseCollection

routingCollection._route : RouteModel

Route object which used to generate urls. Collection will reload whenever route is changed. Attributes will be available at the view as <%= route.page %>

Access to route attributes should be realized in descendants. (e.g. setPage() or setPerPage())

Kind: instance property of RoutingCollection Access: protected

routingCollection._state : BaseModel

State of the collection. Must contain both settings and server response parts such as totalItemsQuantity of items on server. Attributes will be available at the view as <%= state.totalItemsQuantity %>.

The stateChange event is fired when state is changed.

Override parse() function to add values from server response to the state

Kind: instance property of RoutingCollection Access: protected

routingCollection.routeDefaults : Object

Default route attributes

Kind: instance property of RoutingCollection

routingCollection.stateDefaults : Object

Default state

Kind: instance property of RoutingCollection

routingCollection.initialize()

Kind: instance method of RoutingCollection

routingCollection._createState(parameters)

Creates state object. Merges attributes from all stateDefaults objects/functions in class hierarchy.

Kind: instance method of RoutingCollection Access: protected

Param

Type

parameters

Object

routingCollection._createRoute(parameters)

Creates route. Merges attributes from all routeDefaults objects/functions in class hierarchy.

Kind: instance method of RoutingCollection Access: protected

Param

Type

parameters

Object

routingCollection._mergeAllPropertyVersions(attrName) ⇒ Object

Utility function. Extends Chaplin.utils.getAllPropertyVersions with merge and _.result() like call, if property is function

Kind: instance method of outingCollection Access: protected

Param

Type

Description

attrName

string

attribute to merge

routingCollection.getRouteParameters() ⇒ Object

Returns current route parameters

Kind: instance method of RoutingCollection

routingCollection.getState() ⇒ Object

Returns collection state

Kind: instance method of RoutingCollection

routingCollection.url()

Kind: instance method of RoutingCollection

routingCollection.sync()

Kind: instance method of RoutingCollection

routingCollection.parse()

Kind: instance method of RoutingCollection

routingCollection.checkUrlChange()

Fetches collection if url is changed. Callback for state and route changes.

Kind: instance method of RoutingCollection

routingCollection.serializeExtraData()

Kind: instance method of RoutingCollection

routingCollection._onErrorResponse()

Default error response handler function. It will show error messages for all HTTP error codes except 400.

Kind: instance method of RoutingCollection Access: protected

routingCollection._onAdd()

General callback for ‘add’ event

Kind: instance method of RoutingCollection Access: protected

routingCollection._onRemove()

General callback for ‘remove’ event

Kind: instance method of RoutingCollection Access: protected

routingCollection.dispose()

Kind: instance method of RoutingCollection