Debian Codegraph @

dojox/mvc/tests/doh/WidgetList.js

raw symbols SCIP
1 define([
2 "doh",
3 "dojo/_base/array",
4 "dojo/_base/config",
5 "dojo/_base/declare",
6 "dijit/_WidgetBase",
7 "dojox/mvc/at",
8 "dijit/_TemplatedMixin",
9 "dijit/_WidgetsInTemplateMixin",
10 "dijit/_Container",
11 "dijit/form/TextBox",
12 "dojox/mvc/getStateful",
13 "dojox/mvc/WidgetList",
14 "dojo/text!dojox/mvc/tests/test_WidgetList_WidgetListInTemplate.html",
15 "dojo/text!dojox/mvc/tests/test_WidgetList_childTemplate.html",
16 "dojo/text!dojox/mvc/tests/test_WidgetList_childBindings.json"
17 ], function(doh, array, config, declare, _WidgetBase, at, _TemplatedMixin, _WidgetsInTemplateMixin, _Container, _TextBox, getStateful, WidgetList, template, childTemplate, childBindings){
18 var a = getStateful([
19 {
20 Serial: "A111",
21 First: "Anne",
22 Last: "Ackerman",
23 Location: "NY",
24 Office: "1S76",
25 Email: "[email protected]",
26 Tel: "123-764-8237",
27 Fax: "123-764-8228"
28 },
29 {
30 Serial: "B111",
31 First: "Ben",
32 Last: "Beckham",
33 Location: "NY",
34 Office: "5N47",
35 Email: "[email protected]",
36 Tel: "123-764-8599",
37 Fax: "123-764-8600"
38 },
39 {
40 Serial: "C111",
41 First: "Chad",
42 Last: "Chapman",
43 Location: "CA",
44 Office: "1278",
45 Email: "[email protected]",
46 Tel: "408-764-8237",
47 Fax: "408-764-8228"
48 }
49 ]), b = getStateful([
50 {
51 Serial: "D111",
52 First: "David",
53 Last: "Durham",
54 Location: "NJ",
55 Office: "C12",
56 Email: "[email protected]",
57 Tel: "514-764-8237",
58 Fax: "514-764-8228"
59 },
60 {
61 Serial: "E111",
62 First: "Emma",
63 Last: "Eklof",
64 Location: "NY",
65 Office: "4N76",
66 Email: "[email protected]",
67 Tel: "123-764-1234",
68 Fax: "123-764-4321"
69 }
70 ]);
71
72 var wl0 = new WidgetList({
73 children: getStateful(a),
74 childParams: {
75 startup: function(){
76 this.labelNode.set("value", at("rel:", "Serial"));
77 this.inputNode.set("value", at("rel:", "First"));
78 this.inherited("startup", arguments);
79 }
80 },
81 templateString: childTemplate
82 });
83 wl0.startup();
84
85 var wl1 = new WidgetList({
86 children: getStateful(a),
87 childBindings: eval("(" + childBindings + ")"),
88 templateString: childTemplate
89 });
90 wl1.startup();
91
92 var wl2 = new WidgetList({
93 partialRebuild: true,
94 children: getStateful(a),
95 childParams: {
96 startup: function(){
97 this.labelNode.set("value", at("rel:", "Serial"));
98 this.inputNode.set("value", at("rel:", "First"));
99 this.inherited("startup", arguments);
100 }
101 },
102 templateString: childTemplate
103 });
104 wl2.startup();
105
106 var wl3 = new WidgetList({
107 partialRebuild: true,
108 children: getStateful(a),
109 childBindings: eval("(" + childBindings + ")"),
110 templateString: childTemplate
111 });
112 wl3.startup();
113
114 doh.register("dojox.mvc.tests.doh.WidgetList", [
115 function programmaticBinding(){
116 var children = wl0.getChildren();
117 doh.is("A111", children[0].labelNode.value, "The label of index #0 should be: A111");
118 doh.is("Anne", children[0].inputNode.value, "The input of index #0 should be: Anne");
119 doh.is("B111", children[1].labelNode.value, "The label of index #1 should be: B111");
120 doh.is("Ben", children[1].inputNode.value, "The input of index #1 should be: Ben");
121 doh.is("C111", children[2].labelNode.value, "The label of index #2 should be: C111");
122 doh.is("Chad", children[2].inputNode.value, "The input of index #2 should be: Chad");
123
124 wl0.set("children", b);
125 children = wl0.getChildren();
126 doh.is("D111", children[0].labelNode.value, "The label of index #0 should be: D111");
127 doh.is("David", children[0].inputNode.value, "The input of index #0 should be: David");
128 doh.is("E111", children[1].labelNode.value, "The label of index #1 should be: E111");
129 doh.is("Emma", children[1].inputNode.value, "The input of index #1 should be: Emma");
130
131 },
132 function declarativeBinding(){
133 var children = wl1.getChildren();
134 doh.is("A111", children[0].labelNode.value, "The label of index #0 should be: A111");
135 doh.is("Anne", children[0].inputNode.value, "The input of index #0 should be: Anne");
136 doh.is("B111", children[1].labelNode.value, "The label of index #1 should be: B111");
137 doh.is("Ben", children[1].inputNode.value, "The input of index #1 should be: Ben");
138 doh.is("C111", children[2].labelNode.value, "The label of index #2 should be: C111");
139 doh.is("Chad", children[2].inputNode.value, "The input of index #2 should be: Chad");
140
141 wl1.set("children", b);
142 children = wl1.getChildren();
143 doh.is("D111", children[0].labelNode.value, "The label of index #0 should be: D111");
144 doh.is("David", children[0].inputNode.value, "The input of index #0 should be: David");
145 doh.is("E111", children[1].labelNode.value, "The label of index #1 should be: E111");
146 doh.is("Emma", children[1].inputNode.value, "The input of index #1 should be: Emma");
147 },
148 function removeAddElement(){
149 var c = getStateful(a.slice(0));
150 wl0.set("children", c);
151 wl1.set("children", c);
152 wl2.set("children", c);
153 wl3.set("children", c);
154
155 c.splice(1, 1);
156 var children = wl0.getChildren();
157 doh.is("C111", children[1].labelNode.value, "The label of index #1 should be: C111");
158 doh.is("Chad", children[1].inputNode.value, "The input of index #1 should be: Chad");
159 children = wl1.getChildren();
160 doh.is("C111", children[1].labelNode.value, "The label of index #1 should be: C111");
161 doh.is("Chad", children[1].inputNode.value, "The input of index #1 should be: Chad");
162 children = wl2.getChildren();
163 doh.is("C111", children[1].labelNode.value, "The label of index #1 should be: C111");
164 doh.is("Chad", children[1].inputNode.value, "The input of index #1 should be: Chad");
165 children = wl3.getChildren();
166 doh.is("C111", children[1].labelNode.value, "The label of index #1 should be: C111");
167 doh.is("Chad", children[1].inputNode.value, "The input of index #1 should be: Chad");
168
169 c.splice(1, 0, b[0], b[1]);
170 children = wl0.getChildren();
171 doh.is("D111", children[1].labelNode.value, "The label of index #1 should be: D111");
172 doh.is("David", children[1].inputNode.value, "The input of index #1 should be: David");
173 doh.is("E111", children[2].labelNode.value, "The label of index #2 should be: E111");
174 doh.is("Emma", children[2].inputNode.value, "The input of index #2 should be: Emma");
175 children = wl1.getChildren();
176 doh.is("D111", children[1].labelNode.value, "The label of index #1 should be: D111");
177 doh.is("David", children[1].inputNode.value, "The input of index #1 should be: David");
178 doh.is("E111", children[2].labelNode.value, "The label of index #2 should be: E111");
179 doh.is("Emma", children[2].inputNode.value, "The input of index #2 should be: Emma");
180 doh.is("C111", children[3].labelNode.value, "The label of index #3 should be: C111");
181 doh.is("Chad", children[3].inputNode.value, "The input of index #3 should be: Chad");
182 children = wl2.getChildren();
183 doh.is("D111", children[1].labelNode.value, "The label of index #1 should be: D111");
184 doh.is("David", children[1].inputNode.value, "The input of index #1 should be: David");
185 doh.is("E111", children[2].labelNode.value, "The label of index #2 should be: E111");
186 doh.is("Emma", children[2].inputNode.value, "The input of index #2 should be: Emma");
187 children = wl3.getChildren();
188 doh.is("D111", children[1].labelNode.value, "The label of index #1 should be: D111");
189 doh.is("David", children[1].inputNode.value, "The input of index #1 should be: David");
190 doh.is("E111", children[2].labelNode.value, "The label of index #2 should be: E111");
191 doh.is("Emma", children[2].inputNode.value, "The input of index #2 should be: Emma");
192 doh.is("C111", children[3].labelNode.value, "The label of index #3 should be: C111");
193 doh.is("Chad", children[3].inputNode.value, "The input of index #3 should be: Chad");
194 },
195 function replaceElement(){
196 wl0.set("children", a);
197 wl1.set("children", a);
198 a.set(1, b[1]);
199
200 var children = wl0.getChildren();
201 doh.is("E111", children[1].labelNode.value, "The label of index #1 should be: E111");
202 doh.is("Emma", children[1].inputNode.value, "The input of index #1 should be: Emma");
203 children = wl1.getChildren();
204 doh.is("E111", children[1].labelNode.value, "The label of index #1 should be: E111");
205 doh.is("Emma", children[1].inputNode.value, "The input of index #1 should be: Emma");
206 },
207 function wrongChildren(){
208 wl0.set("children", null);
209 var children = wl0.getChildren();
210 doh.is(0, children.length, "The widget list should be empty");
211 wl0.set("children", true);
212 children = wl0.getChildren();
213 doh.is(0, children.length, "The widget list should be empty");
214 wl0.set("children", 1);
215 children = wl0.getChildren();
216 doh.is(0, children.length, "The widget list should be empty");
217 wl0.set("children", "foo");
218 children = wl0.getChildren();
219 doh.is(0, children.length, "The widget list should be empty");
220 },
221 function objectInChildType(){
222 var data = [{idx: 0}, {idx: 1}, {idx: 2}, {idx: 3}];
223
224 declare("My.Widget", _WidgetBase, {
225 isMyWidget: true
226 });
227 declare("My.Mixin", null, {
228 isMyMixin: true
229 });
230
231 var w = new (declare([_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], {templateString: template}))({childData: data});
232 w.startup();
233
234 var simpleChildren = w.simpleWidgetList.getChildren(),
235 simpleChildrenWithRegularDijit = w.simpleWidgetListWithRegularDijit.getChildren(),
236 simpleChildrenWithRegularDijitInMixin = w.simpleWidgetListWithRegularDijitInMixin.getChildren();
237
238 doh.t(array.every(simpleChildren, function(child){ return child.isMyWidget && child.isMyMixin && !child.addChild && !child._setValueAttr; }), "simpleChildren should be created by My.Widget and My.Mixin");
239 doh.t(array.every(simpleChildrenWithRegularDijit, function(child){ return !child.isMyWidget && child.isMyMixin && !child.addChild && child._setValueAttr; }), "simpleChildrenWithRegularDijit should be created by dijit/form/TextBox and My.Mixin");
240 doh.t(array.every(simpleChildrenWithRegularDijitInMixin, function(child){ return child.isMyWidget && child.isMyMixin && child.addChild && !child._setValueAttr; }), "simpleChildrenWithRegularDijitInMixin should be created by My.Widget, My.Mixin and dijit/_Container");
241 }
242 ]);
243 });