Home Reference Source Repository
public class | source

BaseCollection

Extends:

backbone~Backbone.Collection → BaseCollection

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.

Member Summary

Public Members
public get

Returns route.

Method Summary

Public Methods
public

create(options: object): Backbone.Model

Override of create.

public

fetch(options: object)

Override of fetch to allow for generic handling.

public

fetchFilter(filters: array, options: object)

Requests a filtered fetch.

public

fetchPage(page: integer, options: object)

Requests a page to be fetched.

public

fetchSort(ascending: boolean, field: string, options: object)

Requests a sorted fetch.

public

getEnumerations(): array

Returns enumerations of this Collection.

public

Returns pagination object for this Collection.

public

parse(response: object): object

Parse results.

public

Parses ID out of URL.

public

Syncs the Collection while preserving the last used fetch options.data.

public

url(): string

Returns the URL associated with this Collection.

Public Constructors

public constructor(options: object) source

Constructor.

Params:

NameTypeAttributeDescription
options object

initialization parameters for Backbone.Collection

Public Members

public get route: string: * source

Returns route.

Return:

string

route

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:

NameTypeAttributeDescription
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:

NameTypeAttributeDescription
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:

NameTypeAttributeDescription
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:

NameTypeAttributeDescription
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.

Params:

NameTypeAttributeDescription
ascending boolean

results will return in ascending order iff true

field string

name of field to sort by

options object

Backbone.Collection.fetch options object

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.

Return:

object

pagination object

TODO:

  • point to pagination info on Rodan server

public parse(response: object): object source

Parse results.

Params:

NameTypeAttributeDescription
response object

JSON object

Return:

object

JSON object

public parseIdFromUrl(url: string): string source

Parses ID out of URL.

Params:

NameTypeAttributeDescription
url string

URL

Return:

string

string representing UUID of Collection

TODO:

  • this should be moved to a utility class

public syncCollection() source

Syncs the Collection while preserving the last used fetch options.data.

public url(): string source

Returns the URL associated with this Collection.

Return:

string

URL associated with this Collection