2
YUI 3.10.3 (build 2fb5187)
3
Copyright 2013 Yahoo! Inc. All rights reserved.
4
Licensed under the BSD License.
5
http://yuilibrary.com/license/
8
YUI.add('datasource-get', function (Y, NAME) {
11
* Provides a DataSource implementation which can be used to retrieve data via the Get Utility.
14
* @submodule datasource-get
18
* Get Utility subclass for the DataSource Utility.
19
* @class DataSource.Get
20
* @extends DataSource.Local
23
var DSGet = function() {
24
DSGet.superclass.constructor.apply(this, arguments);
28
Y.DataSource.Get = Y.extend(DSGet, Y.DataSource.Local, {
30
* Passes query string to Get Utility. Fires <code>response</code> event when
31
* response is received asynchronously.
33
* @method _defRequestFn
34
* @param e {Event.Facade} Event Facade with the following properties:
36
* <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
37
* <dt>request (Object)</dt> <dd>The request.</dd>
38
* <dt>callback (Object)</dt> <dd>The callback object with the following properties:
40
* <dt>success (Function)</dt> <dd>Success handler.</dd>
41
* <dt>failure (Function)</dt> <dd>Failure handler.</dd>
44
* <dt>cfg (Object)</dt> <dd>Configuration object.</dd>
48
_defRequestFn: function(e) {
49
var uri = this.get("source"),
50
get = this.get("get"),
51
guid = Y.guid().replace(/\-/g, '_'),
52
generateRequest = this.get( "generateRequestCallback" ),
53
payload = e.details[0],
57
* Stores the most recent request id for validation against stale
66
// Dynamically add handler function with a closure to the callback stack
68
YUI.Env.DataSource.callbacks[guid] = function(response) {
69
delete YUI.Env.DataSource.callbacks[guid];
70
delete Y.DataSource.Local.transactions[e.tId];
72
var process = self.get('asyncMode') !== "ignoreStaleResponses" ||
76
payload.data = response;
78
self.fire("data", payload);
80
Y.log("DataSource ignored stale response for id " + e.tId + "(" + e.request + ")", "info", "datasource-get");
85
// Add the callback param to the request url
86
uri += e.request + generateRequest.call( this, guid );
88
Y.log("DataSource is querying URL " + uri, "info", "datasource-get");
90
Y.DataSource.Local.transactions[e.tId] = get.script(uri, {
92
// Works in Firefox only....
93
onFailure: function (o) {
94
delete YUI.Env.DataSource.callbacks[guid];
95
delete Y.DataSource.Local.transactions[e.tId];
97
payload.error = new Error(o.msg || "Script node data failure");
99
Y.log("Script node data failure", "error", "datasource-get");
101
self.fire("data", payload);
103
onTimeout: function(o) {
104
delete YUI.Env.DataSource.callbacks[guid];
105
delete Y.DataSource.Local.transactions[e.tId];
107
payload.error = new Error(o.msg || "Script node data timeout");
109
Y.log("Script node data timeout", "error", "datasource-get");
111
self.fire("data", payload);
120
* Default method for adding callback param to url. See
121
* generateRequestCallback attribute.
123
* @method _generateRequest
124
* @param guid {String} unique identifier for callback function wrapper
127
_generateRequest: function (guid) {
128
return "&" + this.get("scriptCallbackParam") +
129
"=YUI.Env.DataSource.callbacks." + guid;
141
* @value "dataSourceGet"
143
NAME: "dataSourceGet",
146
////////////////////////////////////////////////////////////////////////////
148
// DataSource.Get Attributes
150
////////////////////////////////////////////////////////////////////////////
153
* Pointer to Get Utility.
161
cloneDefaultValue: false
165
* Defines request/response management in the following manner:
167
* <!--<dt>queueRequests</dt>
168
* <dd>If a request is already in progress, wait until response is
169
* returned before sending the next request.</dd>
170
* <dt>cancelStaleRequests</dt>
171
* <dd>If a request is already in progress, cancel it before
172
* sending the next request.</dd>-->
173
* <dt>ignoreStaleResponses</dt>
174
* <dd>Send all requests, but handle only the response for the most
175
* recently sent request.</dd>
177
* <dd>Send all requests and handle all responses.</dd>
180
* @attribute asyncMode
182
* @default "allowAll"
189
* Callback string parameter name sent to the remote script. By default,
190
* requests are sent to
191
* <URI>?<scriptCallbackParam>=callbackFunction
193
* @attribute scriptCallbackParam
195
* @default "callback"
197
scriptCallbackParam : {
202
* Accepts the DataSource instance and a callback ID, and returns a callback
203
* param/value string that gets appended to the script URI. Implementers
204
* can customize this string to match their server's query syntax.
206
* @attribute generateRequestCallback
209
generateRequestCallback : {
211
return this._generateRequest.apply(this, arguments);
217
YUI.namespace("Env.DataSource.callbacks");
220
}, '3.10.3', {"requires": ["datasource-local", "get"]});