Debian Codegraph @

dojox/app/tests/mediaQueryLayoutApp/views/list/list.js

raw symbols SCIP
1 define(["dojo/_base/lang", "dojo/dom", "dojo/on", "dijit/registry", "dojo/dom-class"],
2 function(lang, dom, on, registry, domClass){
3 var _onResults = []; // events on array
4
5 return {
6 // setDetailsContext for an item
7 setDetailsContext: function(index, e, params){
8 if(params){
9 params.cursor = index;
10 }else{
11 params = {"cursor":index};
12 }
13 // transition to itemDetails view with the &cursor=index
14 var transOpts = {
15 title : "itemDetails",
16 target : "itemDetails",
17 url : "#itemDetails", // this is optional if not set it will be created from target
18 params : params
19 };
20 this.app.transitionToView(e.target,transOpts,e);
21
22
23 },
24
25 // insert an item
26 insertResult: function(index, e){
27 if(index<0 || index>this.list.store.data.length){
28 throw Error("index out of data model.");
29 }
30 if((this.list.store.data[index-1].First=="") ||
31 (this.list.store.data[index] && (this.list.store.data[index].First == ""))){
32 return;
33 }
34 var data = {id:Math.random(), "label": "", "rightIcon":"mblDomButtonBlueCircleArrow", "First": "", "Last": "", "Location": "CA", "Office": "", "Email": "", "Tel": "", "Fax": ""};
35 this.list.store.add(data);
36 this.setDetailsContext(index, e);
37 },
38
39
40 // list view init
41 init: function(){
42 var list = this.list;
43 if(!list.Store){
44 list.setStore(this.loadedStores.listStore);
45 }
46 },
47
48 beforeActivate: function(){
49 // summary:
50 // view life cycle beforeActivate()
51 //
52
53 var onResult;
54
55 domClass.remove(dom.byId("listInsert1"), "hide");
56 domClass.add(dom.byId("listInsert1"), "show");
57
58 // for(var i = 0; i < this.list.store.data.length; i++){
59 // var item = dom.byId(this.list.store.data[i].id);
60 // onResult = on(item, "click", lang.hitch(this, function(e){
61 // var item = this.list.store.query({"label": e.target.innerHTML})
62 // var index = this.list.store.index[item[0].id];
63 // console.log("index is "+index);
64 // this.setDetailsContext(index, e, this.params);
65 // }));
66 // _onResults.push(onResult);
67 // }
68
69 onResult = this.list.on("click", lang.hitch(this, function(e){
70 console.log("List on click hit ",e);
71 var item = this.list.store.query({"label": e.target.innerHTML});
72 var index = this.list.store.index[item[0].id];
73 console.log("index is "+index);
74 this.setDetailsContext(index, e, this.params);
75 }));
76 _onResults.push(onResult);
77
78 var listInsert1 = dom.byId("listInsert1");
79 onResult = on(listInsert1, "click", lang.hitch(this, function(e){
80 console.log("listInsert1 on click hit ",e);
81 var index = this.list.store.data.length;
82 this.insertResult(index, e);
83 }));
84 _onResults.push(onResult);
85
86 },
87
88 beforeDeactivate: function(){
89 // summary:
90 // view life cycle beforeActivate()
91 //
92 domClass.remove(dom.byId("listInsert1"), "show");
93 domClass.add(dom.byId("listInsert1"), "hide");
94 },
95
96 afterDeactivate: function(){
97 // summary:
98 // view life cycle beforeActivate()
99 //
100 var onResult = _onResults.pop();
101 while(onResult){
102 onResult.remove();
103 onResult = _onResults.pop();
104 }
105 },
106
107
108 // view destroy, this destroy function can be removed since it is empty
109 destroy: function(){
110 // _WidgetBase.on listener is automatically destroyed when the Widget itself is.
111 }
112 };
113 });