2 Copyright (c) 2009, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.net/yui/license.txt
8 YUI.add('datasource-local', function(Y) {
11 * The DataSource utility provides a common configurable interface for widgets to
12 * access a variety of data, from JavaScript arrays to online database servers.
18 * Provides the base DataSource implementation, which can be extended to
19 * create DataSources for specific data protocols, such as the IO Utility, the
20 * Get Utility, or custom functions.
23 * @submodule datasource-local
27 * Base class for the DataSource Utility.
28 * @class DataSource.Local
34 DSLocal = function() {
35 DSLocal.superclass.constructor.apply(this, arguments);
38 /////////////////////////////////////////////////////////////////////////////
40 // DataSource static properties
42 /////////////////////////////////////////////////////////////////////////////
51 * @value "dataSourceLocal"
53 NAME: "dataSourceLocal",
55 /////////////////////////////////////////////////////////////////////////////
57 // DataSource Attributes
59 /////////////////////////////////////////////////////////////////////////////
64 * @description Pointer to live data.
74 * Global transaction counter.
76 * @property DataSource._tId
85 * Executes a given callback. The third param determines whether to execute
87 * @method DataSource.issueCallback
88 * @param callback {Object} The callback object.
89 * @param params {Array} params to be passed to the callback method
90 * @param error {Boolean} whether an error occurred
93 issueCallback: function (e) {
95 var callbackFunc = (e.error && e.callback.failure) || e.callback.success;
103 Y.extend(DSLocal, Y.Base, {
105 * Internal init() handler.
107 * @method initializer
108 * @param config {Object} Config object.
111 initializer: function(config) {
116 * This method creates all the events for this module.
117 * @method _initEvents
120 _initEvents: function() {
122 * Fired when a data request is received.
125 * @param e {Event.Facade} Event Facade with the following properties:
127 * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
128 * <dt>request (Object)</dt> <dd>The request.</dd>
129 * <dt>callback (Object)</dt> <dd>The callback object.</dd>
130 * <dt>cfg (Object)</dt> <dd>Configuration object.</dd>
132 * @preventable _defRequestFn
134 this.publish("request", {defaultFn: Y.bind("_defRequestFn", this), queuable:true});
137 * Fired when raw data is received.
140 * @param e {Event.Facade} Event Facade with the following properties:
142 * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
143 * <dt>request (Object)</dt> <dd>The request.</dd>
144 * <dt>callback (Object)</dt> <dd>The callback object with the following properties:
146 * <dt>success (Function)</dt> <dd>Success handler.</dd>
147 * <dt>failure (Function)</dt> <dd>Failure handler.</dd>
150 * <dt>cfg (Object)</dt> <dd>Configuration object.</dd>
151 * <dt>data (Object)</dt> <dd>Raw data.</dd>
153 * @preventable _defDataFn
155 this.publish("data", {defaultFn: Y.bind("_defDataFn", this), queuable:true});
158 * Fired when response is returned.
161 * @param e {Event.Facade} Event Facade with the following properties:
163 * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
164 * <dt>request (Object)</dt> <dd>The request.</dd>
165 * <dt>callback (Object)</dt> <dd>The callback object with the following properties:
167 * <dt>success (Function)</dt> <dd>Success handler.</dd>
168 * <dt>failure (Function)</dt> <dd>Failure handler.</dd>
171 * <dt>cfg (Object)</dt> <dd>Configuration object.</dd>
172 * <dt>data (Object)</dt> <dd>Raw data.</dd>
173 * <dt>response (Object)</dt> <dd>Normalized response object with the following properties:
175 * <dt>results (Object)</dt> <dd>Parsed results.</dd>
176 * <dt>meta (Object)</dt> <dd>Parsed meta data.</dd>
177 * <dt>error (Boolean)</dt> <dd>Error flag.</dd>
181 * @preventable _defResponseFn
183 this.publish("response", {defaultFn: Y.bind("_defResponseFn", this), queuable:true});
186 * Fired when an error is encountered.
189 * @param e {Event.Facade} Event Facade with the following properties:
191 * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
192 * <dt>request (Object)</dt> <dd>The request.</dd>
193 * <dt>callback (Object)</dt> <dd>The callback object with the following properties:
195 * <dt>success (Function)</dt> <dd>Success handler.</dd>
196 * <dt>failure (Function)</dt> <dd>Failure handler.</dd>
199 * <dt>cfg (Object)</dt> <dd>Configuration object.</dd>
200 * <dt>data (Object)</dt> <dd>Raw data.</dd>
201 * <dt>response (Object)</dt> <dd>Normalized response object with the following properties:
203 * <dt>results (Object)</dt> <dd>Parsed results.</dd>
204 * <dt>meta (Object)</dt> <dd>Parsed meta data.</dd>
205 * <dt>error (Object)</dt> <dd>Error object.</dd>
214 * Manages request/response transaction. Must fire <code>response</code>
215 * event when response is received. This method should be implemented by
216 * subclasses to achieve more complex behavior such as accessing remote data.
218 * @method _defRequestFn
219 * @param e {Event.Facade} Event Facadewith the following properties:
221 * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
222 * <dt>request (Object)</dt> <dd>The request.</dd>
223 * <dt>callback (Object)</dt> <dd>The callback object with the following properties:
225 * <dt>success (Function)</dt> <dd>Success handler.</dd>
226 * <dt>failure (Function)</dt> <dd>Failure handler.</dd>
229 * <dt>cfg (Object)</dt> <dd>Configuration object.</dd>
233 _defRequestFn: function(e) {
234 var data = this.get("source");
237 if(LANG.isUndefined(data)) {
238 e.error = new Error("Local source undefined");
241 this.fire("error", e);
244 this.fire("data", Y.mix({data:data}, e));
248 * Normalizes raw data into a response that includes results and meta properties.
251 * @param e {Event.Facade} Event Facade with the following properties:
253 * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
254 * <dt>request (Object)</dt> <dd>The request.</dd>
255 * <dt>callback (Object)</dt> <dd>The callback object with the following properties:
257 * <dt>success (Function)</dt> <dd>Success handler.</dd>
258 * <dt>failure (Function)</dt> <dd>Failure handler.</dd>
261 * <dt>cfg (Object)</dt> <dd>Configuration object.</dd>
262 * <dt>data (Object)</dt> <dd>Raw data.</dd>
266 _defDataFn: function(e) {
270 results: (LANG.isArray(data)) ? data : [data],
271 meta: (meta) ? meta : {}
274 this.fire("response", Y.mix({response: response}, e));
278 * Sends data as a normalized response to callback.
280 * @method _defResponseFn
281 * @param e {Event.Facade} Event Facade with the following properties:
283 * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
284 * <dt>request (Object)</dt> <dd>The request.</dd>
285 * <dt>callback (Object)</dt> <dd>The callback object with the following properties:
287 * <dt>success (Function)</dt> <dd>Success handler.</dd>
288 * <dt>failure (Function)</dt> <dd>Failure handler.</dd>
291 * <dt>cfg (Object)</dt> <dd>Configuration object.</dd>
292 * <dt>data (Object)</dt> <dd>Raw data.</dd>
293 * <dt>response (Object)</dt> <dd>Normalized response object with the following properties:
295 * <dt>results (Object)</dt> <dd>Parsed results.</dd>
296 * <dt>meta (Object)</dt> <dd>Parsed meta data.</dd>
297 * <dt>error (Boolean)</dt> <dd>Error flag.</dd>
303 _defResponseFn: function(e) {
304 // Send the response back to the callback
305 DSLocal.issueCallback(e);
309 * Generates a unique transaction ID and fires <code>request</code> event.
311 * @method sendRequest
312 * @param request {Object} Request.
313 * @param callback {Object} An object literal with the following properties:
315 * <dt><code>success</code></dt>
316 * <dd>The function to call when the data is ready.</dd>
317 * <dt><code>failure</code></dt>
318 * <dd>The function to call upon a response failure condition.</dd>
319 * <dt><code>argument</code></dt>
320 * <dd>Arbitrary data payload that will be passed back to the success and failure handlers.</dd>
322 * @param cfg {Object} Configuration object
323 * @return {Number} Transaction ID.
325 sendRequest: function(request, callback, cfg) {
326 var tId = DSLocal._tId++;
327 this.fire("request", {tId:tId, request:request, callback:callback, cfg:cfg || {}});
332 Y.namespace("DataSource").Local = DSLocal;
336 }, '3.0.0' ,{requires:['base']});
338 YUI.add('datasource-io', function(Y) {
341 * Provides a DataSource implementation which can be used to retrieve data via the IO Utility.
344 * @submodule datasource-io
348 * IO subclass for the DataSource Utility.
349 * @class DataSource.IO
350 * @extends DataSource.Local
353 var DSIO = function() {
354 DSIO.superclass.constructor.apply(this, arguments);
358 /////////////////////////////////////////////////////////////////////////////
360 // DataSource.IO static properties
362 /////////////////////////////////////////////////////////////////////////////
371 * @value "dataSourceIO"
373 NAME: "dataSourceIO",
376 /////////////////////////////////////////////////////////////////////////////
378 // DataSource.IO Attributes
380 /////////////////////////////////////////////////////////////////////////////
384 * Pointer to IO Utility.
392 cloneDefaultValue: false
397 Y.extend(DSIO, Y.DataSource.Local, {
399 * Internal init() handler.
401 * @method initializer
402 * @param config {Object} Config object.
405 initializer: function(config) {
406 this._queue = {interval:null, conn:null, requests:[]};
411 * @description Object literal to manage asynchronous request/response
412 * cycles enabled if queue needs to be managed (asyncMode/ioConnMode):
414 * <dt>interval {Number}</dt>
415 * <dd>Interval ID of in-progress queue.</dd>
417 * <dd>In-progress connection identifier (if applicable).</dd>
418 * <dt>requests {Object[]}</dt>
419 * <dd>Array of queued request objects: {request:request, callback:callback}.</dd>
422 * @default {interval:null, conn:null, requests:[]}
428 * Passes query string to IO. Fires <code>response</code> event when
429 * response is received asynchronously.
431 * @method _defRequestFn
432 * @param e {Event.Facade} Event Facade with the following properties:
434 * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
435 * <dt>request (Object)</dt> <dd>The request.</dd>
436 * <dt>callback (Object)</dt> <dd>The callback object with the following properties:
438 * <dt>success (Function)</dt> <dd>Success handler.</dd>
439 * <dt>failure (Function)</dt> <dd>Failure handler.</dd>
442 * <dt>cfg (Object)</dt> <dd>Configuration object.</dd>
446 _defRequestFn: function(e) {
447 var uri = this.get("source"),
452 success: function (id, response, e) {
453 this.fire("data", Y.mix({data:response}, e));
455 failure: function (id, response, e) {
456 e.error = new Error("IO data failure");
457 this.fire("error", Y.mix({data:response}, e));
458 this.fire("data", Y.mix({data:response}, e));
465 // Support for POST transactions
466 if(Y.Lang.isString(request)) {
467 if(cfg.method && (cfg.method.toUpperCase() === "POST")) {
468 cfg.data = cfg.data ? cfg.data+request : request;
479 Y.DataSource.IO = DSIO;
484 }, '3.0.0' ,{requires:['datasource-local', 'io']});
486 YUI.add('datasource-get', function(Y) {
489 * Provides a DataSource implementation which can be used to retrieve data via the Get Utility.
492 * @submodule datasource-get
496 * Get Utility subclass for the DataSource Utility.
497 * @class DataSource.Get
498 * @extends DataSource.Local
501 var DSGet = function() {
502 DSGet.superclass.constructor.apply(this, arguments);
506 /////////////////////////////////////////////////////////////////////////////
508 // DataSource.Get static properties
510 /////////////////////////////////////////////////////////////////////////////
519 * @value "dataSourceGet"
521 NAME: "dataSourceGet",
524 /////////////////////////////////////////////////////////////////////////////
526 // DataSource.Get Attributes
528 /////////////////////////////////////////////////////////////////////////////
532 * Pointer to Get Utility.
540 cloneDefaultValue: false
544 * Defines request/response management in the following manner:
546 * <!--<dt>queueRequests</dt>
547 * <dd>If a request is already in progress, wait until response is returned before sending the next request.</dd>
548 * <dt>cancelStaleRequests</dt>
549 * <dd>If a request is already in progress, cancel it before sending the next request.</dd>-->
550 * <dt>ignoreStaleResponses</dt>
551 * <dd>Send all requests, but handle only the response for the most recently sent request.</dd>
553 * <dd>Send all requests and handle all responses.</dd>
556 * @attribute asyncMode
558 * @default "allowAll"
565 * Callback string parameter name sent to the remote script. By default,
566 * requests are sent to
567 * <URI>?<scriptCallbackParam>=callbackFunction
569 * @attribute scriptCallbackParam
571 * @default "callback"
573 scriptCallbackParam : {
578 * Accepts the DataSource instance and a callback ID, and returns a callback
579 * param/value string that gets appended to the script URI. Implementers
580 * can customize this string to match their server's query syntax.
582 * @attribute generateRequestCallback
585 generateRequestCallback : {
586 value: function(self, id) {
587 return "&" + self.get("scriptCallbackParam") + "=YUI.Env.DataSource.callbacks["+id+"]" ;
598 * Global array of callback functions, one for each request sent.
600 * @property callbacks
607 * Unique ID to track requests.
617 Y.extend(DSGet, Y.DataSource.Local, {
619 * Passes query string to Get Utility. Fires <code>response</code> event when
620 * response is received asynchronously.
622 * @method _defRequestFn
623 * @param e {Event.Facade} Event Facade with the following properties:
625 * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
626 * <dt>request (Object)</dt> <dd>The request.</dd>
627 * <dt>callback (Object)</dt> <dd>The callback object with the following properties:
629 * <dt>success (Function)</dt> <dd>Success handler.</dd>
630 * <dt>failure (Function)</dt> <dd>Failure handler.</dd>
633 * <dt>cfg (Object)</dt> <dd>Configuration object.</dd>
637 _defRequestFn: function(e) {
638 var uri = this.get("source"),
639 get = this.get("get"),
655 // Dynamically add handler function with a closure to the callback stack
656 YUI.Env.DataSource.callbacks[id] = Y.rbind(function(response) {
657 if((self.get("asyncMode") !== "ignoreStaleResponses")||
658 (id === DSGet.callbacks.length-1)) { // Must ignore stale responses
660 self.fire("data", Y.mix({data:response}, e));
665 delete DSGet.callbacks[id];
668 // We are now creating a request
669 uri += e.request + this.get("generateRequestCallback")(this, id);
670 //uri = this.doBefore(sUri);
673 // Works in Firefox only....
674 onFailure: Y.bind(function(e) {
675 e.error = new Error("Script node data failure");
676 this.fire("error", e);
698 Y.DataSource.Get = DSGet;
699 YUI.namespace("Env.DataSource.callbacks");
704 }, '3.0.0' ,{requires:['datasource-local', 'get']});
706 YUI.add('datasource-function', function(Y) {
709 * Provides a DataSource implementation which can be used to retrieve data from a custom function.
712 * @submodule datasource-function
716 * Function subclass for the DataSource Utility.
717 * @class DataSource.Function
718 * @extends DataSource.Local
724 DSFn.superclass.constructor.apply(this, arguments);
728 /////////////////////////////////////////////////////////////////////////////
730 // DataSource.Function static properties
732 /////////////////////////////////////////////////////////////////////////////
741 * @value "dataSourceFunction"
743 NAME: "dataSourceFunction",
746 /////////////////////////////////////////////////////////////////////////////
748 // DataSource.Function Attributes
750 /////////////////////////////////////////////////////////////////////////////
755 * @description Pointer to live data.
760 validator: LANG.isFunction
765 Y.extend(DSFn, Y.DataSource.Local, {
767 * Passes query string to IO. Fires <code>response</code> event when
768 * response is received asynchronously.
770 * @method _defRequestFn
771 * @param e {Event.Facade} Event Facade with the following properties:
773 * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
774 * <dt>request (Object)</dt> <dd>The request.</dd>
775 * <dt>callback (Object)</dt> <dd>The callback object with the following properties:
777 * <dt>success (Function)</dt> <dd>Success handler.</dd>
778 * <dt>failure (Function)</dt> <dd>Failure handler.</dd>
781 * <dt>cfg (Object)</dt> <dd>Configuration object.</dd>
785 _defRequestFn: function(e) {
786 var fn = this.get("source"),
791 response = fn(e.request, this, e);
792 this.fire("data", Y.mix({data:response}, e));
796 this.fire("error", e);
800 e.error = new Error("Function data failure");
801 this.fire("error", e);
808 Y.DataSource.Function = DSFn;
813 }, '3.0.0' ,{requires:['datasource-local']});
815 YUI.add('datasource-cache', function(Y) {
818 * Extends DataSource with caching functionality.
821 * @submodule datasource-cache
825 * Adds cacheability to the DataSource Utility.
826 * @class DataSourceCache
829 var DataSourceCache = function() {
830 DataSourceCache.superclass.constructor.apply(this, arguments);
833 Y.mix(DataSourceCache, {
835 * The namespace for the plugin. This will be the property on the host which
836 * references the plugin instance.
853 * @value "dataSourceCache"
855 NAME: "dataSourceCache",
857 /////////////////////////////////////////////////////////////////////////////
859 // DataSourceCache Attributes
861 /////////////////////////////////////////////////////////////////////////////
868 Y.extend(DataSourceCache, Y.Cache, {
870 * Internal init() handler.
872 * @method initializer
873 * @param config {Object} Config object.
876 initializer: function(config) {
877 this.doBefore("_defRequestFn", this._beforeDefRequestFn);
878 this.doBefore("_defResponseFn", this._beforeDefResponseFn);
882 * First look for cached response, then send request to live data.
884 * @method _beforeDefRequestFn
885 * @param e {Event.Facade} Event Facade with the following properties:
887 * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
888 * <dt>request (Object)</dt> <dd>The request.</dd>
889 * <dt>callback (Object)</dt> <dd>The callback object.</dd>
890 * <dt>cfg (Object)</dt> <dd>Configuration object.</dd>
894 _beforeDefRequestFn: function(e) {
895 // Is response already in the Cache?
896 var entry = (this.retrieve(e.request)) || null;
897 if(entry && entry.response) {
898 this.get("host").fire("response", Y.mix({response: entry.response}, e));
899 return new Y.Do.Halt("DataSourceCache plugin halted _defRequestFn");
904 * Adds data to cache before returning data.
906 * @method _beforeDefResponseFn
907 * @param e {Event.Facade} Event Facade with the following properties:
909 * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
910 * <dt>request (Object)</dt> <dd>The request.</dd>
911 * <dt>callback (Object)</dt> <dd>The callback object with the following properties:
913 * <dt>success (Function)</dt> <dd>Success handler.</dd>
914 * <dt>failure (Function)</dt> <dd>Failure handler.</dd>
917 * <dt>data (Object)</dt> <dd>Raw data.</dd>
918 * <dt>response (Object)</dt> <dd>Normalized response object with the following properties:
920 * <dt>cached (Object)</dt> <dd>True when response is cached.</dd>
921 * <dt>results (Object)</dt> <dd>Parsed results.</dd>
922 * <dt>meta (Object)</dt> <dd>Parsed meta data.</dd>
923 * <dt>error (Object)</dt> <dd>Error object.</dd>
926 * <dt>cfg (Object)</dt> <dd>Configuration object.</dd>
930 _beforeDefResponseFn: function(e) {
931 // Add to Cache before returning
932 if(e.response && !e.response.cached) {
933 e.response.cached = true;
934 this.add(e.request, e.response, (e.callback && e.callback.argument));
939 Y.namespace('Plugin').DataSourceCache = DataSourceCache;
943 }, '3.0.0' ,{requires:['datasource-local', 'cache']});
945 YUI.add('datasource-jsonschema', function(Y) {
948 * Extends DataSource with schema-parsing on JSON data.
951 * @submodule datasource-jsonschema
955 * Adds schema-parsing to the DataSource Utility.
956 * @class DataSourceJSONSchema
957 * @extends Plugin.Base
959 var DataSourceJSONSchema = function() {
960 DataSourceJSONSchema.superclass.constructor.apply(this, arguments);
963 Y.mix(DataSourceJSONSchema, {
965 * The namespace for the plugin. This will be the property on the host which
966 * references the plugin instance.
983 * @value "dataSourceJSONSchema"
985 NAME: "dataSourceJSONSchema",
987 /////////////////////////////////////////////////////////////////////////////
989 // DataSourceJSONSchema Attributes
991 /////////////////////////////////////////////////////////////////////////////
1000 Y.extend(DataSourceJSONSchema, Y.Plugin.Base, {
1002 * Internal init() handler.
1004 * @method initializer
1005 * @param config {Object} Config object.
1008 initializer: function(config) {
1009 this.doBefore("_defDataFn", this._beforeDefDataFn);
1013 * Parses raw data into a normalized response.
1015 * @method _beforeDefDataFn
1017 * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
1018 * <dt>request (Object)</dt> <dd>The request.</dd>
1019 * <dt>callback (Object)</dt> <dd>The callback object with the following properties:
1021 * <dt>success (Function)</dt> <dd>Success handler.</dd>
1022 * <dt>failure (Function)</dt> <dd>Failure handler.</dd>
1025 * <dt>data (Object)</dt> <dd>Raw data.</dd>
1029 _beforeDefDataFn: function(e) {
1030 var data = (Y.DataSource.IO && (this.get("host") instanceof Y.DataSource.IO) && Y.Lang.isString(e.data.responseText)) ? e.data.responseText : e.data,
1031 response = Y.DataSchema.JSON.apply(this.get("schema"), data);
1041 this.get("host").fire("response", Y.mix({response:response}, e));
1042 return new Y.Do.Halt("DataSourceJSONSchema plugin halted _defDataFn");
1046 Y.namespace('Plugin').DataSourceJSONSchema = DataSourceJSONSchema;
1050 }, '3.0.0' ,{requires:['plugin', 'datasource-local', 'dataschema-json']});
1052 YUI.add('datasource-xmlschema', function(Y) {
1055 * Extends DataSource with schema-parsing on XML data.
1057 * @module datasource
1058 * @submodule datasource-xmlschema
1062 * Adds schema-parsing to the DataSource Utility.
1063 * @class DataSourceXMLSchema
1064 * @extends Plugin.Base
1066 var DataSourceXMLSchema = function() {
1067 DataSourceXMLSchema.superclass.constructor.apply(this, arguments);
1070 Y.mix(DataSourceXMLSchema, {
1072 * The namespace for the plugin. This will be the property on the host which
1073 * references the plugin instance.
1090 * @value "dataSourceXMLSchema"
1092 NAME: "dataSourceXMLSchema",
1094 /////////////////////////////////////////////////////////////////////////////
1096 // DataSourceXMLSchema Attributes
1098 /////////////////////////////////////////////////////////////////////////////
1107 Y.extend(DataSourceXMLSchema, Y.Plugin.Base, {
1109 * Internal init() handler.
1111 * @method initializer
1112 * @param config {Object} Config object.
1115 initializer: function(config) {
1116 this.doBefore("_defDataFn", this._beforeDefDataFn);
1120 * Parses raw data into a normalized response.
1122 * @method _beforeDefDataFn
1124 * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
1125 * <dt>request (Object)</dt> <dd>The request.</dd>
1126 * <dt>callback (Object)</dt> <dd>The callback object with the following properties:
1128 * <dt>success (Function)</dt> <dd>Success handler.</dd>
1129 * <dt>failure (Function)</dt> <dd>Failure handler.</dd>
1132 * <dt>data (Object)</dt> <dd>Raw data.</dd>
1136 _beforeDefDataFn: function(e) {
1137 var data = (Y.DataSource.IO && (this.get("host") instanceof Y.DataSource.IO) && e.data.responseXML && (e.data.responseXML.nodeType === 9)) ? e.data.responseXML : e.data,
1138 response = Y.DataSchema.XML.apply(this.get("schema"), data);
1148 this.get("host").fire("response", Y.mix({response:response}, e));
1149 return new Y.Do.Halt("DataSourceXMLSchema plugin halted _defDataFn");
1153 Y.namespace('Plugin').DataSourceXMLSchema = DataSourceXMLSchema;
1157 }, '3.0.0' ,{requires:['plugin', 'datasource-local', 'dataschema-xml']});
1159 YUI.add('datasource-arrayschema', function(Y) {
1162 * Extends DataSource with schema-parsing on array data.
1164 * @module datasource
1165 * @submodule datasource-arrayschema
1169 * Adds schema-parsing to the DataSource Utility.
1170 * @class DataSourceArraySchema
1171 * @extends Plugin.Base
1173 var DataSourceArraySchema = function() {
1174 DataSourceArraySchema.superclass.constructor.apply(this, arguments);
1177 Y.mix(DataSourceArraySchema, {
1179 * The namespace for the plugin. This will be the property on the host which
1180 * references the plugin instance.
1197 * @value "dataSourceArraySchema"
1199 NAME: "dataSourceArraySchema",
1201 /////////////////////////////////////////////////////////////////////////////
1203 // DataSourceArraySchema Attributes
1205 /////////////////////////////////////////////////////////////////////////////
1214 Y.extend(DataSourceArraySchema, Y.Plugin.Base, {
1216 * Internal init() handler.
1218 * @method initializer
1219 * @param config {Object} Config object.
1222 initializer: function(config) {
1223 this.doBefore("_defDataFn", this._beforeDefDataFn);
1227 * Parses raw data into a normalized response.
1229 * @method _beforeDefDataFn
1231 * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
1232 * <dt>request (Object)</dt> <dd>The request.</dd>
1233 * <dt>callback (Object)</dt> <dd>The callback object with the following properties:
1235 * <dt>success (Function)</dt> <dd>Success handler.</dd>
1236 * <dt>failure (Function)</dt> <dd>Failure handler.</dd>
1239 * <dt>data (Object)</dt> <dd>Raw data.</dd>
1243 _beforeDefDataFn: function(e) {
1244 var data = (Y.DataSource.IO && (this.get("host") instanceof Y.DataSource.IO) && Y.Lang.isString(e.data.responseText)) ? e.data.responseText : e.data,
1245 response = Y.DataSchema.Array.apply(this.get("schema"), data);
1255 this.get("host").fire("response", Y.mix({response:response}, e));
1256 return new Y.Do.Halt("DataSourceArraySchema plugin halted _defDataFn");
1260 Y.namespace('Plugin').DataSourceArraySchema = DataSourceArraySchema;
1264 }, '3.0.0' ,{requires:['plugin', 'datasource-local', 'dataschema-array']});
1266 YUI.add('datasource-textschema', function(Y) {
1269 * Extends DataSource with schema-parsing on text data.
1271 * @module datasource
1272 * @submodule datasource-textschema
1276 * Adds schema-parsing to the DataSource Utility.
1277 * @class DataSourceTextSchema
1278 * @extends Plugin.Base
1280 var DataSourceTextSchema = function() {
1281 DataSourceTextSchema.superclass.constructor.apply(this, arguments);
1284 Y.mix(DataSourceTextSchema, {
1286 * The namespace for the plugin. This will be the property on the host which
1287 * references the plugin instance.
1304 * @value "dataSourceTextSchema"
1306 NAME: "dataSourceTextSchema",
1308 /////////////////////////////////////////////////////////////////////////////
1310 // DataSourceTextSchema Attributes
1312 /////////////////////////////////////////////////////////////////////////////
1321 Y.extend(DataSourceTextSchema, Y.Plugin.Base, {
1323 * Internal init() handler.
1325 * @method initializer
1326 * @param config {Object} Config object.
1329 initializer: function(config) {
1330 this.doBefore("_defDataFn", this._beforeDefDataFn);
1334 * Parses raw data into a normalized response.
1336 * @method _beforeDefDataFn
1338 * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
1339 * <dt>request (Object)</dt> <dd>The request.</dd>
1340 * <dt>callback (Object)</dt> <dd>The callback object with the following properties:
1342 * <dt>success (Function)</dt> <dd>Success handler.</dd>
1343 * <dt>failure (Function)</dt> <dd>Failure handler.</dd>
1346 * <dt>data (Object)</dt> <dd>Raw data.</dd>
1350 _beforeDefDataFn: function(e) {
1351 var data = (Y.DataSource.IO && (this.get("host") instanceof Y.DataSource.IO) && Y.Lang.isString(e.data.responseText)) ? e.data.responseText : e.data,
1352 response = Y.DataSchema.Text.apply(this.get("schema"), data);
1362 this.get("host").fire("response", Y.mix({response:response}, e));
1363 return new Y.Do.Halt("DataSourceTextSchema plugin halted _defDataFn");
1367 Y.namespace('Plugin').DataSourceTextSchema = DataSourceTextSchema;
1371 }, '3.0.0' ,{requires:['plugin', 'datasource-local', 'dataschema-text']});
1373 YUI.add('datasource-polling', function(Y) {
1376 * Extends DataSource with polling functionality.
1378 * @module datasource
1379 * @submodule datasource-polling
1383 * Adds polling to the DataSource Utility.
1385 * @extends DataSource.Local
1389 Pollable = function() {
1390 this._intervals = {};
1393 Pollable.prototype = {
1396 * @property _intervals
1397 * @description Hash of polling interval IDs that have been enabled,
1398 * stored here to be able to clear all intervals.
1404 * Sets up a polling mechanism to send requests at set intervals and forward
1405 * responses to given callback.
1407 * @method setInterval
1408 * @param msec {Number} Length of interval in milliseconds.
1409 * @param request {Object} Request object.
1410 * @param callback {Object} An object literal with the following properties:
1412 * <dt><code>success</code></dt>
1413 * <dd>The function to call when the data is ready.</dd>
1414 * <dt><code>failure</code></dt>
1415 * <dd>The function to call upon a response failure condition.</dd>
1416 * <dt><code>argument</code></dt>
1417 * <dd>Arbitrary data that will be passed back to the success and failure handlers.</dd>
1419 * @return {Number} Interval ID.
1421 setInterval: function(msec, request, callback) {
1422 var x = Y.later(msec, this, this.sendRequest, [request, callback], true);
1423 this._intervals[x.id] = x;
1428 * Disables polling mechanism associated with the given interval ID.
1430 * @method clearInterval
1431 * @param id {Number} Interval ID.
1433 clearInterval: function(id, key) {
1434 // In case of being called by clearAllIntervals()
1436 if(this._intervals[id]) {
1437 // Clear the interval
1438 this._intervals[id].cancel();
1439 // Clear from tracker
1440 delete this._intervals[id];
1445 * Clears all intervals.
1447 * @method clearAllIntervals
1449 clearAllIntervals: function() {
1450 Y.each(this._intervals, this.clearInterval, this);
1454 Y.augment(Y.DataSource.Local, Pollable);
1458 }, '3.0.0' ,{requires:['datasource-local']});
1462 YUI.add('datasource', function(Y){}, '3.0.0' ,{use:['datasource-local','datasource-io','datasource-get','datasource-function','datasource-cache','datasource-jsonschema','datasource-xmlschema','datasource-arrayschema','datasource-textschema','datasource-polling']});