APIs

Show:

"Small" overrides and extras added to the Backbone.Collection class to better work with the system. You can also add anything extra you know about the code that is not explained in backbones documentation.

See the following for parent class information: http://backbonejs.org/#Collection

Creating a new collection

var collection = new Collection([], {
    model: PatientModel,
    url: window.BAREBONES + 'V1/patients'
});

Chaining of collection parameters

collection.setOrderBy('pat_fname')
    .setSortBy('DESC')
    .setLimit(10);

Fetching and using data

var promise = collection.fetch();
promise.then(function(){
    collection.each(function(model){
        //some logic
    });
});

Fetching without promises

collection.fetch({success: function(){}});

Although filtering support raw sql and attribute|comparator|value approach, the recommended standard now is key value pairs. This approach prevents sql injection and requires that filters be predefined in the backend API.

collection.setFilter('pat_phy_id', [3, 25, 6]);
collection.setFilter('pat_dob_from', '19851128');

Sometimes you'll need to fetch an entire collection that doesn't change often (rendering providers). Use the fetchAll function in this case. It will only fetch on the first request but still call success with the exist in data for subsequent calls.

Constructor

awa.mvc.Collection

(
  • [models]
  • [options.model]
  • [options.filters]
  • [options.params]
  • [options.limit]
  • [options.offset]
  • [options.order_by]
  • [options.sort_by]
  • [options.columns]
  • [options.total_rows]
  • [options.postGet]
)

Parameters:

  • [models] Array optional

    initial set of models, usually you can just pass an empty array

  • [options.model] Constructor optional

    Model class to use for collection

  • [options.filters] Array | Object optional

    Set of initial filters

  • [options.params] Array | Object optional

    Set of initial parameters

  • [options.limit] String | Integer optional

    Initial collection limit

  • [options.offset] String | Integer optional

    Initial collection offset

  • [options.order_by] String optional

    Initial collection ordering

  • [options.sort_by] String optional

    Initial collection sort

  • [options.columns] Array optional

    array of strings dictating return columns

  • [options.total_rows] Boolean optional

    dictate if you want to receive total rows. defaults to true in most cases

  • [options.postGet] String optional

    In the case that you need to use post instead of get to grab a collection, provider the sub action i.e. barebones/V1/patients is the regular path for get, barebones/V1/patients/filtered can be your post version. Only provide the word "filtered"

Methods

_logLastUpdatedOnSync

() Undefined

When sync is triggered, this method updates the lastUpdated value

Returns:

Undefined:

undefined

addFilter

(
  • attr
  • comp
  • val
)
awa.mvc.Collection deprecated chainable

Defined in /var/www/azaleahealth.com/branches/docs/source_repo/awa/resources/apps/js/awa/mvc/Collection.js:674

Deprecated: Using this means you are using string based filter and that is bad Remove when all string based filters are gone Adds one filter to the array of filters that is sent to the server on fetch.

Parameters:

  • attr String

    filter to add

  • comp String

    comparator to use (> < = != IN BETWEEN)

  • val String | Array

    filter to add

Returns:

addParams

(
  • params
)
awa.mvc.Collection chainable

Adds hashmap params to current params

Parameters:

  • params Object

    Full parameter set

Returns:

addReturnColumn

(
  • col
)
awa.mvc.Collection chainable

Adds a column to the collection option for the return that is sent to the server on fetch.

Parameters:

  • col String

    attribute to return

Returns:

canDoLocalQuery

() Boolean

Returns:

Boolean:

Can locally query

displayMethod

(
  • val
  • id
  • source
)
String

Parameters:

Returns:

String:

brief string summary of the collection as a whole

fetchAll

(
  • [options]
)
Promise

Gets all of the collection records. Returns a promise that is already resolved if cache is available. Cleared with reset.

Parameters:

  • [options] Object optional

    xhr options. Use the other methods instead

Returns:

Promise:

promise for when fetch is complete

fetchTotalRows

(
  • get_total_rows
)
awa.mvc.Collection chainable

Instructs server to calculate total row count

Parameters:

  • get_total_rows Boolean

    Flag

Returns:

filterReject

(
  • predicate
)
awa.mvc.Collection

A version of reject to return a modified version of this collection.

