| 1 |
define([ |
| 2 |
"dojo/_base/array", |
| 3 |
"dojo/_base/declare", |
| 4 |
"./_StoreMixin", |
| 5 |
"./ListItem", |
| 6 |
"dojo/has", |
| 7 |
"dojo/has!dojo-bidi?dojox/mobile/bidi/_StoreListMixin" |
| 8 |
], function(array, declare, StoreMixin, ListItem, has, BidiStoreListMixin){ |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
var _StoreListMixin = declare(has("dojo-bidi") ? "dojox.mobile._NonBidiStoreListMixin" : "dojox.mobile._StoreListMixin", StoreMixin, { |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
append: false, |
| 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 |
return new this.itemRenderer(this._createItemProperties(item)); |
| 49 |
}, |
| 50 |
|
| 51 |
_createItemProperties: function(item){ |
| 52 |
|
| 53 |
|
| 54 |
var props = {}; |
| 55 |
if(!item["label"]){ |
| 56 |
props["label"] = item[this.labelProperty]; |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
if(has("dojo-bidi") && typeof props["dir"] == "undefined"){ |
| 62 |
props["dir"] = this.isLeftToRight() ? "ltr" : "rtl"; |
| 63 |
} |
| 64 |
for(var name in item){ |
| 65 |
props[(this.itemMap && this.itemMap[name]) || name] = item[name]; |
| 66 |
} |
| 67 |
return props; |
| 68 |
}, |
| 69 |
|
| 70 |
_setDirAttr: function(props){ |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
return props; |
| 75 |
}, |
| 76 |
generateList: function(items){ |
| 77 |
|
| 78 |
|
| 79 |
if(!this.append){ |
| 80 |
array.forEach(this.getChildren(), function(child){ |
| 81 |
child.destroyRecursive(); |
| 82 |
}); |
| 83 |
} |
| 84 |
array.forEach(items, function(item, index){ |
| 85 |
this.addChild(this.createListItem(item)); |
| 86 |
if(item[this.childrenProperty]){ |
| 87 |
array.forEach(item[this.childrenProperty], function(child, index){ |
| 88 |
this.addChild(this.createListItem(child)); |
| 89 |
}, this); |
| 90 |
} |
| 91 |
}, this); |
| 92 |
}, |
| 93 |
|
| 94 |
onComplete: function(items){ |
| 95 |
|
| 96 |
|
| 97 |
this.generateList(items); |
| 98 |
}, |
| 99 |
|
| 100 |
onError: function( ){ |
| 101 |
|
| 102 |
|
| 103 |
}, |
| 104 |
|
| 105 |
onAdd: function(item, insertedInto){ |
| 106 |
|
| 107 |
|
| 108 |
this.addChild(this.createListItem(item), insertedInto); |
| 109 |
}, |
| 110 |
|
| 111 |
onUpdate: function(item, insertedInto){ |
| 112 |
|
| 113 |
|
| 114 |
this.getChildren()[insertedInto].set(this._createItemProperties(item)); |
| 115 |
}, |
| 116 |
|
| 117 |
onDelete: function(item, removedFrom){ |
| 118 |
|
| 119 |
|
| 120 |
this.getChildren()[removedFrom].destroyRecursive(); |
| 121 |
} |
| 122 |
}); |
| 123 |
return has("dojo-bidi") ? declare("dojox.mobile._StoreListMixin", [_StoreListMixin, BidiStoreListMixin]) : _StoreListMixin; |
| 124 |
}); |