Debian Codegraph @

dojox/mvc/tests/WidgetList_tests/test_mvc_observable-search-results-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>Static Master/Detail Pattern -- Search Results example</title>
6 <script src="../../../../dojo/dojo.js" type="text/javascript" data-dojo-config="parseOnLoad: 0, isDebug: true, mvc: {debugBindings: true}">
7 </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 data = [
14 {
15 id: "1",
16 Group: "Engineer",
17 First: "Anne",
18 Last: "Ackerman",
19 Location: "NY",
20 Office: "1S76",
21 Email: "[email protected]",
22 Tel: "123-764-8237",
23 Fax: "123-764-8228"
24 },
25 {
26 id: "2",
27 Group: "Engineer",
28 First: "Ben",
29 Last : "Beckham",
30 Location: "NY",
31 Office: "5N47",
32 Email: "[email protected]",
33 Tel: "123-764-8599",
34 Fax: "123-764-8600"
35 },
36 {
37 id: "3",
38 Group: "Engineer",
39 First: "Chad",
40 Last: "Chapman",
41 Location: "CA",
42 Office: "1278",
43 Email: "[email protected]",
44 Tel: "408-764-8237",
45 Fax: "408-764-8228"
46 },
47 {
48 id: "4",
49 Group: "Engineer",
50 First: "David",
51 Last: "Durham",
52 Location: "NJ",
53 Office: "C12",
54 Email: "[email protected]",
55 Tel: "514-764-8237",
56 Fax: "514-764-8228"
57 },
58 {
59 id: "5",
60 Group: "Engineer",
61 First: "Emma",
62 Last: "Eklof",
63 Location: "NY",
64 Office: "4N76",
65 Email: "[email protected]",
66 Tel: "123-764-1234",
67 Fax: "123-764-4321"
68 },
69 {
70 id: "6",
71 Group: "Manager",
72 First: "Fred",
73 Last: "Fisher",
74 Location: "NJ",
75 Office: "V89",
76 Email: "[email protected]",
77 Tel: "514-764-8567",
78 Fax: "514-764-8000"
79 },
80 {
81 id: "7",
82 Group: "Manager",
83 First: "George",
84 Last: "Garnett",
85 Location: "NY",
86 Office: "7S11",
87 Email: "[email protected]",
88 Tel: "123-999-8599",
89 Fax: "123-999-8600"
90 },
91 {
92 id: "8",
93 Group: "Accountant",
94 First: "Hunter",
95 Last: "Huffman",
96 Location: "CA",
97 Office: "6532",
98 Email: "[email protected]",
99 Tel: "408-874-8237",
100 Fax: "408-874-8228"
101 },
102 {
103 id: "9",
104 Group: "Accountant",
105 First: "Irene",
106 Last: "Ira",
107 Location: "NJ",
108 Office: "F09",
109 Email: "[email protected]",
110 Tel: "514-764-6532",
111 Fax: "514-764-7300"
112 },
113 {
114 id: "10",
115 Group: "Accountant",
116 First: "John",
117 Last: "Jacklin",
118 Location: "CA",
119 Office: "6701",
120 Email: "[email protected]",
121 Tel: "408-764-1234",
122 Fax: "408-764-4321"
123 }
124 ], ctrl;
125
126 require([
127 "dojo/_base/declare",
128 "dojo/when",
129 "dojo/parser",
130 "dijit/registry",
131 "dojo/Stateful",
132 "dojo/store/Memory",
133 "dojo/store/Observable",
134 "dojox/mvc/EditStoreRefListController",
135 "dojox/mvc/equals",
136 "dijit/form/Button",
137 "dijit/form/RadioButton",
138 "dijit/form/TextBox",
139 "dijit/form/ComboBox",
140 "dijit/Dialog",
141 "dojox/mvc/Group",
142 "dojox/mvc/Output",
143 "dojox/mvc/Templated",
144 "dojox/mvc/WidgetList",
145 "dojo/domReady!"
146 ], function(declare, when, parser, registry, Stateful, Memory, Observable,
147 EditStoreRefListController, equals){
148
149 var inited,
150 ctrlClass = declare([EditStoreRefListController], {
151 cursorIndex: 0,
152 idProperty: "id",
153 group: "",
154 groupTyped: "",
155 _refModelProp: "model",
156
157 addEmpty: function(idx){
158 //this.model.push(new Stateful({id:Math.random(), Group: this.groupTyped, First: "", Last: "", Location: "", Office: "", Email: "", Tel: "", Fax: ""}));
159 this.model.splice(idx+1, 0, new Stateful({id:Math.random(), Group: this.groupTyped, First: "", Last: "", Location: "", Office: "", Email: "", Tel: "", Fax: ""}));
160 this.set("cursorIndex", idx+1);
161 //this.set("cursorIndex", this.get("length") - 1);
162 },
163
164 remove: function(idx){
165 this.model.splice(idx, 1);
166 if(this.get("cursorIndex") < 0){
167 this.set("cursorIndex", this.get("length") - 1);
168 }
169 },
170
171 // called when set("group",..) is called, this will query the store
172 _setGroupAttr: function(value){
173 this.set("groupTyped", value);
174 var old = this.group;
175 if(old === value){ return; }
176 when(this.queryStore({Group: value}), function(){
177 if(!inited){
178 parser.parse();
179 inited = true;
180 }
181 });
182 this._set("group", value);
183
184 this.sourceModel.observe(function(object, removedFrom, insertedInto){
185 console.log("observeHandle hit");
186 // need to check to see if the model has been updated, use mvc.equals.
187 var clean = equals(ctrl.originalModel, ctrl.model);
188 console.log("store updated, model is clean? "+clean);
189 if(!clean){
190 // use a simple confirm dialog for this one
191 if(confirm("The store has been updated, do you want to save your changes? Select 'OK' to save your changes, select 'Cancel' to discard your changes")){
192 ctrl.commit();
193 }
194 }
195 var grp = ctrl.get("group");
196 ctrl.queryStore({Group: grp});
197 });
198
199 }
200 });
201
202 // called to show items for a different group
203 search = function() {
204 // need to check to see if the model has been updated, use mvc.equals.
205 var clean = equals(ctrl.originalModel, ctrl.model);
206 console.log("the seach is changing, model is clean? "+clean);
207 if(!clean && (ctrl.get('groupTyped') !== ctrl.get('group'))){
208 // use a dijit.dialog for this one
209 registry.byId("myFormDialog").show();
210 }else{
211 ctrl.set('group', ctrl.get('groupTyped'));
212 }
213 };
214
215 commitAndUpdate = function(){
216 registry.byId("myFormDialog").hide();
217 ctrl.commit();
218 ctrl.set('group', ctrl.get('groupTyped'));
219 };
220
221 justUpdate = function(){
222 registry.byId("myFormDialog").hide();
223 ctrl.set('group', ctrl.get('groupTyped'));
224 };
225
226 storeAddIndex = 0;
227 // Add an item to the store, to see the Observable fire
228 testStoreAdd = function(){
229 storeAddIndex++;
230 var store = ctrl.store;
231 var grp = ctrl.get("group");
232 var newdata = {Group: grp, First: "NEWfirst"+storeAddIndex,
233 Last: "NEWlast"+storeAddIndex, Location: "NEWlocation"+storeAddIndex,
234 Office: "NEWoffice"+storeAddIndex, Email: "NEWEmail"+storeAddIndex,
235 Tel: "NEWtel"+storeAddIndex, Fax: "NEWfax"+storeAddIndex};
236
237 store.put(newdata);
238 };
239
240 // using Observable allows us to listen for any changes to the store
241 ctrl = new ctrlClass({store: Observable(new dojo.store.Memory({data: data}))});
242 ctrl.set("group", "Engineer");
243 });
244 </script>
245 </head>
246 <body class="claro" style="background-image: url(../images/master_detail.png)">
247 <script type="dojo/require">at: "dojox/mvc/at"</script>
248 <div id="wrapper">
249 <div id="header">
250 <div id="navigation"></div>
251 <div id="headerInsert">
252 <h1>Employee Search</h1>
253 <h2>Master Detail Example - Observable Repeat with insert and delete.</h2>
254 <h4>Press the "Add New Item to Store" button to update the store with a new item, the Observable will fire and update the model if no updates are in progress. If an uncommitted change has been made an alert will ask if you want to save your change.</h4>
255 </div>
256 </div>
257 <div id="main">
258 <div id="leftNav"></div>
259 <div id="mainContent">
260 <div class="row">
261 <div class="spacer"></div>
262 <button type="button" data-dojo-type="dijit.form.Button" data-dojo-props="onClick: function(){ testStoreAdd(); }">Add New Item to Store</button>
263 <button type="button" data-dojo-type="dijit.form.Button" data-dojo-props="onClick: function(){ ctrl.commit(); }">Commit All</button>
264 <button type="button" data-dojo-type="dijit.form.Button" data-dojo-props="onClick: function(){ ctrl.reset(); }">Reset to last saved</button>
265 </div>
266 <div class="spacer"></div>
267 <div>
268 Try "Engineer", "Manager", or "Accountant":
269 </div>
270 <div class="row">
271 <label class="cell" for="queryInput">Search for:</label>
272 <select id="setvaluetest" data-dojo-type="dijit.form.ComboBox" data-dojo-props="value: at(ctrl, 'groupTyped')">
273 <option value="Engineer">Engineer</option>
274 <option value="Manager">Manager</option>
275 <option value="Accountant">Accountant</option>
276 </select>
277 <button type="button" data-dojo-type="dijit.form.Button"
278 data-dojo-props="onClick: function(){ search(); }">Search</button>
279 </div>
280 <div class="spacer"></div>
281 <div id="searchBanner">
282 Search Results for group: <span data-dojo-type="dojox.mvc.Output" data-dojo-props="value: at(ctrl, 'group')"></span>
283 </div>
284 <!--
285 <div data-dojo-type="dojox.mvc.Repeat" data-dojo-props="children: at(ctrl, 'model')">
286 <div class="row" data-dojo-type="dijit._WidgetBase" data-dojo-props="target: at('rel:', ${this.index})">
287 <label class="cell" for="nameInput${this.index}">Name:</label>
288 <input class="cell" data-dojo-type="dijit.form.TextBox" id="nameInput${this.index}"
289 data-dojo-props="value: at('rel:', 'First')">
290 <button type="button" data-dojo-type="dijit.form.Button"
291 data-dojo-props="onClick: function(){ ctrl.set('cursorIndex', ${this.index}); }">Details</button>
292 <button type="button" data-dojo-type="dijit.form.Button"
293 data-dojo-props="onClick: function(){ ctrl.addEmpty(${index}); }">+</button>
294 <button type="button" data-dojo-type="dijit.form.Button"
295 data-dojo-props="onClick: function(){ ctrl.remove(${index}); }">-</button>
296 </div>
297 </div>
298 -->
299
300 <div data-dojo-type="dojox/mvc/WidgetList"
301 data-dojo-mixins="dojox/mvc/_InlineTemplateMixin"
302 data-dojo-props="children: at(ctrl, 'model')">
303 <script type="dojox/mvc/InlineTemplate">
304 <div>
305 <label class="cell" for="nameInput${indexAtStartup}">Name:</label>
306 <input class="cell" data-dojo-type="dijit.form.TextBox" id="nameInput${indexAtStartup}"
307 data-dojo-props="value: at('rel:', 'First')">
308 <button type="button" data-dojo-type="dijit.form.Button"
309 data-dojo-props="onClick: function(){ ctrl.set('cursorIndex', ${indexAtStartup}); }">Details</button>
310 <button type="button" data-dojo-type="dijit.form.Button"
311 data-dojo-props="onClick: function(){ ctrl.addEmpty(${indexAtStartup}); }">+</button>
312 <button type="button" data-dojo-type="dijit.form.Button"
313 data-dojo-props="onClick: function(){ ctrl.remove(${indexAtStartup}); }">-</button>
314 </div>
315 </script>
316 </div>
317
318
319 <div class="spacer"></div>
320 <div id="detailsBanner">
321 Details for result index:
322 <span data-dojo-type="dojox.mvc.Output" data-dojo-props="value: at(ctrl, 'cursorIndex')"></span>
323 </div>
324 <button type="button" data-dojo-type="dijit.form.Button" data-dojo-props="onClick: function(){ ctrl.commitCurrent(); }">Save Item</button>
325 <div id="detailsGroup" data-dojo-type="dojox.mvc.Group" data-dojo-props="target: at(ctrl, 'cursor')">
326 <div class="row">
327 <label class="cell" for="firstInput">First Name:</label>
328 <input class="cell" id="firstInput" data-dojo-type="dijit.form.TextBox" data-dojo-props="value: at('rel:', 'First')">
329 </div>
330 <div class="row">
331 <label class="cell" for="lastInput">Last Name:</label>
332 <input class="cell" id="lastInput" data-dojo-type="dijit.form.TextBox" data-dojo-props="value: at('rel:', 'Last')">
333 </div>
334 <div class="row">
335 <label class="cell" for="locationInput">Location:</label>
336 <input class="cell" id="locationInput" data-dojo-type="dijit.form.TextBox" data-dojo-props="value: at('rel:', 'Location')">
337 </div>
338 <div class="row">
339 <label class="cell" for="officeInput">Office:</label>
340 <input class="cell" id="officeInput" data-dojo-type="dijit.form.TextBox" data-dojo-props="value: at('rel:', 'Office')">
341 </div>
342 <div class="row">
343 <label class="cell" for="emailInput">Email:</label>
344 <input class="cell" id="emailInput" data-dojo-type="dijit.form.TextBox" data-dojo-props="value: at('rel:', 'Email')">
345 </div>
346 <div class="row">
347 <label class="cell" for="telInput">Telephone:</label>
348 <input class="cell" id="telInput" data-dojo-type="dijit.form.TextBox" data-dojo-props="value: at('rel:', 'Tel')">
349 </div>
350 <div class="row">
351 <label class="cell" for="faxInput">Fax:</label>
352 <input class="cell" id="faxInput" data-dojo-type="dijit.form.TextBox" data-dojo-props="value: at('rel:', 'Fax')">
353 </div>
354 </div>
355 </div>
356 </div>
357 </div>
358 <div data-dojo-type="dijit/Dialog" id="myFormDialog" title="Changing the search will cause you to lose your updates, do you want to save your changes?">
359 <h3>Save Updates?</h3>
360 <h5>
361 "Changing the search will cause you to lose your updates, do you want to save your changes?
362 <br />
363 Select 'Yes' to save your changes, select 'No' to discard your changes"
364 </h5>
365 <br />
366 <button type="button" data-dojo-type="dijit.form.Button" data-dojo-props="onClick:commitAndUpdate">Yes</button>
367 <button type="button" data-dojo-type="dijit.form.Button" data-dojo-props="onClick:justUpdate">No</button>
368 </div>
369 </body>
370 </html>