BaseCollection
Extends:
Direct Subclass:
Subclass of Backbone.Collection.
Some functionality of Backbone.Collection is overridden to facilitate server-based pagination, filtering, and sorting.
Constructor Summary
Public Constructor | ||
public |
constructor(options: object) Constructor. |
Method Summary
Public Methods | ||
public |
Override of create. |
|
public |
Override of fetch to allow for generic handling. |
|
public |
fetchFilter(filters: array, options: object) Requests a filtered fetch. |
|
public |
Requests a page to be fetched. |
|
public |
Requests a sorted fetch. |
|
public |
getEnumerations(): array Returns enumerations of this Collection. |
|
public |
Returns pagination object for this Collection. |
|
public |
Parse results. |
|
public |
parseIdFromUrl(url: string): string Parses ID out of URL. |
|
public |
Syncs the Collection while preserving the last used fetch options.data. |
|
public |
Returns the URL associated with this Collection. |
Public Constructors
Public Methods
public create(options: object): Backbone.Model source
Override of create.
This override exists because we do NOT want to add it to the collection by default (as there's a limit to what the server returns for collections, and we need to respect that). However, if the save worked, we do want to do a fetch to update the Collection. The fetch is called in the custom success handler for creation.
There's also the case if this Collection is local and not associated with a DB Collection.
Params:
Name | Type | Attribute | Description |
options | object | Backbone.Collection.create options object |
Return:
Backbone.Model | instance of Backbone.Model or subclass of Backbone.Model |
public fetch(options: object) source
Override of fetch to allow for generic handling.
Note that we save the data options. This is in case we do a create and have to reload/fetch the previous collection. We need to preserve the fetch parameters.
Params:
Name | Type | Attribute | Description |
options | object | Backbone.Collection.fetch options object |
public fetchFilter(filters: array, options: object) source
Requests a filtered fetch.
If no options.data is passed, the options.data from the last fetch are used.
Params:
Name | Type | Attribute | Description |
filters | array | array of objects; {name: string, value: primitive}; what filters can be used is defined in Rodan |
|
options | object | Backbone.Collection.fetch options object |
TODO:
- give more info on filters
public fetchPage(page: integer, options: object) source
Requests a page to be fetched.
If no options.data is passed, the options.data from the last fetch are used.
Params:
Name | Type | Attribute | Description |
page | integer | non-negative page number to retrieve from server |
|
options | object | Backbone.Collection.fetch options object |
public fetchSort(ascending: boolean, field: string, options: object) source
Requests a sorted fetch. This is not called "sort" because backbone already has a sort method for the Collection.
If no options.data is passed, the options.data from the last fetch are used.
public getEnumerations(): array source
Returns enumerations of this Collection. These are custom-defined in the subclasses.
Enumerations should be defined in subclasses as follows:
- [{field: string, label: string, values: [{value: primitive type, label: string}] (optional)}]
In the above:
- "field" is a property of the associated Model in the Collection
- "label" is a string that will appear in the table header
- "values" is optional; populate this array with explicit "value"/"label"s if desired, else BaseCollection will determine the values for enumeration based on the contents of the Collection
Return:
array | enumerations |
TODO:
- Rodan server should provide explicit enumerations
public getPagination(): object source
Returns pagination object for this Collection.
TODO:
- point to pagination info on Rodan server
public parse(response: object): object source
Parse results.
Params:
Name | Type | Attribute | Description |
response | object | JSON object |
public parseIdFromUrl(url: string): string source
Parses ID out of URL.
Params:
Name | Type | Attribute | Description |
url | string | URL |
TODO:
- this should be moved to a utility class
public syncCollection() source
Syncs the Collection while preserving the last used fetch options.data.