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