| 1 |
define(["dojo/dom", "dojo/dom-style", "dojo/_base/connect", "dojo/_base/lang", "dojo/_base/declare", "dijit/registry", "dojox/mvc/at", |
| 2 |
"dojox/mobile/TransitionEvent", "dojox/mvc/Repeat", "dojox/mvc/getStateful", "dojox/mvc/Output", "dojo/sniff", |
| 3 |
"dojox/mobile/RoundRectList", "dojox/mvc/WidgetList", "dojox/mvc/Templated", "dojox/mobile/ListItem", "dojo/text!../views/RoundRectWidListTemplate.html"], |
| 4 |
function(dom, domStyle, connect, lang, declare, registry, at, TransitionEvent, Repeat, getStateful, Output, has, RoundRectList, WidgetList, Templated, |
| 5 |
ListItem, RoundRectWidListTemplate){ |
| 6 |
var _connectResults = []; |
| 7 |
|
| 8 |
var repeatmodel = null; |
| 9 |
var roundRectWidList = null; |
| 10 |
|
| 11 |
|
| 12 |
var backId = 'sc1back1P'; |
| 13 |
var insert1Id = 'sc1insert1xP'; |
| 14 |
var insert10Id = 'sc1insert10xP'; |
| 15 |
var remove10Id = 'sc1remove10xP'; |
| 16 |
|
| 17 |
var app = null; |
| 18 |
|
| 19 |
|
| 20 |
var insertResult = function(index, e){ |
| 21 |
if(index<0 || index>repeatmodel.model.length){ |
| 22 |
throw Error("index out of data model."); |
| 23 |
} |
| 24 |
if((repeatmodel.model[index].First=="") || |
| 25 |
(repeatmodel.model[index+1] && (repeatmodel.model[index+1].First == ""))){ |
| 26 |
return; |
| 27 |
} |
| 28 |
var data = {id:Math.random(), "First": "", "Last": "", "Location": "CA", "Office": "", "Email": "", "Tel": "", "Fax": ""}; |
| 29 |
repeatmodel.model.splice(index+1, 0, new getStateful(data)); |
| 30 |
this.app.setDetailsContext(index+1); |
| 31 |
var transOpts = { |
| 32 |
title : "repeatDetails", |
| 33 |
target : "repeatDetails", |
| 34 |
url : "#repeatDetails", |
| 35 |
params : {"cursor":index+1} |
| 36 |
}; |
| 37 |
new TransitionEvent(e.target, transOpts, e).dispatch(); |
| 38 |
|
| 39 |
}; |
| 40 |
|
| 41 |
var showListData = function( datamodel){ |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
if(!roundRectWidList){ |
| 51 |
var clz = declare([WidgetList, RoundRectList], {}); |
| 52 |
roundRectWidList = new clz({ |
| 53 |
children: at(datamodel, 'model'), |
| 54 |
childClz: declare([Templated , ListItem ]), |
| 55 |
childParams: { |
| 56 |
transitionOptions: {title:'Details',target:'repeatDetails',url:'#repeatDetails',params:{'cursor':this.indexAtStartup}}, |
| 57 |
clickable: true, |
| 58 |
onClick: function(){ |
| 59 |
console.log("in onClick this.indexAtStartup="+this.indexAtStartup); |
| 60 |
app.setDetailsContext(this.indexAtStartup);} |
| 61 |
}, |
| 62 |
childBindings: { |
| 63 |
titleNode: {value: at("rel:", "First")} |
| 64 |
}, |
| 65 |
templateString: RoundRectWidListTemplate |
| 66 |
}); |
| 67 |
roundRectWidList.placeAt(dom.byId("addWidgetHere")); |
| 68 |
roundRectWidList.startup(); |
| 69 |
}else{ |
| 70 |
roundRectWidList.set("children", at(datamodel, 'model')); |
| 71 |
} |
| 72 |
}; |
| 73 |
|
| 74 |
return { |
| 75 |
init: function(){ |
| 76 |
app = this.app; |
| 77 |
|
| 78 |
repeatmodel = this.loadedModels.repeatmodels; |
| 79 |
var connectResult; |
| 80 |
|
| 81 |
connectResult = connect.connect(dom.byId(insert1Id), "click", function(e){ |
| 82 |
app.insertResult(repeatmodel.model.length-1,e); |
| 83 |
}); |
| 84 |
_connectResults.push(connectResult); |
| 85 |
|
| 86 |
connectResult = connect.connect(dom.byId(insert10Id), "click", function(){ |
| 87 |
|
| 88 |
app.showProgressIndicator(true); |
| 89 |
setTimeout(lang.hitch(this,function(){ |
| 90 |
var maxentries = repeatmodel.model.length+10; |
| 91 |
for(var i = repeatmodel.model.length; i < maxentries; i++){ |
| 92 |
var data = {id:Math.random(), "First": "First"+repeatmodel.model.length, "Last": "Last"+repeatmodel.model.length, "Location": "CA", "Office": "", "Email": "", "Tel": "", "Fax": ""}; |
| 93 |
repeatmodel.model.splice(repeatmodel.model.length, 0, new getStateful(data)); |
| 94 |
} |
| 95 |
app.showProgressIndicator(false); |
| 96 |
}), 100); |
| 97 |
|
| 98 |
}); |
| 99 |
_connectResults.push(connectResult); |
| 100 |
|
| 101 |
connectResult = connect.connect(dom.byId(remove10Id), "click", function(){ |
| 102 |
|
| 103 |
app.showProgressIndicator(true); |
| 104 |
setTimeout(lang.hitch(this,function(){ |
| 105 |
var maxentries = repeatmodel.model.length-10; |
| 106 |
for(var i = repeatmodel.model.length; i >= maxentries; i--){ |
| 107 |
repeatmodel.model.splice(i, 1); |
| 108 |
} |
| 109 |
repeatmodel.set("cursorIndex", 0); |
| 110 |
app.showProgressIndicator(false); |
| 111 |
}), 100); |
| 112 |
}); |
| 113 |
_connectResults.push(connectResult); |
| 114 |
|
| 115 |
showListData(this.loadedModels.repeatmodels); |
| 116 |
}, |
| 117 |
|
| 118 |
|
| 119 |
beforeActivate: function(){ |
| 120 |
|
| 121 |
|
| 122 |
if(dom.byId(backId) && !has("phone")){ |
| 123 |
domStyle.set(dom.byId(backId), "visibility", "hidden"); |
| 124 |
} |
| 125 |
if(dom.byId("tab1WrapperA")){ |
| 126 |
domStyle.set(dom.byId("tab1WrapperA"), "visibility", "visible"); |
| 127 |
domStyle.set(dom.byId("tab1WrapperB"), "visibility", "visible"); |
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
showListData(this.loadedModels.repeatmodels); |
| 135 |
}, |
| 136 |
|
| 137 |
afterActivate: function(){ |
| 138 |
|
| 139 |
|
| 140 |
}, |
| 141 |
|
| 142 |
|
| 143 |
destroy: function(){ |
| 144 |
var connectResult = _connectResults.pop(); |
| 145 |
while(connectResult){ |
| 146 |
connect.disconnect(connectResult); |
| 147 |
connectResult = _connectResults.pop(); |
| 148 |
} |
| 149 |
} |
| 150 |
}; |
| 151 |
}); |