| 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 |
|
| 10 |
|
| 11 |
|
| 12 |
kernel.deprecated("dojox/mobile/_DataMixin", "Use dojox/mobile/_StoreMixin instead", "2.0"); |
| 13 |
|
| 14 |
return declare("dojox.mobile._DataMixin", null, { |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
store: null, |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
query: null, |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
queryOptions: null, |
| 33 |
|
| 34 |
setStore: function(store, query, queryOptions){ |
| 35 |
|
| 36 |
|
| 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(query, queryOptions){ |
| 53 |
|
| 54 |
|
| 55 |
this._setQuery(query, queryOptions); |
| 56 |
return this.refresh(); |
| 57 |
}, |
| 58 |
|
| 59 |
_setQuery: function(query, queryOptions){ |
| 60 |
|
| 61 |
|
| 62 |
this.query = query; |
| 63 |
this.queryOptions = queryOptions || this.queryOptions; |
| 64 |
}, |
| 65 |
|
| 66 |
refresh: function(){ |
| 67 |
|
| 68 |
|
| 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 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
}); |
| 125 |
}); |