| 1 |
define(["dojo/_base/lang", "dojo/on"], function(lang, on){ |
| 2 |
|
| 3 |
return { |
| 4 |
|
| 5 |
setDetailsContext: function(index, e, params){ |
| 6 |
if(params){ |
| 7 |
params.cursor = index; |
| 8 |
}else{ |
| 9 |
params = {"cursor":index}; |
| 10 |
} |
| 11 |
|
| 12 |
var transOpts = { |
| 13 |
title : "itemDetails", |
| 14 |
target : "listMain,itemDetails", |
| 15 |
url : "#listMain,itemDetails", |
| 16 |
params : params |
| 17 |
}; |
| 18 |
this.app.transitionToView(e.target,transOpts,e); |
| 19 |
|
| 20 |
|
| 21 |
}, |
| 22 |
|
| 23 |
|
| 24 |
insertResult: function(index, e){ |
| 25 |
if(index<0 || index>this.list.store.data.length){ |
| 26 |
throw Error("index out of data model."); |
| 27 |
} |
| 28 |
if((this.list.store.data[index-1].First=="") || |
| 29 |
(this.list.store.data[index] && (this.list.store.data[index].First == ""))){ |
| 30 |
return; |
| 31 |
} |
| 32 |
var data = {id:Math.random(), "label": "", "rightIcon":"mblDomButtonBlueCircleArrow", "First": "", "Last": "", "Location": "CA", "Office": "", "Email": "", "Tel": "", "Fax": ""}; |
| 33 |
this.list.store.add(data); |
| 34 |
this.setDetailsContext(index, e); |
| 35 |
}, |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
init: function(){ |
| 40 |
var list = this.list; |
| 41 |
if(!list.Store){ |
| 42 |
list.setStore(this.loadedStores.listStore); |
| 43 |
} |
| 44 |
|
| 45 |
this.list.on("click", lang.hitch(this, function(e){ |
| 46 |
console.log("List on click hit ",e); |
| 47 |
var item = this.list.store.query({"label": e.target.innerHTML}); |
| 48 |
var index = this.list.store.index[item[0].id]; |
| 49 |
console.log("index is "+index); |
| 50 |
this.setDetailsContext(index, e, this.params); |
| 51 |
})); |
| 52 |
|
| 53 |
this.listInsert1.on("click", lang.hitch(this, function(e){ |
| 54 |
console.log("listInsert1 on click hit ",e); |
| 55 |
var index = this.list.store.data.length; |
| 56 |
this.insertResult(index, e); |
| 57 |
})); |
| 58 |
|
| 59 |
}, |
| 60 |
|
| 61 |
|
| 62 |
destroy: function(){ |
| 63 |
|
| 64 |
} |
| 65 |
}; |
| 66 |
}); |