| 1 |
define([ |
| 2 |
"dojo/_base/array", |
| 3 |
"dojo/_base/declare", |
| 4 |
"dijit/registry", |
| 5 |
"./_DataMixin", |
| 6 |
"./ListItem", |
| 7 |
"dojo/has", |
| 8 |
"dojo/has!dojo-bidi?dojox/mobile/bidi/_StoreListMixin" |
| 9 |
], function(array, declare, registry, DataMixin, ListItem, has, BidiDataListMixin){ |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
var _DataListMixin = declare(has("dojo-bidi") ? "dojox.mobile._NonBidiDataListMixin" : "dojox.mobile._DataListMixin", DataMixin, { |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
append: false, |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
itemMap: null, |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
itemRenderer: ListItem, |
| 36 |
|
| 37 |
buildRendering: function(){ |
| 38 |
this.inherited(arguments); |
| 39 |
if(!this.store){ return; } |
| 40 |
var store = this.store; |
| 41 |
this.store = null; |
| 42 |
this.setStore(store, this.query, this.queryOptions); |
| 43 |
}, |
| 44 |
|
| 45 |
createListItem: function(item){ |
| 46 |
|
| 47 |
|
| 48 |
var attr = {}; |
| 49 |
var arr = this.store.getLabelAttributes(item); |
| 50 |
var labelAttr = arr ? arr[0] : null; |
| 51 |
array.forEach(this.store.getAttributes(item), function(name){ |
| 52 |
if(name === labelAttr){ |
| 53 |
attr["label"] = this.store.getLabel(item); |
| 54 |
}else{ |
| 55 |
attr[(this.itemMap && this.itemMap[name]) || name] = this.store.getValue(item, name); |
| 56 |
} |
| 57 |
}, this); |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
if(has("dojo-bidi") && typeof attr["dir"] == "undefined"){ |
| 62 |
attr["dir"] = this.isLeftToRight() ? "ltr" : "rtl"; |
| 63 |
} |
| 64 |
var w = new this.itemRenderer(attr); |
| 65 |
item._widgetId = w.id; |
| 66 |
return w; |
| 67 |
}, |
| 68 |
generateList: function(items, dataObject){ |
| 69 |
|
| 70 |
|
| 71 |
if(!this.append){ |
| 72 |
array.forEach(this.getChildren(), function(child){ |
| 73 |
child.destroyRecursive(); |
| 74 |
}); |
| 75 |
} |
| 76 |
array.forEach(items, function(item, index){ |
| 77 |
this.addChild(this.createListItem(item)); |
| 78 |
}, this); |
| 79 |
}, |
| 80 |
|
| 81 |
onComplete: function(items, request){ |
| 82 |
|
| 83 |
|
| 84 |
this.generateList(items, request); |
| 85 |
}, |
| 86 |
|
| 87 |
onError: function(errorData, request){ |
| 88 |
|
| 89 |
|
| 90 |
}, |
| 91 |
|
| 92 |
onSet: function(item, attribute, oldValue, newValue){ |
| 93 |
|
| 94 |
|
| 95 |
}, |
| 96 |
|
| 97 |
onNew: function(newItem, parentInfo){ |
| 98 |
|
| 99 |
|
| 100 |
this.addChild(this.createListItem(newItem)); |
| 101 |
}, |
| 102 |
|
| 103 |
onDelete: function(deletedItem){ |
| 104 |
|
| 105 |
|
| 106 |
registry.byId(deletedItem._widgetId).destroyRecursive(); |
| 107 |
}, |
| 108 |
|
| 109 |
onStoreClose: function(request){ |
| 110 |
|
| 111 |
|
| 112 |
if(this.store.clearOnClose){ |
| 113 |
this.refresh(); |
| 114 |
} |
| 115 |
} |
| 116 |
}); |
| 117 |
return has("dojo-bidi") ? declare("dojox.mobile._DataListMixin", [_DataListMixin, BidiDataListMixin]) : _DataListMixin; |
| 118 |
}); |