Debian Codegraph @

dojox/mvc/tests/1.7/mobile/demo/src.js

raw symbols SCIP
1 var repeatModel, setRef, nextIndexToAdd, selectedIndex;
2 var setRef, setDetailsContext, insertResult, updateView, updateModel;
3
4 require(['dojo/has',
5 'dojox/mobile/parser',
6 //'dojo/parser',
7 'dojo/ready',
8 'dojox/mvc',
9 'dojox/mobile',
10 'dojox/mobile/ScrollableView',
11 'dojox/mobile/Button',
12 'dojox/mobile/TextArea',
13 'dojox/mvc/Group',
14 'dojox/mvc/Generate',
15 'dojox/mvc/Repeat',
16 'dojox/mobile/TextBox',
17 'dojox/mobile/ViewController',
18 'dojox/mobile/FixedSplitter',
19 'dojox/mobile/EdgeToEdgeList',
20 'dojox/mobile/EdgeToEdgeCategory',
21 'dojox/mobile/deviceTheme',
22 'dojox/mobile/RoundRectCategory',
23 'dojox/mobile/Heading',
24 'dijit/registry',
25 'dojo/_base/json',
26 'dojo/dom'
27 ], function(has, parser, ready, mvc, mobile, ScrollableView, Button, TextArea, Group, Generate, Repeat, TextBox, ViewController,
28 FixedSplitter, EdgeToEdgeList, EdgeToEdgeCategory, deviceTheme, RoundRectCategory, Heading, WidgetRegistry,
29 json, dom){
30
31 if(!has("webkit")){
32 require(["dojox/mobile/compat"]);
33 }
34
35 var names = {
36 "Serial" : "360324",
37 "First" : "John",
38 "Last" : "Doe",
39 "Email" : "[email protected]",
40 "ShipTo" : {
41 "Street" : "123 Valley Rd",
42 "City" : "Katonah",
43 "State" : "NY",
44 "Zip" : "10536"
45 },
46 "BillTo" : {
47 "Street" : "17 Skyline Dr",
48 "City" : "Hawthorne",
49 "State" : "NY",
50 "Zip" : "10532"
51 }
52 };
53
54 // Initial repeat data used in the Repeat Data binding demo
55 var repeatData = [
56 {
57 "First" : "Chad",
58 "Last" : "Chapman",
59 "Location": "CA",
60 "Office" : "1278",
61 "Email" : "[email protected]",
62 "Tel" : "408-764-8237",
63 "Fax" : "408-764-8228"
64 },
65 {
66 "First" : "Irene",
67 "Last" : "Ira",
68 "Location": "NJ",
69 "Office" : "F09",
70 "Email" : "[email protected]",
71 "Tel" : "514-764-6532",
72 "Fax" : "514-764-7300"
73 },
74 {
75 "First" : "John",
76 "Last" : "Jacklin",
77 "Location": "CA",
78 "Office" : "6701",
79 "Email" : "[email protected]",
80 "Tel" : "408-764-1234",
81 "Fax" : "408-764-4321"
82 }
83 ];
84
85 selectedIndex = 0;
86
87 model = mvc.newStatefulModel({ data : names });
88 repeatmodel = mvc.newStatefulModel({ data : repeatData });
89 nextIndexToAdd = repeatmodel.data.length;
90
91 // used in the Ship to - Bill to demo
92 setRef = function(id, addrRef) {
93 var widget = WidgetRegistry.byId(id);
94 widget.set("ref", addrRef);
95 }
96
97 // used in the Repeat Data binding demo
98 setDetailsContext = function(index){
99 selectedIndex = index;
100 var groupRoot = WidgetRegistry.byId("detailsGroup");
101 groupRoot.set("ref", index);
102 }
103
104 // used in the Repeat Data binding demo
105 insertResult = function(index){
106 if (repeatmodel[index-1].First.value !== ""){ // TODO: figure out why we are getting called twice for each click
107 var insert = mvc.newStatefulModel({ "data" : {
108 "First" : "",
109 "Last" : "",
110 "Location": "CA",
111 "Office" : "",
112 "Email" : "",
113 "Tel" : "",
114 "Fax" : ""}
115 });
116 repeatmodel.add(index, insert);
117 setDetailsContext(index);
118 nextIndexToAdd++;
119 }else{
120 setDetailsContext(index-1);
121 }
122 };
123
124 // used in the Generate View demo
125 var genmodel;
126 updateView = function() {
127 try {
128 var modeldata = json.fromJson(dom.byId("modelArea").value);
129 genmodel = mvc.newStatefulModel({ data : modeldata });
130 WidgetRegistry.byId("view").set("ref", genmodel);
131 dom.byId("outerModelArea").style.display = "none";
132 dom.byId("viewArea").style.display = "";
133 }catch(err){
134 console.error("Error parsing json from model: "+err);
135 }
136 };
137
138 // used in the Generate View demo
139 updateModel = function() {
140 dom.byId("outerModelArea").style.display = "";
141 try {
142 dom.byId("modelArea").focus(); // hack: do this to force focus off of the textbox, bug on mobile?
143 dom.byId("viewArea").style.display = "none";
144 WidgetRegistry.byId("modelArea").set("value",(json.toJson(genmodel.toPlainObject(), true)));
145 } catch(e) {
146 console.log(e);
147 };
148 };
149
150
151 // The dojox.mvc.StatefulModel class creates a data model instance
152 // where each leaf within the data model is decorated with dojo.Stateful
153 // properties that widgets can bind to and watch for their changes.
154
155
156 // when "dojo/ready" is ready call parse
157 ready(function(){
158 parser.parse();
159 });
160
161 // when domReady! is ready show the page
162 require(['dojo/domReady!'], function(){
163 dom.byId("wholepage").style.display = "";
164 });
165
166 }); // end function
167