Debian Codegraph @

dojox/mobile/_DataListMixin.js

raw symbols SCIP
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 // module:
12 // dojox/mobile/_DataListMixin
13
14 var _DataListMixin = declare(has("dojo-bidi") ? "dojox.mobile._NonBidiDataListMixin" : "dojox.mobile._DataListMixin", DataMixin, {
15 // summary:
16 // Mixin for widgets to generate the list items corresponding to
17 // the data provider object.
18 // description:
19 // By mixing this class into the widgets, the list item nodes are
20 // generated as the child nodes of the widget and automatically
21 // regenerated whenever the corresponding data items are modified.
22
23 // append: Boolean
24 // If true, refresh() does not clear the existing items.
25 append: false,
26
27 // itemMap: Object
28 // An optional parameter mapping field names from the store to ItemList name.
29 // example:
30 // | 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 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 // 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 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(/*Array*/items, /*Object*/dataObject){
69 // summary:
70 // Given the data, generates a list of items.
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(/*Array*/items, /*Object*/request){
82 // summary:
83 // An handler that is called after the fetch completes.
84 this.generateList(items, request);
85 },
86
87 onError: function(/*Object*/errorData, /*Object*/request){
88 // summary:
89 // An error handler.
90 },
91
92 onSet: function(/*Object*/item, /*String*/attribute, /*Object|Array*/oldValue, /*Object|Array*/newValue){
93 // summary:
94 // See dojo/data/api/Notification.onSet().
95 },
96
97 onNew: function(/*Object*/newItem, /*Object?*/parentInfo){
98 // summary:
99 // See dojo/data/api/Notification.onNew().
100 this.addChild(this.createListItem(newItem));
101 },
102
103 onDelete: function(/*Object*/deletedItem){
104 // summary:
105 // See dojo/data/api/Notification.onDelete().
106 registry.byId(deletedItem._widgetId).destroyRecursive();
107 },
108
109 onStoreClose: function(/*Object?*/request){
110 // summary:
111 // Refresh list on close.
112 if(this.store.clearOnClose){
113 this.refresh();
114 }
115 }
116 });
117 return has("dojo-bidi") ? declare("dojox.mobile._DataListMixin", [_DataListMixin, BidiDataListMixin]) : _DataListMixin;
118 });