Class Index | File Index

## Classes

- _global_
- M
- M.ActionSheetDialogView
- M.AlertDialogView
- M.Application
- M.Base64
- M.ButtonGroupView
- M.ButtonView
- M.ConfirmDialogView
- M.ContainerView
- M.Controller
- M.Cypher
- M.DataProvider
- M.Date
- M.DateValidator
- M.EmailValidator
- M.Environment
- M.EventDispatcher
- M.FormView
- M.GridView
- M.I18N
- M.ImageView
- M.LabelView
- M.ListItemView
- M.ListView
- M.LoaderView
- M.LocalStorageProvider
- M.Logger
- M.Math
- M.Model
- M.ModelAttribute
- M.ModelRegistry
- M.NotMinusValidator
- M.NumberValidator
- M.Object
- M.Observable
- M.PageView
- M.PhoneValidator
- M.PresenceValidator
- M.RecordManager
- M.RemoteStorageProvider
- M.Request
- M.ScrollView
- M.SearchBarView
- M.SelectionListItemView
- M.SelectionListView
- M.SHA256
- M.TabBarItemView
- M.TabBarView
- M.TextFieldView
- M.ToggleView
- M.ToolbarView
- M.UrlValidator
- M.Validator
- M.View
- M.ViewManager
- M.WebSqlProvider

# Class M.Model

Extends M.Object.
M.Model is the prototype for every model and for every model record (a model itself is the blueprint for a model record). Models hold the business data of an application respectively the application's state. It's usually the part of an application that is persisted to storage. M.Model acts as the gatekeeper to storage. It uses data provider for persistence and validators to validate its records.
Defined in: model.js.

Class Summary
Constructor Attributes | Constructor Name and Description
--- | ---
| M.Model()

Field Summary
Field Attributes | Field Name and Description
--- | ---
| dataProvider The model's data provider.
| id Unique identifier for the model record.
| name The name of the model.
| record The model's record defines the properties that are semantically bound to this model: e.g.
| recordManager Manages records of this model
| records
| state A constant defining the model's state.
| type The type of this object.
| usesValidation determines whether model shall be validated before saving to storage or not.

Method Summary
Method Attributes | Method Name and Description
--- | ---
| attr(type, opts) Returns a M.ModelAttribute object to map an attribute in our record.
| create(obj, dp) Create defines a new model blueprint.
| createRecord(obj) Creates a new record of the model, means an instance of the model based on the blueprint.
| del() Delete a record in storage.
| find(obj) Calls the corresponding find() of the data provider to fetch data based on the passed query or key.
| get(propName) Get attribute propName from model
| save(obj) Create or update a record in storage if it is valid (first check this).
| set(propName, val) Set attribute propName of model with value val
| validate() Validates the model, means calling validate for each property.

Methods borrowed from class M.Object:
  bindToCaller, destroy, extend, include

Class Detail
M.Model()
Field Detail
{Object} dataProvider
The model's data provider. Needs a refactoring, also in connection with storageEngine.

{Number} id
Unique identifier for the model record. Note: Unique doesn't mean that this id is a global unique ID, it is just unique for records of this type of model.

{String} name
The name of the model.

{Object record} record
The model's record defines the properties that are semantically bound to this model: e.g. a person's record is in simplest case: firstname, lastname, age.

{Object} recordManager
Manages records of this model

records

{String} state
A constant defining the model's state. Important e.g. for syncing storage

{String} type
The type of this object.

{Boolean} usesValidation
determines whether model shall be validated before saving to storage or not.
Method Detail
{Object} attr(type, opts)
Returns a M.ModelAttribute object to map an attribute in our record.

Parameters:
{String} type
  type of the attribute
{Object} opts
  options for the attribute, like required flag and validators array

Returns:
  {Object} An M.ModelAttribute object configured with the type and options passed to the function.

{Object} create(obj, dp)
Create defines a new model blueprint. It is passed an object with the model's attributes and the model's business logic and after it the type of data provider to use.

Parameters:
{Object} obj
  An object defining the model's
{Object} dp
  The data provider to use, e. g. M.LocalStorageProvider

Returns:
  {Object} The model blueprint: acts as blueprint to all records created with @link M.Model#createRecord

{Object} createRecord(obj)
Creates a new record of the model, means an instance of the model based on the blueprint. You pass the object's specific attributes to it as an object.

Parameters:
{Object} obj
  The specific attributes as an object, e.g. {firstname: 'peter', lastname ='fox'}

Returns:
  {Object} The model record with the passed properties set. State depends on newly creation or fetch from storage: if from storage then state is M.STATE_NEW or 'state_new', if fetched from database then it is M.STATE_VALID or 'state_valid'

{Boolean} del()
Delete a record in storage.

Returns:
  {Boolean} Indicating whether deletion was successful or not (only with synchronous data providers, e.g. LocalStorage). When asynchronous data providers are used, e.g. WebSQL provider the real result comes asynchronous and here just the result of the del() function call of the @link M.WebSqlProvider is used.

{Boolean|Object} find(obj)
Calls the corresponding find() of the data provider to fetch data based on the passed query or key.

Parameters:
{Object} obj
  The param object with query or key and callbacks.

Returns:
  {Boolean|Object} Depends on data provider used. When WebSQL used, a boolean is returned, the find result is returned asynchronously, because the call itself is asynchronous. If LocalStorage is used, the result of the query is returned.

{Object|String} get(propName)
Get attribute propName from model

Parameters:
{String} propName
  the name of the property whose value shall be returned

Returns:
  {Object|String} value of property

{Boolean} save(obj)
Create or update a record in storage if it is valid (first check this).

Parameters:
{Object} obj
  The param object with query and callbacks.

Returns:
  {Boolean} The result of the data provider function call. Is a boolean. With LocalStorage used, it indicates if the save operation was successful. When WebSQL is used, the result of the save operation returns asynchronously. The result then is just the standard result returned by the web sql provider's save method which does not necessarily indicate whether the operation was successful, because the operation is asynchronous, means the operation's end is not predictable.

set(propName, val)
Set attribute propName of model with value val

Parameters:
{String} propName
  the name of the property whose value shall be set
{String|Object} val
  the new value

{Boolean} validate()
Validates the model, means calling validate for each property.

Returns:
  {Boolean} Indicating whether this record is valid (YES|true) or not (NO|false).

Documentation generated by JsDoc Toolkit 2.4.0 on Wed Dec 08 2010 15:07:32 GMT+0100 (MEZ)