dojox/mvc/EditStoreRefController (version 1.10)

dojox/mvc/StoreRefController, dojox/mvc/EditModelRefController

Summary

A child class of dojox/mvc/StoreRefController, managing edits.

In addition to what dojox/mvc/StoreRefController does, the commit() method sends the data model as well as the removed entries in array to the data store. 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/EditStoreRefController reference documentation for more information.

Examples

Example 1

The check box refers to "value" property in the controller (with "ctrl" ID). The controller provides the "value" property, from the data coming from data store ("store" property in the controller), using the first one in array. Two seconds later, the check box changes from unchecked to checked. The change is committed to the data store, which is reflected to dojo/store/Observable callback.

<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/when", "dojo/store/Observable", "dojo/store/Memory", "dijit/registry", "dojo/domReady!"
            ], function(ddom, parser, when, Observable, Memory, registry){
                store = Observable(new Memory({data: [{id: "Foo", value: false}]}));
                when(parser.parse(), function(){
                    registry.byId("ctrl").queryStore().observe(function(object, previousIndex, newIndex){
                        alert("ID: " + object.id + ", value: " + object.value);
                    }, true);
                    var count = 0;
                    var h = setInterval(function(){
                        ddom.byId("check").click();
                        registry.byId("ctrl").commit();
                        if(++count >= 2){ clearInterval(h); }
                    }, 2000);
                });
            });
        </script>
    </head>
    <body>
        <script type="dojo/require">at: "dojox/mvc/at"</script>
        <span id="ctrl" data-dojo-type="dojox/mvc/EditStoreRefController" data-dojo-mixins="dojox/mvc/ListController"
         data-dojo-props="store: store, cursorIndex: 0"></span>
        <input id="check" type="checkbox" data-dojo-type="dijit/form/CheckBox" data-dojo-props="checked: at('widget:ctrl', 'value')">
    </body>
</html>

Property Summary

Method Summary

  • _changeAttrValue(name,value) Internal helper for directly changing an attribute value.
  • _dbpostscript(params,srcNodeRef) See if any parameters for this widget are dojox/mvc/at handles.
  • _get(name,names) Private function that does a get based off a hash of names
  • _getAttrNames(name) Helper function for get() and set().
  • _getExcludesAttr() Returns list of all properties that data binding is established with.
  • _getPropertiesAttr() Returns list of all properties in this widget, except "id".
  • _set(name,value) Set the value to the data model or to this object.
  • _setAtWatchHandle(name,value) Called if the value is a dojox/mvc/at handle.
  • _setBind(value) Sets data binding described in data-mvc-bindings.
  • _startAtWatchHandles(bindWith) Establish data bindings based on dojox/mvc/at handles.
  • _stopAtWatchHandles() Stops data binding synchronization handles as widget is destroyed.
  • addStore(object,options) Creates an object, throws an error if the object already exists.
  • cloneModel(value) Create a clone object of the data source.
  • commit() Send the change back to the data source.
  • destroy() Clean up model watch handle as this object is destroyed.
  • get(name) If getter function is there, use it.
  • getStore(id,options) Retrieves an object by its identity.
  • hasControllerProperty(name) Returns true if this controller itself owns the given property.
  • postscript(params,srcNodeRef) Sets _relTargetProp so that the property specified by _refModelProp is used for relative data binding.
  • putStore(object,options) Stores an object.
  • queryStore(query,options) Queries the store for objects.
  • removeStore(id,options) Deletes an object by its identity
  • reset() Change the model back to its original state.
  • set(name,value) If the value given is dojox/mvc/at handle, use it for data binding.
  • startup() Starts up data binding as this object starts up.
  • watch(name,callback) Watch a property in the data model or in this object.

Properties

_attrPairNames
Defined by: dojo/Stateful

Used across all instances a hash to cache attribute names and their getter and setter names.

_refEditModelProp

The property name for the data model, that is being edited.

_refInModelProp

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.

_refModelProp

The property name for the data model.

_refOriginalModelProp

The property name for the data model, that serves as the original data.

_refSourceModelProp

The property name for the data model, that serves as the data source.

_removals

The list of removed elements.