Parameters:

  • predicate Function

    A function that returns true when an item should be removed from the collection. It takes one argument, the model it should test against. Defaults to _.noop

Returns:

awa.mvc.Collection:

This collection without models rejected by predicate.

findWhere

(
  • [list]
  • props
)
awa.mvc.Model

Overridden version of findWhere to be less typesafe. ID changes from string or int based on if model is new which causes several issues when doing a search

Parameters:

  • [list] Array optional

    not used

  • props Object

    Properties to match against

Returns:

awa.mvc.Model:

returns matches model

get

(
  • attr
)
Mixed

Get the current value of an attribute from the model Overwritten to create collections and sub models only when needed.

Parameters:

  • attr String

    supports dot notation to get properties of individual models

Returns:

Mixed:

model or attribute of sub model

getArgument

(
  • key
  • filter
)
String | Array | Object

Gets an argument based on the key

Parameters:

  • key String

    Argument key

  • filter String | Array | Object

    or array of filters

Returns:

String | Array | Object:

Argument value

getDisplay

(
  • attr
)
Mixed

Parameters:

  • attr String

    supports dot notation to get properties of individual models

Returns:

Mixed:

Like get, but this uses the displayMethod.

getDisplayMethod

(
  • attr
)
Function

Parameters:

  • attr String

    attribute of model

Returns:

Function:

returns the displayMethod for a given attribute

getFetchData

() Object

Get the entire data object {with the exception of the ahis session id} that is sent to the server.

Returns:

Object:

object fo data sent when fetching

getFilters

() Array | Object

Gets the array of filters that is sent to the server.

Returns:

Array | Object:

All filters

getFilters

(
  • key
)
Mixed

Gets the array of filters that is sent to the server.

Parameters:

  • key String

    Filter key

Returns:

Mixed:

filter value

getLimit

() Integer

Returns:

Integer:

collection option for the maximum returned results that is sent to the server on fetch.

getName

(
  • attr
)
String

Gets the name of an attribute. This can be set by and attribute's attributeProp name. returns the attribute if not set.

Parameters:

  • attr String

    attribute of model

Returns:

String:

attribute Name of attribute

getOffset

() Integer

Returns:

Integer:

collection option for the offset that is sent to the server on fetch.

getOrderBy

() String

Returns:

String:

collection option for ordering that is sent to the server on fetch.

getParam

(
  • key
)
Mixed

Gets a parameter that are sent to the server by key.

Parameters:

  • key String

    Paramter key

Returns:

Mixed:

selected param

getParams

() Object

Gets all of the parameters that are sent to the server.

Returns:

Object:

all params

getQuery

() String | Object

Gets the collection option for searching that is sent to the server on fetch.

Returns:

String | Object:

Query value

getReturnColumns

() Array

Returns:

Array:

collection option for the return that is sent to the server on fetch.

getSortBy

() String

Returns:

String:

collection option for sorting ascending or descending that is sent to the server on fetch. Can be ASC or DESC

hasAPIPagination

() Boolean

Api will return meta data to indicate pagination for grids/lists. The collection will gain properties such as currentPage, nextPage, etc.

Returns:

Boolean:

True if api supports pagination

idAttribute

() String

Returns:

String:

Specifies the key/id of the models in this collection.

isFetchingTotalRows

() Boolean

Returns:

Boolean:

Indicates collection will request total rows on next fetch

load

(
  • id
  • [options]
)
Promise

Get the entire data object {with the exception of the ahis session id} that is sent to the server.

Parameters:

  • id Integer | String

    id of single model

  • [options] Object optional

    set of options

Returns:

Promise:

promise when fetch is complete

makeCollectionFromPrimitiveArray

(
  • arr
)
awa.mvc.Collection static

Parameters:

  • arr Array

    Array of primitive data types (string, number, boolean, etc)

Returns:

awa.mvc.Collection:

Collection with models that have the primitive as id and name

onQuery

(
  • query
)
Array

Override this method and return a list of models if you want to implement local querying

Parameters:

  • query String

    string to search

Returns:

Array:

query string to search

save

(
  • models
  • options
)
Promise

Saves several models at a time. Not always supported by backend

Parameters:

  • models Array

    just pass undefined for now

  • options Object

    configuration object with various properties

Returns:

Promise:

sometimes its a promise

setArgument

