| 1 | define([ |
| 2 | "dojo/_base/declare", |
| 3 | "dojo/_base/lang", |
| 4 | "./getPlainValue", |
| 5 | "./EditStoreRefController", |
| 6 | "./ListController" |
| 7 | ], function(declare, lang, getPlainValue, EditStoreRefController, ListController){ |
| 8 | return declare("dojox.mvc.EditStoreRefListController", [EditStoreRefController, ListController], { |
| 9 | // summary: |
| 10 | // A child class of dojox/mvc/EditStoreRefController, mixed with ListController. |
| 11 | // description: |
| 12 | // It supports Lists in addition to what dojox/mvc/EditStoreRefController does. |
| 13 | // 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. |
| 14 | // example: |
| 15 | // The check box refers to "value" property in the controller (with "ctrl" ID). |
| 16 | // The controller provides the "value" property, from the data coming from data store ("store" property in the controller), using the first one in array. |
| 17 | // Two seconds later, the check box changes from unchecked to checked. |
| 18 | // The change is committed to the data store, which is reflected to dojo/store/Observable callback. |
| 19 | // | <html> |
| 20 | // | <head> |
| 21 | // | <script src="/path/to/dojo-toolkit/dojo/dojo.js" type="text/javascript" data-dojo-config="parseOnLoad: 0"></script> |
| 22 | // | <script type="text/javascript"> |
| 23 | // | require([ |
| 24 | // | "dojo/dom", "dojo/parser", "dojo/store/Observable", "dojo/store/Memory", "dijit/registry", |
| 25 | // | "dijit/form/CheckBox", "dojox/mvc/EditStoreRefListController", "dojox/mvc/ListController", "dojo/domReady!" |
| 26 | // | ], function(ddom, parser, Observable, Memory, registry){ |
| 27 | // | store = Observable(new Memory({data: [{id: "Foo", value: false}]})); |
| 28 | // | parser.parse(); |
| 29 | // | registry.byId("ctrl").queryStore().observe(function(object, previousIndex, newIndex){ |
| 30 | // | alert("ID: " + object.id + ", value: " + object.value); |
| 31 | // | }, true); |
| 32 | // | var count = 0; |
| 33 | // | var h = setInterval(function(){ |
| 34 | // | ddom.byId("check").click(); |
| 35 | // | registry.byId("ctrl").commit(); |
| 36 | // | if(++count >= 2){ clearInterval(h); } |
| 37 | // | }, 2000); |
| 38 | // | }); |
| 39 | // | </script> |
| 40 | // | </head> |
| 41 | // | <body> |
| 42 | // | <script type="dojo/require">at: "dojox/mvc/at"</script> |
| 43 | // | <span id="ctrl" data-dojo-type="dojox/mvc/EditStoreRefListController" |
| 44 | // | data-dojo-props="store: store, cursorIndex: 0"></span> |
| 45 | // | <input id="check" type="checkbox" data-dojo-type="dijit/form/CheckBox" data-dojo-props="checked: at('widget:ctrl', 'value')"> |
| 46 | // | </body> |
| 47 | // | </html> |
| 48 | |
| 49 | commitCurrent: function(){ |
| 50 | // summary: |
| 51 | // Send the change back to the data source for the current index. |
| 52 | |
| 53 | var id = this.cursor[this.idProperty]; |
| 54 | for(var i = 0; i < this.originalModel.length; i++){ |
| 55 | if(this.originalModel[i][this.idProperty] == id){ |
| 56 | this.originalModel.set(i, this.cloneModel(this.cursor)); |
| 57 | break; |
| 58 | } |
| 59 | } |
| 60 | this.store.put(this.cursor); |
| 61 | } |
| 62 | |
| 63 | }); |
| 64 | }); |