Debian Codegraph @

dojox/mobile/_StoreListMixin.js

raw symbols SCIP
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 // module:
11 // dojox/mobile/_StoreListMixin
12
13 var _StoreListMixin = declare(has("dojo-bidi") ? "dojox.mobile._NonBidiStoreListMixin" : "dojox.mobile._StoreListMixin", StoreMixin, {
14 // summary:
15 // Mixin for widgets to generate the list items corresponding to
16 // the dojo/store data provider object.
17 // description:
18 // Mixin for widgets to generate the list items corresponding to
19 // the dojo/store data provider object.
20 // By mixing this class into the widgets, the list item nodes are
21 // generated as the child nodes of the widget and automatically
22 // regenerated whenever the corresponding data items are modified.
23
24 // append: Boolean
25 // If true, refresh() does not clear the existing items.
26 append: false,
27
28 // itemMap: Object
29 // An optional parameter mapping field names from the store to ItemList names.
30 // Example: itemMap:{text:'label', profile_image_url:'icon'}
31 itemMap: null,
32
33 // itemRenderer: ListItem class or subclass
34 // The class used to create list items. Default is dojox/mobile/ListItem.
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(/*Object*/item){
46 // summary:
47 // Creates a list item widget.
48 return new this.itemRenderer(this._createItemProperties(item));
49 },
50
51 _createItemProperties: function(/*Object*/item){
52 // summary:
53 // Creates list item properties.
54 var props = {};
55 if(!item["label"]){
56 props["label"] = item[this.labelProperty];
57 }
58 // TODO this code should be like for textDir in the bidi mixin createListItem method
59 // however for that dynamic set/get of the dir property must be supported first
60 // that is why for now as a workaround we keep the code here
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 // summary:
72 // Set the 'dir' attribute to support Mirroring.
73 // To be implemented by the bidi/_StoreLisMixin.js
74 return props;
75 },
76 generateList: function(/*Array*/items){
77 // summary:
78 // Given the data, generates a list of items.
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(/*Array*/items){
95 // summary:
96 // A handler that is called after the fetch completes.
97 this.generateList(items);
98 },
99
100 onError: function(/*Object*/ /*===== errorData =====*/){
101 // summary:
102 // An error handler.
103 },
104
105 onAdd: function(/*Object*/item, /*Number*/insertedInto){
106 // summary:
107 // Calls createListItem and adds the new list item when a new data item has been added to the store.
108 this.addChild(this.createListItem(item), insertedInto);
109 },
110
111 onUpdate: function(/*Object*/item, /*Number*/insertedInto){
112 // summary:
113 // Updates an existing list item when a data item has been modified.
114 this.getChildren()[insertedInto].set(this._createItemProperties(item));
115 },
116
117 onDelete: function(/*Object*/item, /*Number*/removedFrom){
118 // summary:
119 // Deletes an existing item.
120 this.getChildren()[removedFrom].destroyRecursive();
121 }
122 });
123 return has("dojo-bidi") ? declare("dojox.mobile._StoreListMixin", [_StoreListMixin, BidiStoreListMixin]) : _StoreListMixin;
124 });