Debian Codegraph @

dojox/mobile/_DataMixin.js

raw symbols SCIP
1 define([
2 "dojo/_base/kernel",
3 "dojo/_base/array",
4 "dojo/_base/declare",
5 "dojo/_base/lang",
6 "dojo/_base/Deferred"
7 ], function(kernel, array, declare, lang, Deferred){
8
9 // module:
10 // dojox/mobile/_DataMixin
11
12 kernel.deprecated("dojox/mobile/_DataMixin", "Use dojox/mobile/_StoreMixin instead", "2.0");
13
14 return declare("dojox.mobile._DataMixin", null, {
15 // summary:
16 // Mixin for widgets to enable dojo/data data store.
17 // description:
18 // By mixing this class into a widget, it can get data through a
19 // dojo/data data store. The widget must implement
20 // onComplete(/*Array*/items) to handle the retrieved data.
21
22 // store: Object
23 // Reference to data provider object used by this widget.
24 store: null,
25
26 // query: Object
27 // A query that can be passed to 'store' to initially filter the items.
28 query: null,
29
30 // queryOptions: Object
31 // An optional parameter for the query.
32 queryOptions: null,
33
34 setStore: function(/*dojo/data/store*/store, /*dojo/data/api/Request|Object*/query, /*Object?*/queryOptions){
35 // summary:
36 // Sets the store to use with this widget.
37 if(store === this.store){ return null; }
38 this.store = store;
39 this._setQuery(query, queryOptions);
40 if(store && store.getFeatures()["dojo.data.api.Notification"]){
41 array.forEach(this._conn || [], this.disconnect, this);
42 this._conn = [
43 this.connect(store, "onSet", "onSet"),
44 this.connect(store, "onNew", "onNew"),
45 this.connect(store, "onDelete", "onDelete"),
46 this.connect(store, "close", "onStoreClose")
47 ];
48 }
49 return this.refresh();
50 },
51
52 setQuery: function(/*dojo/data/api/Request|Object*/query, /*Object?*/queryOptions){
53 // summary:
54 // Sets a query.
55 this._setQuery(query, queryOptions);
56 return this.refresh();
57 },
58
59 _setQuery: function(query, queryOptions){
60 // tags:
61 // private
62 this.query = query;
63 this.queryOptions = queryOptions || this.queryOptions;
64 },
65
66 refresh: function(){
67 // summary:
68 // Fetches the data and generates the list items.
69 if(!this.store){ return null; }
70 var d = new Deferred();
71 var onComplete = lang.hitch(this, function(items, request){
72 this.onComplete(items, request);
73 d.resolve();
74 });
75 var onError = lang.hitch(this, function(errorData, request){
76 this.onError(errorData, request);
77 d.resolve();
78 });
79 var q = this.query;
80 this.store.fetch({
81 query: q,
82 queryOptions: this.queryOptions,
83 onComplete: onComplete,
84 onError: onError,
85 start: q && q.start,
86 count: q && q.count
87 });
88 return d;
89 }
90
91 /*
92 // Subclass MUST implement the following methods.
93
94 onComplete: function(items, request){
95 // summary:
96 // An handler that is called after the fetch completes.
97 },
98
99 onError: function(errorData, request){
100 // summary:
101 // An error handler.
102 },
103
104 onSet: function(item, attribute, oldValue, newValue){
105 // summary:
106 // See dojo/data/api/Notification.onSet()
107 },
108
109 onNew: function(newItem, parentInfo){
110 // summary:
111 // See dojo/data/api/Notification.onNew()
112 },
113
114 onDelete: function(deletedItem){
115 // summary:
116 // See dojo/data/api/Notification.onDelete()
117 },
118
119 onStoreClose: function(request){
120 // summary:
121 // Refresh list on close.
122 }
123 */
124 });
125 });