(
  • key
  • value
)
awa.mvc.Collection chainable

Sets one collection argument. params, options, and filters will be ignored this is the preferred way of handling "filters"

Parameters:

  • key String

    or array of filters

  • value String | Array | Object

    or array of filters

Returns:

setArguments

(
  • obj
)
awa.mvc.Collection chainable

Sets the collection arguments. This must be an object and is the preferred way of handling "filters" The object properties options, filters, and params will overwritten by their pre-existing values.

Parameters:

  • obj Object

    Argument object

Returns:

setFilter

(
  • attr
  • val
  • comp
)
awa.mvc.Collection chainable

Adds one filter to the array of filters that is sent to the server on fetch.

Used to accept (attr, comp, val) this has been changed for new filtering for hermes and in consideration of deprecating the old addFilter method

Parameters:

  • attr String

    attribute to filter

  • val String | Array

    value(s) to filter

  • comp String

    comparator to use "=",">",">=","<","<=","!=","~" (Only works with hermes)

Returns:

setFilters

(
  • filters
)
awa.mvc.Collection chainable

Sets the collection option for all filtering strings that is sent to the server on fetch.

Parameters:

  • filters String | Array | Object

    object or array of filters

Returns:

setLimit

(
  • limit
)
awa.mvc.Collection chainable

Sets the collection option for the maximum returned results that is sent to the server on fetch.

Parameters:

  • limit String | Integer

    amount to limit by

Returns:

setOffset

(
  • offset
)
awa.mvc.Collection chainable

Sets the collection option for the offset that is sent to the server on fetch.

Parameters:

  • offset String | Integer

    number to start at in a list

Returns:

setOrderBy

(
  • order_by
)
awa.mvc.Collection chainable

Sets the collection option for ordering that is sent to the server on fetch.

Parameters:

  • order_by String

    attribute to order by

Returns:

setOrderBy

(
  • order_by
  • sort_by
)
awa.mvc.Collection chainable

Sets the collection option for ordering that is sent to the server on fetch.

Parameters:

  • order_by String

    attribute to order by

  • sort_by String

    ASC or DESC

Returns:

setParam

(
  • k
  • v
)
awa.mvc.Collection chainable

Sets the parameter value that is sent to the server

Parameters:

  • k String

    Paramter key

  • v String

    Paramter value

Returns:

setParams

(
  • params
)
awa.mvc.Collection chainable

Sets all of the parameters that are sent to the server

Parameters:

  • params Object

    Full parameter set

Returns:

setQuery

(
  • query
)
awa.mvc.Collection chainable

Sets the collection option for searching that is sent to the server on fetch. What this is matched against is api/controller dependent.

Parameters:

  • query String

    string to search

Returns:

setReturnColumns

(
  • cols
)
awa.mvc.Collection chainable

Sets the collection option for the return that is sent to the server on fetch.

Parameters:

  • cols Array

    Array of attributes

Returns:

setSortBy

(
  • sort_by
)
awa.mvc.Collection chainable

Sets the collection option for sorting ascending or descending that is sent to the server on fetch. Can be ASC or DESC

Parameters:

  • sort_by String

    attribute to sort by

Returns:

sync

(
  • method
  • collection
  • options
)
Promise

Overridden from Backbone.Collection.fetch to handle not so restful backend.

Parameters:

  • method String

    read update or create

  • collection awa.mvc.Collection

    collection this is called on

  • options Object

    xhr options

Returns:

Promise:

sometimes its a promise

toDisplayJSON

() Array

Uses the displayRules/Methods that are set in either the displayRules property or the attributeProps to generate a javascript object (w/o getters and setters) that represents the model's data in a displayable format.

Returns:

Array:

array of objects

toJSON

(
  • options
)
Array

Override of collections toJSON to handle empty indexes

Parameters:

  • options Object

    configuration object with various properties

Returns:

Array:

array of objects

where

(
  • props
)
Array

Overridden version of where to be less typesafe and to handle undefined. ID changes from string or int based on if model is new which causes several issues when doing a search

Parameters:

  • props Object

    configuration object with various properties to match on

Returns:

Array:

returns array of matched models

Events

filters

Gets an argument based on the key

Event Payload:

  • source awa.mvc.Collection

    This collection

  • args Object

    object of arguments

    • filters Object

      Object of current filters