| 1 | <!DOCTYPE html> |
| 2 | <html> |
| 3 | <head> |
| 4 | <meta http-equiv="Content-type" content="text/html; charset=utf-8"> |
| 5 | <title>DOH Async Late Binding Template Input - Output Group example</title> |
| 6 | <style type="text/css"> |
| 7 | @import "../../../../dojo/resources/dojo.css"; |
| 8 | @import "../../../../dijit/tests/css/dijitTests.css"; |
| 9 | @import "../css/app-format.css"; |
| 10 | @import "../../../../dijit/themes/claro/claro.css"; |
| 11 | </style> |
| 12 | <script type="text/javascript" data-dojo-config="parseOnLoad:0,isDebug:1,async:1, mvc: {debugBindings: 1}" src="../../../../dojo/dojo.js"></script> |
| 13 | <script type="text/javascript"> |
| 14 | var model; |
| 15 | |
| 16 | require([ |
| 17 | 'dojo/_base/declare', |
| 18 | 'dojox/mvc/at', |
| 19 | 'dojox/mvc/EditModelRefController', |
| 20 | 'dojox/mvc/ModelRefController', |
| 21 | 'dojo/Stateful', |
| 22 | 'dojox/mvc/Group', |
| 23 | 'dijit/_TemplatedMixin', |
| 24 | 'dijit/_WidgetsInTemplateMixin', |
| 25 | 'dojox/mvc/StatefulModel', |
| 26 | 'dojo/ready', |
| 27 | 'dojo/parser', |
| 28 | 'dijit/form/TextBox' |
| 29 | ], function (declare, at, EditModelRefController, ModelRefController, Stateful, Group, _TemplatedMixin, |
| 30 | _WidgetsInTemplateMixin, StatefulModel, ready, parser, TextBox) { |
| 31 | |
| 32 | declare('test.TextBox', [TextBox], { |
| 33 | startup: function () { |
| 34 | console.log('starting...', this.id, this._refs.value.targetProp); |
| 35 | this.inherited(arguments); |
| 36 | console.log('started', this.id, this._refs.value.targetProp); |
| 37 | } |
| 38 | }); |
| 39 | var testGroup = declare('test.Group', [Group], { |
| 40 | startup: function () { |
| 41 | console.log('starting...', this.id); |
| 42 | this.inherited(arguments); |
| 43 | console.log('started', this.id); |
| 44 | } |
| 45 | }); |
| 46 | declare('test.Templated', [testGroup, _TemplatedMixin, _WidgetsInTemplateMixin], { |
| 47 | templateString: '<div><input data-dojo-type="test.TextBox" data-dojo-props="value: at(\'rel:\', \'fn\')"></div>' |
| 48 | }); |
| 49 | |
| 50 | // All 3 of these models work |
| 51 | //model = new EditModelRefController({sourceModel: new Stateful({fn: 'first', ln: 'last'})}); |
| 52 | //model = new Stateful({fn: 'first', ln: 'last'}); |
| 53 | model = new ModelRefController({model: new Stateful({fn: 'first', ln: 'last'})}); |
| 54 | |
| 55 | |
| 56 | require([ |
| 57 | 'doh/runner', 'dijit/dijit' |
| 58 | ], function(){ |
| 59 | require([ |
| 60 | 'dojo/domReady!' |
| 61 | ], function(){ |
| 62 | doh.register("parse", function() { |
| 63 | parser.parse(); |
| 64 | console.log('setting ref after parsing...'); |
| 65 | dijit.byId('late').set('target', model); |
| 66 | var prog = new test.Templated({ |
| 67 | target: model |
| 68 | }, 'prog'); |
| 69 | prog.startup(); |
| 70 | |
| 71 | }); |
| 72 | // should be able to verify all of the inputs |
| 73 | doh.register("check initial values", [{ |
| 74 | name : "initial", |
| 75 | runTest : function() { |
| 76 | doh.is("first", dijit.byId("parsedInput").get('value'),"parsedInput should be first"); |
| 77 | doh.is("first", dijit.byId("test_TextBox_0").get('value'),"test_TextBox_0 should be first"); |
| 78 | doh.is("first", dijit.byId("test_TextBox_1").get('value'),"test_TextBox_1 should be first"); |
| 79 | doh.is("first", dijit.byId("test_TextBox_2").get('value'),"test_TextBox_2 should be first"); |
| 80 | } |
| 81 | }]); |
| 82 | |
| 83 | doh.register("update first", [{ |
| 84 | name : "Update-first", |
| 85 | runTest : function() { |
| 86 | var first1; |
| 87 | first1 = dijit.byId("parsedInput"); |
| 88 | first1.set("value","first-update"); |
| 89 | if (first1) { |
| 90 | doh.is("first-update", dijit.byId("parsedInput").get('value'),"parsedInput should be first-update"); |
| 91 | doh.is("first-update", dijit.byId("test_TextBox_0").get('value'),"test_TextBox_0 should be first-update"); |
| 92 | doh.is("first-update", dijit.byId("test_TextBox_1").get('value'),"test_TextBox_1 should be first-update"); |
| 93 | doh.is("first-update", dijit.byId("test_TextBox_2").get('value'),"test_TextBox_2 should be first-update"); |
| 94 | } |
| 95 | } |
| 96 | }]); |
| 97 | doh.run(); |
| 98 | |
| 99 | }); |
| 100 | }); |
| 101 | }); |
| 102 | </script> |
| 103 | </head> |
| 104 | <body class="claro"> |
| 105 | <script type="dojo/require">at: "dojox/mvc/at"</script> |
| 106 | <h1>late binding</h1> |
| 107 | <p>no template</p> |
| 108 | <div id="parsedGroup" data-dojo-type="test.Group" data-dojo-props="target : model"> |
| 109 | <input data-dojo-type="test.TextBox" data-dojo-props="value: at('rel:', 'fn')" id="parsedInput"> |
| 110 | </div> |
| 111 | <p>Early parsed</p><div id="early" data-dojo-type="test.Templated" data-dojo-props="target : model"></div> |
| 112 | <p>Late parsed</p><div id="late" data-dojo-type="test.Templated"></div> |
| 113 | <p>programmatic</p><div id="prog"></div> |
| 114 | </body> |
| 115 | |
| 116 | </html> |