A child class of dojox/mvc/ModelRefController. Keeps a copy (originalModel) of given data model (sourceModel) so that it can manage the data model of before/after the edit.
Has two modes:
For the 1st case, dojo/Stateful get()/set()/watch() interfaces will work with sourceModel. For the 2nd case, dojo/Stateful get()/set()/watch() interfaces will work with a copy of sourceModel, and sourceModel will be replaced with such copy when commit() is called.
NOTE - If this class is used with a widget by data-dojo-mixins, make sure putting the widget in data-dojo-type and putting this class to data-dojo-mixins.
See the dojox/mvc/Bind.EditModelRefController reference documentation for more information.
The check box refers to "value" property in the controller (with "ctrl" ID). The controller provides the "value" property on behalf of the model ("model" property in the controller, which comes from "sourceModel" property). Two seconds later, the check box changes from unchecked to checked, and the controller saves the state. Two seconds later then, the check box changes from checked to unchecked. Two seconds later then, the controller goes back to the last saved state, and the check box changes from unchecked to checked as the result.
<html> <head> <script src="/path/to/dojo-toolkit/dojo/dojo.js" type="text/javascript" data-dojo-config="parseOnLoad: 0"></script> <script type="text/javascript"> require([ "dojo/dom", "dojo/parser", "dojo/Stateful", "dijit/registry", "dijit/form/CheckBox", "dojox/mvc/EditModelRefController", "dojo/domReady!" ], function(ddom, parser, Stateful, registry){ model = new Stateful({value: false}); setTimeout(function(){ ddom.byId("check").click(); registry.byId("ctrl").commit(); setTimeout(function(){ ddom.byId("check").click(); setTimeout(function(){ registry.byId("ctrl").reset(); }, 2000); }, 2000); }, 2000); parser.parse(); }); </script> </head> <body> <script type="dojo/require">at: "dojox/mvc/at"</script> <span id="ctrl" data-dojo-type="dojox/mvc/EditModelRefController" data-dojo-props="sourceModel: model"></span> <input id="check" type="checkbox" data-dojo-type="dijit/form/CheckBox" data-dojo-props="checked: at('widget:ctrl', 'value')"> </body> </html>
The controller with "ctrlSource" ID specifies holding changes until commit() is called (by setting true to holdModelUntilCommit). As the change in the second check box is committed two seconds later from the change, the first check box is checked at then (when the change is committed).
<html> <head> <script src="/path/to/dojo-toolkit/dojo/dojo.js" type="text/javascript" data-dojo-config="parseOnLoad: 0"></script> <script type="text/javascript"> require([ "dojo/dom", "dojo/parser", "dojo/Stateful", "dijit/registry", "dijit/form/CheckBox", "dojox/mvc/ModelRefController", "dojox/mvc/EditModelRefController", "dojo/domReady!" ], function(ddom, parser, Stateful, registry){ model = new Stateful({value: false}); setTimeout(function(){ ddom.byId("checkEdit").click(); setTimeout(function(){ registry.byId("ctrlEdit").commit(); }, 2000); }, 2000); parser.parse(); }); </script> </head> <body> <script type="dojo/require">at: "dojox/mvc/at"</script> <span id="ctrlSource" data-dojo-type="dojox/mvc/ModelRefController" data-dojo-props="model: model"></span> <span id="ctrlEdit" data-dojo-type="dojox/mvc/EditModelRefController" data-dojo-props="sourceModel: at('widget:ctrlSource', 'model'), holdModelUntilCommit: true"></span> Source: <input id="checkSource" type="checkbox" data-dojo-type="dijit/form/CheckBox" data-dojo-props="checked: at('widget:ctrlSource', 'value')"> Edit: <input id="checkEdit" type="checkbox" data-dojo-type="dijit/form/CheckBox" data-dojo-props="checked: at('widget:ctrlEdit', 'value')"> </body> </html>
Used across all instances a hash to cache attribute names and their getter and setter names.
The property name for the data model, that is being edited.
The property name for the data model, used as the input. Used when this controller needs data model (as input) that is different from the data model this controller provides.
The property name for the data model, that serves as the original data.
The property name for the data model, that serves as the data source.
The options to get plain value from stateful object.
The options to get stateful object from plain value.
True not to send the change in model back to sourceModel until commit() is called.
The data model, that serves as the original data.
List of property names owned by this controller, instead of the data model.
Internal helper for directly changing an attribute value.
Directly change the value of an attribute on an object, bypassing any accessor setter. Also handles the calling of watch and emitting events. It is designed to be used by descendant class when there are two values of attributes that are linked, but calling .set() is not appropriate.
Parameter | Type | Description |
---|---|---|
name | String | The property to set. |
value | Mixed | The value to set in the property. |
Internal helper for directly changing an attribute value.
See if any parameters for this widget are dojox/mvc/at handles. If so, move them under this._refs to prevent widget implementations from referring them.
Parameter | Type | Description |
---|---|---|
params | Object |
Optional
|
srcNodeRef | DomNode | String |
Private function that does a get based off a hash of names
Parameter | Type | Description |
---|---|---|
name | undefined | |
names | undefined | Hash of names of custom attributes |
Helper function for get() and set(). Caches attribute name values so we don't do the string ops every time.
Parameter | Type | Description |
---|---|---|
name | undefined |
Returns list of all properties that data binding is established with.
Returns list of all properties in this widget, except "id".
The list of all properties in this widget, except "id"..
Set the value to the data model or to this object.
Parameter | Type | Description |
---|---|---|
name | String | The property name. |
value | Anything | The property value. |
Set the value to the data model or to this object.
Called if the value is a dojox/mvc/at handle. If this widget has started, start data binding with the new dojox/mvc/at handle. Otherwise, queue it up to this._refs so that _dbstartup() can pick it up.
Parameter | Type | Description |
---|---|---|
name | String | |
value | Anything |
Sets data binding described in data-mvc-bindings.
Parameter | Type | Description |
---|---|---|
value | Object |
Establish data bindings based on dojox/mvc/at handles.
Parameter | Type | Description |
---|---|---|
bindWith | dojo/Stateful | The dojo/Stateful to bind properties with. |
Stops data binding synchronization handles as widget is destroyed.
Create a clone object of the data source. Child classes of this controller can override it to achieve its specific needs.
Parameter | Type | Description |
---|---|---|
value | Anything | The data serving as the data source. |
If getter function is there, use it. Otherwise, get the data from data model of this object.
Parameter | Type | Description |
---|---|---|
name | String | The property name. |
Returns true if this controller itself owns the given property.
Parameter | Type | Description |
---|---|---|
name | String | The property name. |
Sets certain properties before setting models.
Parameter | Type | Description |
---|---|---|
params | Object |
Optional
|
srcNodeRef | DomNode | String |
Optional
|
Set a property to this.
Parameter | Type | Description |
---|---|---|
name | String | The property to set. |
value | Anything | The value to set in the property. |
Watch a property in the data model or in this object.
Parameter | Type | Description |
---|---|---|
name | String |
Optional The property name. |
callback | Function | The callback function. |