_resultsWatchHandle

The watch handle for model array elements.

data-mvc-bindings
dataBindAttr

The attribute name for data binding.

getPlainValueOptions

The options to get plain value from stateful object.

getStatefulOptions

The options to get stateful object from plain value.

holdModelUntilCommit

True not to send the change in model back to sourceModel until commit() is called.

model

The data model.

originalModel

The data model, that serves as the original data.

ownProps

List of property names owned by this controller, instead of the data model.

sourceModel
store

The Dojo Object Store in use.

Methods

_changeAttrValue(name,value)
Defined by dojo/Stateful

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.

Returns:function

Internal helper for directly changing an attribute value.

_dbpostscript(params,srcNodeRef)

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
_get(name,names)
Defined by dojo/Stateful

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

Returns:undefined
_getAttrNames(name)
Defined by dojo/Stateful

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:undefined | object
_getExcludesAttr()

Returns list of all properties that data binding is established with.

Returns:undefined | Array
_getPropertiesAttr()

Returns list of all properties in this widget, except "id".

Returns:String[] | undefined

The list of all properties in this widget, except "id"..

_set(name,value)

Set the value to the data model or to this object.

Parameter Type Description
name String

The property name.

value Anything

The property value.

Returns:function | undefined

Set the value to the data model or to this object.

_setAtWatchHandle(name,value)

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
_setBind(value)

Sets data binding described in data-mvc-bindings.

Parameter Type Description
value Object
_startAtWatchHandles(bindWith)

Establish data bindings based on dojox/mvc/at handles.

Parameter Type Description
bindWith dojo/Stateful

The dojo/Stateful to bind properties with.

_stopAtWatchHandles()

Stops data binding synchronization handles as widget is destroyed.

addStore(object,options)

Creates an object, throws an error if the object already exists.

Parameter Type Description
object Object

The object to store.

options dojo/store/api/Store.PutDirectives
Optional

Additional metadata for storing the data. Includes an "id" property if a specific id is to be used.

Returns:Number | undefined
cloneModel(value)

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.

Returns:undefined
commit()

Send the change back to the data source.

destroy()

Clean up model watch handle as this object is destroyed.

get(name)

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:undefined
getStore(id,options)

Retrieves an object by its identity.

Parameter Type Description
id Number

The identity to use to lookup the object.

options Object

The options for dojo/store/*/get().

Returns:Object | undefined

The object in the store that matches the given id.

hasControllerProperty(name)

Returns true if this controller itself owns the given property.

Parameter Type Description
name String

The property name.

Returns:boolean
postscript(params,srcNodeRef)

Sets _relTargetProp so that the property specified by _refModelProp is used for relative data binding.

Parameter Type Description
params Object
Optional
srcNodeRef DomNode | String
Optional
putStore(object,options)

Stores an object.

Parameter Type Description
object Object

The object to store.

options dojo/store/api/Store.PutDirectives
Optional

Additional metadata for storing the data. Includes an "id" property if a specific id is to be used.

Returns:Number | undefined
queryStore(query,options)

Queries the store for objects.

Parameter Type Description
query Object

The query to use for retrieving objects from the store.

options dojo/store/api/Store.QueryOptions
Optional

The optional arguments to apply to the resultset.

The results of the query, extended with iterative methods.

removeStore(id,options)

Deletes an object by its identity

Parameter Type Description
id Number

The identity to use to delete the object

options Object

The options for dojo/store/*.remove().

Returns:Boolean | undefined

Returns true if an object was removed, falsy (undefined) if no object matched the id.

reset()

Change the model back to its original state.

set(name,value)

If the value given is dojox/mvc/at handle, use it for data binding. Otherwise, if setter function is there, use it. Otherwise, set the value to the data model or to this object.

Parameter Type Description
name String

The property name.

value Anything

The property value.

Returns:function | undefined

If the value given is dojox/mvc/at handle, use it for data binding. Otherwise, if setter function is there, use it. Otherwise, set the value to the data model or to this object.

startup()

Starts up data binding as this object starts up.

watch(name,callback)

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.

Returns:undefined | object
Error in the documentation? Can’t find what you are looking for? Let us know!