| 1 |
define(["dojo/_base/lang", "dojo/dom", "dojo/on", "dijit/registry", "dojo/dom-class"], |
| 2 |
function(lang, dom, on, registry, domClass){ |
| 3 |
var _onResults = []; |
| 4 |
|
| 5 |
return { |
| 6 |
|
| 7 |
setDetailsContext: function(index, e, params){ |
| 8 |
if(params){ |
| 9 |
params.cursor = index; |
| 10 |
}else{ |
| 11 |
params = {"cursor":index}; |
| 12 |
} |
| 13 |
|
| 14 |
var transOpts = { |
| 15 |
title : "itemDetails", |
| 16 |
target : "itemDetails", |
| 17 |
url : "#itemDetails", |
| 18 |
params : params |
| 19 |
}; |
| 20 |
this.app.transitionToView(e.target,transOpts,e); |
| 21 |
|
| 22 |
|
| 23 |
}, |
| 24 |
|
| 25 |
|
| 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 |
|
| 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 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
var onResult; |
| 54 |
|
| 55 |
domClass.remove(dom.byId("listInsert1"), "hide"); |
| 56 |
domClass.add(dom.byId("listInsert1"), "show"); |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 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 |
|
| 90 |
|
| 91 |
|
| 92 |
domClass.remove(dom.byId("listInsert1"), "show"); |
| 93 |
domClass.add(dom.byId("listInsert1"), "hide"); |
| 94 |
}, |
| 95 |
|
| 96 |
afterDeactivate: function(){ |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
var onResult = _onResults.pop(); |
| 101 |
while(onResult){ |
| 102 |
onResult.remove(); |
| 103 |
onResult = _onResults.pop(); |
| 104 |
} |
| 105 |
}, |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
destroy: function(){ |
| 110 |
|
| 111 |
} |
| 112 |
}; |
| 113 |
}); |