Model
and Collection
classes extends an initial BaseModel
class, which is described here.
The url on which we have to sync the model or collection.
Called by the constructor, this method will take the options
and override if needed the url
and baseUrl
attributes.
Replace the parameters in URL path
with the given parameters
bag.
Called when the server response is received.
httpResponse
is the object from$http
serviceoptions
are the options given to thesync
method
On a model, it must return an object, that will be the attributes of that object and an array for collections.
Called before sending a request to the server, to create the request body.
attributes
are the object attributes
It return an object that will be sent as request body.
Fetch the object from API.
options
is optional and is an object that is given to theoptions
argument ofsync
method.
It return the sync
promise.
Send a POST request to the API, with the prepared request body (by prepare
method).
options
is optional and is an object that is given to theoptions
argument ofsync
method.
It return the sync
promise.
Send a DELETE
request without body.
It return the sync
promise.
Launch a request to the API.
method
is the HTTP method of the requestdata
is the request bodyoptions
is an object containing options for the given request. The following options are supported:method
: Override the HTTP methodurl
: Override the request URLdata
: Override the request body
This method return a deferred.
- The success callback will receive the current object as argument
- The error callback will receive an
httpResponse
object created by the$http
service.
This method is used internally to resolve the url
value which can be a string or a function.
These attributes and methods are in addition to the common attributes and methods.
The url that will be computed to the model URL. Arguments can be added in the URL with the {foo}
format: it will be replaced by the value of the foo
attribute if it exists.
The raw object of the instance attributes.
It takes two optional arguments:
attributes
(object): Initial attributes of modeloptions
: An array of options that will be computed by theinitialize
method
Return true if an attribute with the given key
exists, false otherwise.
Return the value of key
attribute, undefined
otherwise.
Set (or override) the value of the attribute for the given key.
These attributes and methods are in addition to the common attributes and methods.
Must be set: the class of the models contained in the collection.
An array of the models in the collection.
An array of the attributes of models in the collection. It's no more than an array of references to the attributes
object of each model.
It takes two optional arguments:
models
(array): Initial models of collectionoptions
: An array of options that will be computed by theinitialize
method
model
is a model instance or its attributes
If model
isn't the model instance, it is create and the options
are used as second argument of model constructor.
Return an instance of the model.
Add a model in the collection.
The options
(object, optional) argument is used to send options to _prepareModel
.
Remove the given model from the collection.
Remove the model at the given index.
Replace models in the collection by the given models.