Debian Codegraph @

dojox/app/tests/swapViewTestApp/views/repeat.js

raw symbols SCIP
1 define(["dojo/dom", "dojo/_base/connect", "dijit/registry", "dojox/mvc/at", "dojox/mobile/TransitionEvent", "dojox/mvc/Repeat", "dojox/mvc/getStateful"],
2 function(dom, connect, registry, at, TransitionEvent, Repeat, getStateful){
3 var _connectResults = []; // events connect result
4
5 var repeatmodel = null; //repeat view data model
6
7 // delete an item
8 var deleteResult = function(index){
9 var nextIndex = repeatmodel.get("cursorIndex");
10 if(nextIndex >= index){
11 nextIndex = nextIndex-1;
12 }
13 repeatmodel.model.splice(index, 1);
14 repeatmodel.set("cursorIndex", nextIndex);
15 };
16 // show an item detail
17 var setDetailsContext = function(index,e){
18 repeatmodel.set("cursorIndex", index);
19
20 // transition to repeatDetails view with the &cursor=index
21 var transOpts = {
22 title : "TestInfo+simple+repeatDetails+navigation",
23 target : "TestInfo+simple+repeatDetails+navigation",
24 url : "#TestInfo+simple+repeatDetails+navigation", // this is optional if not set it will be created from target
25 params : {"cursor":index}
26 };
27 new TransitionEvent(e.target, transOpts, e).dispatch();
28
29 };
30 // insert an item
31 var insertResult = function(index, e){
32 if(index<0 || index>repeatmodel.model.length){
33 throw Error("index out of data model.");
34 }
35 if((repeatmodel.model[index].First=="") ||
36 (repeatmodel.model[index+1] && (repeatmodel.model[index+1].First == ""))){
37 return;
38 }
39 var data = {id:Math.random(), "First": "", "Last": "", "Location": "CA", "Office": "", "Email": "", "Tel": "", "Fax": ""};
40 repeatmodel.model.splice(index+1, 0, new getStateful(data));
41 setDetailsContext(index+1, e);
42 };
43 // get index from dom node id
44 var getIndexFromId = function(nodeId, perfix){
45 var len = perfix.length;
46 if(nodeId.length <= len){
47 throw Error("repeat node id error.");
48 }
49 var index = nodeId.substring(len, nodeId.length);
50 return parseInt(index);
51 };
52
53 return {
54 // repeat view init
55 init: function(){
56 repeatmodel = this.loadedModels.repeatmodels;
57 },
58
59 beforeActivate: function(){
60 // summary:
61 // view life cycle beforeActivate()
62 //
63 var repeatDom = dom.byId('repeatWidget');
64 var connectResult;
65 connectResult = connect.connect(repeatDom, "button[id^=\"detail\"]:click", function(e){
66 var index = getIndexFromId(e.target.id, "detail");
67 setDetailsContext(index, e);
68 });
69 _connectResults.push(connectResult);
70
71 connectResult = connect.connect(repeatDom, "button[id^=\"insert\"]:click", function(e){
72 var index = getIndexFromId(e.target.id, "insert");
73 insertResult(index, e);
74 });
75 _connectResults.push(connectResult);
76
77 connectResult = connect.connect(repeatDom, "button[id^=\"delete\"]:click", function(e){
78 var index = getIndexFromId(e.target.id, "delete");
79 deleteResult(index);
80 });
81 _connectResults.push(connectResult);
82
83 },
84
85 afterDeactivate: function(){
86 // summary:
87 // view life cycle beforeActivate()
88 //
89 var connectResult = _connectResults.pop();
90 while(connectResult){
91 connect.disconnect(connectResult);
92 connectResult = _connectResults.pop();
93 }
94 },
95
96 // view destroy
97 destroy: function(){
98 var connectResult = _connectResults.pop();
99 while(connectResult){
100 connect.disconnect(connectResult);
101 connectResult = _connectResults.pop();
102 }
103 }
104 };
105 });