Class: module:RestModelBase

module:RestModelBase

new module:RestModelBase(skipLocalModel)

Constructor for REST models.
Parameters:
Name Type Description
skipLocalModel boolean Controls constructor call for LocalModel.

Methods

accept() → {string}

Returns the HTTP Accept header. Defaults to application/json.
Returns:
Value of Accept header.
Type
string

activate()

Activates this model. Model activation may cause a model to be refreshed or, if set to refresh periodically, its worker to be fired.

deactivate()

Deactivates this model by stopping the automatic refreshing feature.

del(sync)

Executes an HTTP DELETE operation and calls onDeleteDone when the operation is completed.
Parameters:
Name Type Description
sync boolean Set to true for synchronous DELETE.

get(sync)

Executes an HTTP GET operation calling onGetData to process the response. Once @onGetData has finished processing the data, it calls onGetDone to complete the request.
Parameters:
Name Type Description
sync boolean Set to true for synchronous GET.

getUrl() → {string}

Returns underlying URL for this model.
Returns:
URL for model.
Type
string

mergeData(localData, remoteData) → {string}

Parses JSON representation corresponding to local and remote data and then merges the result based on configured merge policy.
Parameters:
Name Type Description
localData string JSON representation of local data.
remoteData string JSON representation of remote data.
Returns:
Merged data as JSON string.
Type
string

onError(error)

Default error handler for this model. Outputs error message to console, if available.
Parameters:
Name Type Description
error string Error message.

onGetData()

Processes data returned from an HTTP GET operation. It handles collections, local store and deserialization. When completed, it calls onGetDone.

post(sync)

Executes an HTTP POST operation using a JSON-serialized version of this model as the HTTP entity. Once the operation is completed, it calls onPostDone.
Parameters:
Name Type Description
sync boolean Set to true for synchronous POST.

put(sync)

Executes an HTTP PUT operation using a JSON-serialized version of this model as the HTTP entity. Once the operation is completed, it calls onPutDone.
Parameters:
Name Type Description
sync boolean Set to true for synchronous PUT.

readHeaders() → {object}

Returns default HTTP read headers including Accept.
Returns:
Object with property for each HTTP header.
Type
object

readWriteHeaders() → {object}

Returns read and write headers.
Returns:
Object that includes all HTTP headers.
Type
object

resolve() → {boolean}

Returns true if a data merge is required. This can be overriden to change the merging condition.
Returns:
True if a data merge is required.
Type
boolean

setUrl(url)

Updates the underlying URL for this model.
Parameters:
Name Type Description
url string URL for model.

updateData() → {object}

Merges remote data with any local data from local storage.
Returns:
Merged data.
Type
object

writeHeaders() → {object}

Returns default HTTP write headers including X-Requested-By.
Returns:
Object with property for each HTTP header.
Type
object