ModelView Class
ModelView
Definition: Model: The model manages the behavior and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). View: The view manages the display of information. Source: http://bit.ly/fQnaJI
ModelView creates the glue which binds the UI(View) with the Backend code functionality of the program. It keeps the View synchronized with the 'Model'.
ModelView creates a new object with data and settings. The data and settings are (JSON) object literals and merged and returned after all the internal setup is done. The ModelView contains all the information about the object, which keeps the View synchronized with the Model and vice versa.
Constructor
ModelView
-
$object -
$settings -
$methods
Parameters:
-
$objectObjectModel data
-
$settingsObjectConfig & view input events
-
$methodsObjectCustom user defined methods/functions
Item Index
Methods
- _SetDataboundDomVal
- _SetDataboundDomVal
- Add
- Add
- Add
- Add
- AddEvents
- AddEvents
- AddGetSet
- AddGetSet
- AddProperty
- AddProperty
- Clear
- Clear
- ClearAll
- ClearAll
- Delete
- Delete
- FillSelect
- FillSelect
- Find
- Find
- Get
- Get
- GetDatasrcId
- GetDatasrcId
- GetModelData
- GetModelData
- GetViewData
- GetViewData
- GetViewHtml
- GetViewHtml
- GetViewId
- GetViewId
- Has
- Has
- RemoveGetSet
- RemoveGetSet
- RemoveProperty
- RemoveProperty
- RunEvent
- RunEvent
- Save
- Save
- Set
- Set
- SetModelFromView
- SetModelFromView
- SetViewData
- SetViewData
- SetViewFromModel
- SetViewFromModel
- Start
- Start
- toArray
- toArray
- TriggerEvent
- TriggerEvent
- Update
- Update
Methods
_SetDataboundDomVal
-
datasrc -
name -
value
Update the databound elements inside or outside the View.
Parameters:
-
datasrcStringA viewId.
-
nameStringAn element's name.
-
valueStringA new value.
Returns:
The object (itself)
_SetDataboundDomVal
-
datasrc -
name -
value
Update the databound elements inside or outside the View.
Parameters:
-
datasrcStringA viewId.
-
nameStringAn element's name.
-
valueStringA new value.
Returns:
The object (itself)
Add
-
listName -
item
Add
NOTE: Must only be used if 'isMirror' is TRUE.
Adds an item to a list object in the model and updates the View.
Parameters:
-
listNameStringThe object's property name
-
itemStringThe new value to add to the property list
Returns:
The object (itself)
Add
-
listName -
item
Remove
NOTE: Must only be used if 'isMirror' is TRUE.
Removes an item from a list object in the model and updates the View.
Parameters:
-
listNameStringThe object's property name
-
itemStringThe new value to add to the property list
Returns:
The object (itself)
Add
-
listName -
item
Add
NOTE: Must only be used if 'isMirror' is TRUE.
Adds an item to a list object in the model and updates the View.
Parameters:
-
listNameStringThe object's property name
-
itemStringThe new value to add to the property list
Returns:
The object (itself)
Add
-
listName -
item
Remove
NOTE: Must only be used if 'isMirror' is TRUE.
Removes an item from a list object in the model and updates the View.
Parameters:
-
listNameStringThe object's property name
-
itemStringThe new value to add to the property list
Returns:
The object (itself)
AddEvents
()
Object
AddEvents
Add events to the object's input fields
Returns:
The object
AddEvents
()
Object
AddEvents
Add events to the object's input fields
Returns:
The object
AddGetSet
-
prop -
onUpdate
AddGetSet
Add getter and setter methods for a property
Getters and Setters in JavaScript/JScript (ECMAScript) are not an option as it is hard to make it work cross-browser/platform! There is a solution here, but only down to IE9: Source: http://javascriptweblog.wordpress.com/2010/11/15/extending-objects-with-javascript-getters/
If changes in the model properties should be reflected in the view then setter and getter methods will be attached using jQuery.
Note: Will only be used(exec.) if 'isMirror' is TRUE.
Works in IE 7+: http://jsfiddle.net/cTJZN/
Parameters:
-
propStringThe object's property name
-
onUpdateFunctioncallBack function will execute, whenever the get/set event handlers bound with .bind() method are triggered.
Returns:
The object (itself)
AddGetSet
-
prop -
onUpdate
AddGetSet
Add getter and setter methods for a property
Getters and Setters in JavaScript/JScript (ECMAScript) are not an option as it is hard to make it work cross-browser/platform! There is a solution here, but only down to IE9: Source: http://javascriptweblog.wordpress.com/2010/11/15/extending-objects-with-javascript-getters/
If changes in the model properties should be reflected in the view then setter and getter methods will be attached using jQuery.
Note: Will only be used(exec.) if 'isMirror' is TRUE.
Works in IE 7+: http://jsfiddle.net/cTJZN/
Parameters:
-
propStringThe object's property name
-
onUpdateFunctioncallBack function will execute, whenever the get/set event handlers bound with .bind() method are triggered.
Returns:
The object (itself)
AddProperty
-
prop
AddProperty
Add a property to the Model
Parameters:
-
propStringThe property name
Returns:
The object (itself)
AddProperty
-
prop
AddProperty
Add a property to the Model
Parameters:
-
propStringThe property name
Returns:
The object (itself)
Clear
()
Object
Clear
Clears a property's value in the Model and optionally in the View if 'isMirror' = true.
Returns:
The object (itself)
Clear
()
Object
Clear
Clears a property's value in the Model and optionally in the View if 'isMirror' = true.
Returns:
The object (itself)
ClearAll
()
Object
Clear All
Clears all the data in the Model and the View.
Returns:
The object (itself)
ClearAll
()
Object
Clear All
Clears all the data in the Model and the View.
Returns:
The object (itself)
Delete
-
par
Call the .Delete() method whenever you want to delete the object. Notice: This is intended behaviour, but the implementation of the method is up to the individual how and what is done when this method is called/executed.
Parameters:
-
parObjectProvide extra parameters if needed.
Returns:
The object (itself)
Delete
-
par
Call the .Delete() method whenever you want to delete the object. Notice: This is intended behaviour, but the implementation of the method is up to the individual how and what is done when this method is called/executed.
Parameters:
-
parObjectProvide extra parameters if needed.
Returns:
The object (itself)
FillSelect
-
prop -
text -
value
FillSelect
Fill select element with one or more option elements.
Parameters:
-
propArrayThe property name which holds an array of values
-
textStringThe text to be displayed in the option element
-
valueStringThe value of the option element
Returns:
The object (itself)
FillSelect
-
prop -
text -
value
FillSelect
Fill select element with one or more option elements.
Parameters:
-
propArrayThe property name which holds an array of values
-
textStringThe text to be displayed in the option element
-
valueStringThe value of the option element
Returns:
The object (itself)
Find
()
Array
Find
Find and return one or many element/s within the View using a (id or class) selector.
If the elemenet is not found an empty array is returned.
Returns:
An element from the View.
Find
()
Array
Find
Find and return one or many element/s within the View using a (id or class) selector.
If the elemenet is not found an empty array is returned.
Returns:
An element from the View.
Get
-
prop
Get
NOTE: Must only be used if 'isMirror' is TRUE.
Parameters:
-
propStringThe object's property name.
Returns:
value The value from the object's property.
Get
-
prop
Get
NOTE: Must only be used if 'isMirror' is TRUE.
Parameters:
-
propStringThe object's property name.
Returns:
value The value from the object's property.
GetDatasrcId
()
Number
GetDatasrcId
Return the (view) ID of the datasource.
Returns:
The (View) ID of the datasource.
GetDatasrcId
()
Number
GetDatasrcId
Return the (view) ID of the datasource.
Returns:
The (View) ID of the datasource.
GetModelData
-
withSettings
GetModelData
Return's a copy of the Model's data without it's functions. Useful when storing the data.
Note: As this object has all of it's functions/methods removed, then it's not possible to use the .toArray() (if needed for any reason) anymore. Instead use $.makeArray(theObject); which is what .toArray() uses.
Parameters:
-
withSettingsBooleanIf TRUE, then append the settings object.
Returns:
A copy of the Model's data (as JSON object literal).
GetModelData
-
withSettings
GetModelData
Return's a copy of the Model's data without it's functions. Useful when storing the data.
Note: As this object has all of it's functions/methods removed, then it's not possible to use the .toArray() (if needed for any reason) anymore. Instead use $.makeArray(theObject); which is what .toArray() uses.
Parameters:
-
withSettingsBooleanIf TRUE, then append the settings object.
Returns:
A copy of the Model's data (as JSON object literal).
GetViewData
()
Object
GetViewData
Return the View data as an JSON object literal.
Returns:
The View data as JSON object
GetViewData
()
Object
GetViewData
Return the View data as an JSON object literal.
Returns:
The View data as JSON object
GetViewHtml
()
Object
GetViewHtml
Returns the jQuery object.
Returns:
jQuery object.
GetViewHtml
()
Object
GetViewHtml
Returns the jQuery object.
Returns:
jQuery object.
GetViewId
()
String
GetViewId
Get the ID of the View
Returns:
The View ID
GetViewId
()
String
GetViewId
Get the ID of the View
Returns:
The View ID
Has
-
prop
Has
Checks if the Model has a given property (true) or not (false).
Parameters:
-
propStringThe object's property name
Returns:
TRUE if the property exists. Otherwise FALSE.
Has
-
prop
Has
Checks if the Model has a given property (true) or not (false).
Parameters:
-
propStringThe object's property name
Returns:
TRUE if the property exists. Otherwise FALSE.
RemoveGetSet
-
prop
RemoveGetSet
Remove getter and setter methods for a property
Parameters:
-
propStringThe object's property name
Returns:
The object (itself)
RemoveGetSet
-
prop
RemoveGetSet
Remove getter and setter methods for a property
Parameters:
-
propStringThe object's property name
Returns:
The object (itself)
RemoveProperty
-
prop
RemoveProperty
Remove a property from the Model
Parameters:
-
propStringThe property name
Returns:
The object (itself)
RemoveProperty
-
prop
RemoveProperty
Remove a property from the Model
Parameters:
-
propStringThe property name
Returns:
The object (itself)
RunEvent
-
event
RunEvent
Trigger an event if specified in the settings.
Parameters:
-
eventStringThe eventName to trigger/execute.
Returns:
The object (itself)
RunEvent
-
event
RunEvent
Trigger an event if specified in the settings.
Parameters:
-
eventStringThe eventName to trigger/execute.
Returns:
The object (itself)
Save
-
par
Call the .Save() method whenever you want to save the object. Notice: This is intended behaviour, but the implementation of the method is up to the individual how and what is done when this method is called/executed.
Parameters:
-
parObjectProvide extra parameters if needed.
Returns:
The object (itself)
Save
-
par
Call the .Save() method whenever you want to save the object. Notice: This is intended behaviour, but the implementation of the method is up to the individual how and what is done when this method is called/executed.
Parameters:
-
parObjectProvide extra parameters if needed.
Returns:
The object (itself)
Set
-
prop -
value
Set
NOTE: Must only be used if 'isMirror' is TRUE.
When you need to update a value in the Model and reflect in the View.
Parameters:
-
propStringThe object's property name
-
valueStringThe new value to set for the property
Returns:
The object (itself)
Set
-
prop -
value
Set
NOTE: Must only be used if 'isMirror' is TRUE.
When you need to update a value in the Model and reflect in the View.
Parameters:
-
propStringThe object's property name
-
valueStringThe new value to set for the property
Returns:
The object (itself)
SetModelFromView
-
updateDataboundValues
SetModelFromView
Update the model and databound elements.
This method is internally every time a 'change' and 'keyup' event occur in form elements. This is part of the concept to always update the Model, so it is synchronized with the View.
It is possible to override the call to this method for the 'keyup' event if it is implemented manually in the settings. Therefore it's important to know that if overriding this event, but still want 'live' updating of the Model to occur, then this method must be called from the custom implementation of the 'keyup' event!
Parameters:
-
updateDataboundValuesBooleanTRUE | FALSE - If undefined or true, databound elements inside and/or outside the the View will also get updated. If false, then they won't.
Returns:
The object (itself)
SetModelFromView
-
updateDataboundValues
SetModelFromView
Update the model and databound elements.
This method is internally every time a 'change' and 'keyup' event occur in form elements. This is part of the concept to always update the Model, so it is synchronized with the View.
It is possible to override the call to this method for the 'keyup' event if it is implemented manually in the settings. Therefore it's important to know that if overriding this event, but still want 'live' updating of the Model to occur, then this method must be called from the custom implementation of the 'keyup' event!
Parameters:
-
updateDataboundValuesBooleanTRUE | FALSE - If undefined or true, databound elements inside and/or outside the the View will also get updated. If false, then they won't.
Returns:
The object (itself)
SetViewData
()
Object
SetViewData
Set the View data from the Model (does not update databound elments)
Returns:
The object (itself)
SetViewData
()
Object
SetViewData
Set the View data from the Model (does not update databound elments)
Returns:
The object (itself)
SetViewFromModel
()
SetViewFromModel
Updates the elements in the View from the Model (including databound elements).
SetViewFromModel
()
SetViewFromModel
Updates the elements in the View from the Model (including databound elements).
Start
-
method -
par
Start
Execute a method in the controller.
Parameters:
-
methodStringThe methods name specified in the controller.
-
parObjectIf needed you can provide optional parameters.
Returns:
The object (itself)
Start
-
method -
par
Start
Execute a method in the controller.
Parameters:
-
methodStringThe methods name specified in the controller.
-
parObjectIf needed you can provide optional parameters.
Returns:
The object (itself)
toArray
()
Array
toArray
Convert the object to a real Array.
Returns:
The object converted into a real Array.
toArray
()
Array
toArray
Convert the object to a real Array.
Returns:
The object converted into a real Array.
TriggerEvent
-
prop -
evt
Trigger Event
Trigger an event on an input element inside the view
Parameters:
-
propStringProperty name
-
evtStringEvent type/name (e.g. 'keyup')
Returns:
The object (itself)
TriggerEvent
-
prop -
evt
Trigger Event
Trigger an event on an input element inside the view
Parameters:
-
propStringProperty name
-
evtStringEvent type/name (e.g. 'keyup')
Returns:
The object (itself)
Update
-
par
Call the .Update() method whenever you want to update the object. Notice: This is intended behaviour, but the implementation of the method is up to the individual how and what is done when this method is called/executed.
Parameters:
-
parObjectProvide extra parameters if needed.
Returns:
The object (itself)
Update
-
par
Call the .Update() method whenever you want to update the object. Notice: This is intended behaviour, but the implementation of the method is up to the individual how and what is done when this method is called/executed.
Parameters:
-
parObjectProvide extra parameters if needed.
Returns:
The object (itself)
Events
keyup ...
keyup event
It's important to know that when overriding this event, but still want 'live' updating of the Model to occur, then this method must be called from the custom implementation of the 'keyup' event!
keyup ...
keyup event
It's important to know that when overriding this event, but still want 'live' updating of the Model to occur, then this method must be called from the custom implementation of the 'keyup' event!
