Debian Codegraph @

dojox/mvc/tests/WidgetList_tests/test_nested_widgetLists-jsonRest-ins-del.html

raw symbols SCIP
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta http-equiv="Content-type" content="text/html; charset=utf-8">
5 <title>Nested WidgetList example</title>
6 <script src="../../../../dojo/dojo.js" type="text/javascript"
7 data-dojo-config="parseOnLoad: 0, isDebug: true, mvc: {debugBindings: true}"></script>
8 <style type="text/css">
9 @import "../css/app-format.css";
10 @import "../../../../dijit/themes/claro/claro.css";
11 </style>
12 <script type="text/javascript">
13 var ctrl;
14
15 require(["dojo/_base/declare", "dojo/when", "dojo/parser", "dojo/Stateful", "dojo/store/JsonRest", "dojo/_base/kernel",
16 "dijit/registry", "dojox/mvc/EditStoreRefListController", "dijit/form/Button", "dijit/form/TextBox", "dijit/form/ComboBox",
17 "dojox/mvc/Group", "dojox/mvc/Output", "dojox/mvc/Templated", "dojox/mvc/WidgetList", "dojo/domReady!"],
18 function(declare, when, parser, Stateful, JsonRest, kernel, registry, EditStoreRefListController) {
19
20 var inited, ctrlClass = declare([EditStoreRefListController], {
21 cursorIndex : 0,
22 group : "",
23 groupTyped : "",
24 _refModelProp : "model",
25
26 addEmpty : function() {
27 this.model.push(new Stateful({
28 id : Math.random(),
29 Group : this.groupTyped,
30 First : "",
31 Last : "",
32 Location : "",
33 Office : "",
34 Email : "",
35 Tel : [{
36 "name" : "Home",
37 "number" : ""
38 }]
39 }));
40 this.set("cursorIndex", this.get("length") - 1);
41 },
42
43 remove : function(idx) {
44 this.model.splice(idx, 1);
45 if (this.get("cursorIndex") < 0) {
46 this.set("cursorIndex", this.get("length") - 1);
47 }
48 },
49
50 phoneAddEmpty : function() {
51 this.cursor.Tel.push(new Stateful({
52 "name" : "Home",
53 "number" : ""
54 }));
55 // this is needed for when a new person is added, those phones would not be added correctly without this
56 registry.byId("telRepeat").set("children", at('rel:', 'Tel'));
57 registry.byId("emailInput").focus();
58 // this is done to force it to scroll to the bottom so you can see that it was added.
59 },
60
61 phoneRemove : function(idx) {
62 this.cursor.Tel.splice(idx, 1);
63 registry.byId("telRepeat").set("children", at('rel:', 'Tel'));
64 },
65
66 _setGroupAttr : function(value) {
67 this.set("groupTyped", value);
68 var old = this.group;
69 if (old === value) {
70 return;
71 }
72 when(this.queryStore({
73 Group : value
74 }), function() {
75 if (!inited) {
76 parser.parse();
77 inited = true;
78 }
79 });
80 this._set("group", value);
81 }
82 });
83
84 ctrl = new ctrlClass({
85 store : new JsonRest({
86 target : kernel.moduleUrl("dojox.mvc.tests._data", "jsonRestRepeatData.json")
87 })
88 });
89 ctrl.set("group", "Engineer");
90 });
91 </script>
92 </head>
93 <body class="claro" style="background-image: url(../images/master_detail.png)">
94 <script type="dojo/require">
95 at: "dojox/mvc/at"
96 </script>
97 <div id="wrapper">
98 <div id="header">
99 <div id="navigation"></div>
100 <div id="headerInsert">
101 <h1>Nested WidgetLists</h1>
102 <h2>Nested WidgetLists one for the people and one for their phones, select person and use Details to add or remove a phone.</h2>
103 </div>
104 </div>
105 <div id="main">
106 <div id="leftNav"></div>
107 <div id="mainContent">
108 <div class="fullrow">
109 <div class="spacer"></div>
110 <button type="button" data-dojo-type="dijit.form.Button" data-dojo-props="onClick: function(){ ctrl.commit(); }">
111 Commit All
112 </button>
113 <button type="button" data-dojo-type="dijit.form.Button" data-dojo-props="onClick: function(){ ctrl.reset(); }">
114 Reset to last saved
115 </button>
116 </div>
117 <div class="spacer"></div>
118 <div id="searchBanner">
119 People with multiple phone numbers:
120 </div>
121
122 <div data-dojo-type="dojox/mvc/WidgetList"
123 data-dojo-mixins="dojox/mvc/_InlineTemplateMixin"
124 data-dojo-props="children: at(ctrl, 'model')">
125 <script type="dojox/mvc/InlineTemplate">
126 <div>
127 <label class="fixedcell" for="nameInput${indexAtStartup}">Name:</label>
128 <input class="fixedcell" data-dojo-type="dijit.form.TextBox" id="nameInput${indexAtStartup}"
129 data-dojo-props="value: at('rel:', 'First')">
130 <button type="button" data-dojo-type="dijit.form.Button"
131 data-dojo-props="onClick: function(){ ctrl.set('cursorIndex', ${indexAtStartup}); }">Details</button>
132 <button type="button" data-dojo-type="dijit.form.Button"
133 data-dojo-props="onClick: function(){ ctrl.addEmpty(); }">+</button>
134 <button type="button" data-dojo-type="dijit.form.Button"
135 data-dojo-props="onClick: function(){ ctrl.remove(${indexAtStartup}); }">-</button>
136
137 <!-- try to add nested widgetList here -->
138 <div data-dojo-type="dojox/mvc/WidgetList"
139 data-dojo-mixins="dojox/mvc/_InlineTemplateMixin"
140 data-dojo-props="children: at('rel:', 'Tel')">
141 <script type="dojox/mvc/InlineTemplate">
142 <div>
143 <div class="fullrow">
144 <div class="fixedcell"></div>
145 <label class="fixedcell" data-dojo-type="dojox.mvc.Output" data-dojo-props="value: at('rel:', 'name')"></label>
146 <input class="fixedcell" data-dojo-type="dijit.form.TextBox" data-dojo-props="value: at('rel:', 'number')">
147 </div>
148 </script>
149 </div>
150
151 </div>
152 </script>
153
154 <div class="spacer"></div>
155 <div class="fullrow">
156 <div id="detailsBanner" class="fullrow">
157 <div class="fixedcell"></div>
158 <div class="fixedcell">
159 Details for result index:
160 </div>
161 <span data-dojo-type="dojox.mvc.Output" data-dojo-props="value: at(ctrl, 'cursorIndex')"></span>
162 </div>
163 </div>
164 <div id="detailsGroup" data-dojo-type="dojox.mvc.Group" data-dojo-props="target: at(ctrl, 'cursor')">
165 <div class="fullrow">
166 <label class="fixedcell" for="firstInput">First Name:</label>
167 <input class="fixedcell" id="firstInput" data-dojo-type="dijit.form.TextBox" data-dojo-props="value: at('rel:', 'First')">
168 </div>
169 <div class="fullrow">
170 <label class="fixedcell" for="lastInput">Last Name:</label>
171 <input class="fixedcell" id="lastInput" data-dojo-type="dijit.form.TextBox" data-dojo-props="value: at('rel:', 'Last')">
172 </div>
173 <div class="fullrow">
174 <label class="fixedcell" for="locationInput">Location:</label>
175 <input class="fixedcell" id="locationInput" data-dojo-type="dijit.form.TextBox" data-dojo-props="value: at('rel:', 'Location')">
176 </div>
177 <div class="fullrow">
178 <label class="fixedcell" for="officeInput">Office:</label>
179 <input class="fixedcell" id="officeInput" data-dojo-type="dijit.form.TextBox" data-dojo-props="value: at('rel:', 'Office')">
180 </div>
181 <div class="fullrow">
182 <label class="fixedcell">Phones:</label>
183 <button type="button" data-dojo-type="dijit.form.Button"
184 data-dojo-props="onClick: function(){ ctrl.phoneAddEmpty(); }">
185 +
186 </button>
187 </div>
188 <div data-dojo-type="dojox/mvc/WidgetList" id="telRepeat"
189 data-dojo-mixins="dojox/mvc/_InlineTemplateMixin"
190 data-dojo-props="children: at('rel:', 'Tel')">
191 <script type="dojox/mvc/InlineTemplate">
192 <div>
193 <div class="fullrow">
194 <div class="fixedcell"></div>
195 <input class="fixedcell" data-dojo-type="dijit.form.TextBox" data-dojo-props="value: at('rel:', 'name')">
196 <input class="fixedcell" data-dojo-type="dijit.form.TextBox" data-dojo-props="value: at('rel:', 'number')">
197 <button type="button" data-dojo-type="dijit.form.Button"
198 data-dojo-props="onClick: function(){ ctrl.phoneRemove(${indexAtStartup}); }">-</button>
199 </div>
200 </div>
201 </script>
202 </div>
203 <div class="fullrow">
204 <label class="fixedcell" for="emailInput">Email:</label>
205 <input class="fixedcell" id="emailInput" data-dojo-type="dijit.form.TextBox" data-dojo-props="value: at('rel:', 'Email')">
206 </div>
207 </div>
208 </div>
209 </div>
210 </div>
211 </div>
212 </body>
213 </html>