Debian Codegraph @

dojox/mvc/tests/1.7/mobile/demo/src-async-store.js

raw symbols SCIP
1 var repeatModel, setRef, nextIndexToAdd, selectedIndex;
2 var setRef, setDetailsContext, insertResult, updateView, updateModel;
3
4 require([
5 'dojox/mobile/parser',
6 'dojox/mvc',
7 'dojox/mobile',
8 'dojox/mobile/ScrollableView',
9 'dojox/mobile/Button',
10 'dojox/mobile/TextArea',
11 'dojox/mvc/Group',
12 'dojox/mvc/Generate',
13 'dojox/mvc/Repeat',
14 'dojox/mobile/TextBox',
15 'dojox/mobile/ViewController',
16 'dojox/mobile/FixedSplitter',
17 'dojox/mobile/EdgeToEdgeList',
18 'dojox/mobile/EdgeToEdgeCategory',
19 'dojox/mobile/deviceTheme',
20 'dojox/mobile/RoundRectCategory',
21 'dojox/mobile/Heading',
22 'dojo/data/ItemFileWriteStore',
23 'dojo/store/DataStore'
24 ], function(){
25 require([
26 "dojox/mobile/compat"
27 ]);
28
29 var names = {
30 "Serial" : "360324",
31 "First" : "John",
32 "Last" : "Doe",
33 "Email" : "[email protected]",
34 "ShipTo" : {
35 "Street" : "123 Valley Rd",
36 "City" : "Katonah",
37 "State" : "NY",
38 "Zip" : "10536"
39 },
40 "BillTo" : {
41 "Street" : "17 Skyline Dr",
42 "City" : "Hawthorne",
43 "State" : "NY",
44 "Zip" : "10532"
45 }
46 };
47
48 selectedIndex = 0;
49
50 model = dojox.mvc.newStatefulModel({ data : names });
51 repeatmodel = null; // use store for repeat data
52 nextIndexToAdd = -1;
53
54 // used in the Ship to - Bill to demo
55 setRef = function(id, addrRef) {
56 var widget = dijit.byId(id);
57 widget.set("ref", addrRef);
58 }
59
60 // used in the Repeat Data binding demo
61 setDetailsContext = function(index){
62 selectedIndex = index;
63 var groupRoot = dijit.byId("detailsGroup");
64 groupRoot.set("ref", index);
65 }
66
67 // used in the Repeat Data binding demo
68 insertResult = function(index){
69 if (repeatmodel[index-1].First.value !== ""){ // TODO: figure out why we are getting called twice for each click
70 var insert = dojox.mvc.newStatefulModel({ "data" : {
71 "First" : "",
72 "Last" : "",
73 "Location": "CA",
74 "Office" : "",
75 "Email" : "",
76 "Tel" : "",
77 "Fax" : ""}
78 });
79 repeatmodel.add(index, insert);
80 setDetailsContext(index);
81 nextIndexToAdd++;
82 }else{
83 setDetailsContext(index-1);
84 }
85 };
86
87 // used in the Generate View demo
88 var genmodel;
89 updateView = function() {
90 try {
91 var modeldata = dojo.fromJson(dojo.byId("modelArea").value);
92 genmodel = dojox.mvc.newStatefulModel({ data : modeldata });
93 dijit.byId("view").set("ref", genmodel);
94 dojo.byId("outerModelArea").style.display = "none";
95 dojo.byId("viewArea").style.display = "";
96 }catch(err){
97 console.error("Error parsing json from model: "+err);
98 }
99 };
100
101 // used in the Generate View demo
102 updateModel = function() {
103 dojo.byId("outerModelArea").style.display = "";
104 try {
105 dojo.byId("modelArea").focus(); // hack: do this to force focus off of the textbox, bug on mobile?
106 dojo.byId("viewArea").style.display = "none";
107 dijit.byId("modelArea").set("value",(dojo.toJson(genmodel.toPlainObject(), true)));
108 } catch(e) {
109 console.log(e);
110 };
111 };
112
113
114 // The dojox.mvc.StatefulModel class creates a data model instance
115 // where each leaf within the data model is decorated with dojo.Stateful
116 // properties that widgets can bind to and watch for their changes.
117 var writeStore = new dojo.data.ItemFileWriteStore({url: dojo.moduleUrl("dojox.mvc.tests._data", "mvcRepeatData.json")});
118 var modelPromise = dojox.mvc.newStatefulModel({store: new dojo.store.DataStore({store: writeStore}), query:{"Location" : "CA"}}); // example of using a query parm for Location
119
120 require(['dojo/domReady!'], function(){
121 modelPromise.then(function(results){
122 repeatmodel = results;
123 nextIndexToAdd = repeatmodel.data.length;
124 console.log("before call to parser.parse");
125 dojox.mobile.parser.parse();
126 console.log("before call to set the wholepage style for display");
127 dojo.byId("wholepage").style.display = "";
128 console.log("after call to set the wholepage style for display");
129 });
130
131 });
132
133 dojo.addOnLoad(function() {
134 });
135
136 }); // end function
137