datasource-debug.js revision 9593cd5be06a4d8436ea33c4ac3620c4c0243c91
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * The DataSource utility provides a common configurable interface for widgets to
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * access a variety of data, from JavaScript arrays to online database servers.
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @module datasource
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @requires base
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @title DataSource Utility
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * Base class for the YUI DataSource utility.
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @class DataSource
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @extends Base
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @constructor
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshDSLocal = function() {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh DSLocal.superclass.constructor.apply(this, arguments);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh /////////////////////////////////////////////////////////////////////////////
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // DataSource static properties
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh /////////////////////////////////////////////////////////////////////////////
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * Class name.
16a8c7d5e433b176636a4a1260c42ea43932110bKrzysztof Kosiński * @property DataSource.NAME
54e660c4de9d37185e3953165d053526632ef4f0johanengelen * @type String
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @value "DataSource.Local"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh /////////////////////////////////////////////////////////////////////////////
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // DataSource Attributes
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh /////////////////////////////////////////////////////////////////////////////
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @attribute source
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @description Pointer to live data.
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @type MIXED
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @default null
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * Global transaction counter.
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @property DataSource._tId
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib * @type Number
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @default 0
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * Executes a given callback. The third param determines whether to execute
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @method DataSource.issueCallback
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @param callback {Object} The callback object.
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @param params {Array} params to be passed to the callback method
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @param error {Boolean} whether an error occurred
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh callbackFunc = (response.error && response.callback.failure) || response.callback.success;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @property _queue
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @description Object literal to manage asynchronous request/response
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * cycles enabled if queue needs to be managed (asyncMode/xhrConnMode):
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh <dt>interval {Number}</dt>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh <dd>Interval ID of in-progress queue.</dd>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh <dt>conn</dt>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh <dd>In-progress connection identifier (if applicable).</dd>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh <dt>requests {Object[]}</dt>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh <dd>Array of queued request objects: {request:oRequest, callback:_xhrCallback}.</dd>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @type Object
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @default {interval:null, conn:null, requests:[]}
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @method initializer
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @description Internal init() handler.
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh initializer: function() {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh this._queue = {interval:null, conn:null, requests:[]};
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @method destructor
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @description Internal destroy() handler.
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh destructor: function() {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @method _createEvents
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @description This method creates all the events for this module
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * Target and publishes them so we get Event Bubbling.
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh _initEvents: function() {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * Fired when a data request is received.
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @event request
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @param e {Event.Facade} Event Facade.
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @param o {Object} Object with the following properties:
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * <dt>request (Object)</dt> <dd>The request.</dd>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * <dt>callback (Object)</dt> <dd>The callback object.</dd>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @preventable _defRequestFn
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh //this.publish("request", {defaultFn: this._defRequestFn});
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * Fired when raw data is received.
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @event data
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @param e {Event.Facade} Event Facade.
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @param o {Object} Object with the following properties:
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * <dt>request (Object)</dt> <dd>The request.</dd>
05a66d0771cb563225b8690de04e9490b35453f2johanengelen * <dt>callback (Object)</dt> <dd>The callback object.</dd>
05a66d0771cb563225b8690de04e9490b35453f2johanengelen * <dt>data (Object)</dt> <dd>The raw data.</dd>
05a66d0771cb563225b8690de04e9490b35453f2johanengelen * @preventable _defDataFn
05a66d0771cb563225b8690de04e9490b35453f2johanengelen //this.publish("data", {defaultFn: this._defDataFn});
05a66d0771cb563225b8690de04e9490b35453f2johanengelen this.publish("data", {defaultFn:function(e, o){
05a66d0771cb563225b8690de04e9490b35453f2johanengelen * Fired when response is returned.
05a66d0771cb563225b8690de04e9490b35453f2johanengelen * @event response
05a66d0771cb563225b8690de04e9490b35453f2johanengelen * @param e {Event.Facade} Event Facade.
05a66d0771cb563225b8690de04e9490b35453f2johanengelen * @param o {Object} Object with the following properties:
05a66d0771cb563225b8690de04e9490b35453f2johanengelen * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
05a66d0771cb563225b8690de04e9490b35453f2johanengelen * <dt>request (Object)</dt> <dd>The request.</dd>
05a66d0771cb563225b8690de04e9490b35453f2johanengelen * <dt>callback (Object)</dt> <dd>The callback object.</dd>
05a66d0771cb563225b8690de04e9490b35453f2johanengelen * <dt>data (Object)</dt> <dd>The raw data.</dd>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * <dt>results (Object)</dt> <dd>Parsed results.</dd>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * <dt>meta (Object)</dt> <dd>Parsed meta results data.</dd>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * <dt>error (Boolean)</dt> <dd>Error flag.</dd>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @preventable _defResponseFn
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh //this.publish("response", {defaultFn: this._defResponseFn});
7cc06cc17ffc875601993118f9533dfe36bd2dd5johanengelen * Fired when an error is encountered.
7cc06cc17ffc875601993118f9533dfe36bd2dd5johanengelen * @event error
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @param e {Event.Facade} Event Facade.
68b9e386db1a231abaddbfed4d05f7539bdac786scislac * @param o {Object} Object with the following properties:
68b9e386db1a231abaddbfed4d05f7539bdac786scislac * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
68b9e386db1a231abaddbfed4d05f7539bdac786scislac * <dt>request (Object)</dt> <dd>The request.</dd>
68b9e386db1a231abaddbfed4d05f7539bdac786scislac * <dt>callback (Object)</dt> <dd>The callback object.</dd>
68b9e386db1a231abaddbfed4d05f7539bdac786scislac * <dt>data (Object)</dt> <dd>The raw data (if available).</dd>
68b9e386db1a231abaddbfed4d05f7539bdac786scislac * <dt>results (Object)</dt> <dd>Parsed results (if available).</dd>
68b9e386db1a231abaddbfed4d05f7539bdac786scislac * <dt>meta (Object)</dt> <dd>Parsed meta results data (if available).</dd>
68b9e386db1a231abaddbfed4d05f7539bdac786scislac * <dt>error (Boolean)</dt> <dd>Error flag.</dd>
68b9e386db1a231abaddbfed4d05f7539bdac786scislac * Manages request/response transaction. Must fire <code>response</code>
68b9e386db1a231abaddbfed4d05f7539bdac786scislac * event when response is received. This method should be implemented by
68b9e386db1a231abaddbfed4d05f7539bdac786scislac * subclasses to achieve more complex behavior such as accessing remote data.
68b9e386db1a231abaddbfed4d05f7539bdac786scislac * @method _defRequestFn
68b9e386db1a231abaddbfed4d05f7539bdac786scislac * @param e {Event.Facade} Event Facade.
68b9e386db1a231abaddbfed4d05f7539bdac786scislac * @param o {Object} Object with the following properties:
e9b6af083e34e2397a8ddbe9781920733d09d151Ted Gould * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
05a66d0771cb563225b8690de04e9490b35453f2johanengelen * <dt>request (Object)</dt> <dd>The request.</dd>
e9b6af083e34e2397a8ddbe9781920733d09d151Ted Gould * <dt>callback (Object)</dt> <dd>The callback object.</dd>
e9b6af083e34e2397a8ddbe9781920733d09d151Ted Gould * @protected
05a66d0771cb563225b8690de04e9490b35453f2johanengelen _defRequestFn: function(e, o) {
05a66d0771cb563225b8690de04e9490b35453f2johanengelen // Problematic data
05a66d0771cb563225b8690de04e9490b35453f2johanengelen Y.log("Error in response", "error", this.toString());
05a66d0771cb563225b8690de04e9490b35453f2johanengelen this.fire("data", null, Y.mix(o, {data:data}));
7079a43aa387066c2f67402d77dbe3db981b1054Ted Gould Y.log("Transaction " + e.tId + " complete. Request: " +
05a66d0771cb563225b8690de04e9490b35453f2johanengelen Y.dump(o.request) + " . Response: " + Y.dump(o.response), "info", this.toString());
54e660c4de9d37185e3953165d053526632ef4f0johanengelen * Normalizes raw data into a response that includes results and meta properties.
05a66d0771cb563225b8690de04e9490b35453f2johanengelen * @method _defDataFn
05a66d0771cb563225b8690de04e9490b35453f2johanengelen * @param e {Event.Facade} Event Facade.
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @param o {Object} Object with the following properties:
68b9e386db1a231abaddbfed4d05f7539bdac786scislac * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
68b9e386db1a231abaddbfed4d05f7539bdac786scislac * <dt>request (Object)</dt> <dd>The request.</dd>
05a66d0771cb563225b8690de04e9490b35453f2johanengelen * <dt>callback (Object)</dt> <dd>The callback object.</dd>
05a66d0771cb563225b8690de04e9490b35453f2johanengelen * <dt>data (Object)</dt> <dd>The raw response data.</dd>
7079a43aa387066c2f67402d77dbe3db981b1054Ted Gould * @protected
7079a43aa387066c2f67402d77dbe3db981b1054Ted Gould _defDataFn: function(e, o) {
05a66d0771cb563225b8690de04e9490b35453f2johanengelen // Pass through data as-is
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // Normalize
68b9e386db1a231abaddbfed4d05f7539bdac786scislac * Sends data as a normalized response to callback.
68b9e386db1a231abaddbfed4d05f7539bdac786scislac * @method _defResponseFn
68b9e386db1a231abaddbfed4d05f7539bdac786scislac * @param e {Event.Facade} Event Facade.
68b9e386db1a231abaddbfed4d05f7539bdac786scislac * @param o {Object} Object with the following properties:
68b9e386db1a231abaddbfed4d05f7539bdac786scislac * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
68b9e386db1a231abaddbfed4d05f7539bdac786scislac * <dt>request (Object)</dt> <dd>The request.</dd>
68b9e386db1a231abaddbfed4d05f7539bdac786scislac * <dt>callback (Object)</dt> <dd>The callback object.</dd>
68b9e386db1a231abaddbfed4d05f7539bdac786scislac * <dt>data (Object)</dt> <dd>Raw data.</dd>
68b9e386db1a231abaddbfed4d05f7539bdac786scislac * <dt>results (Object)</dt> <dd>Parsed results.</dd>
68b9e386db1a231abaddbfed4d05f7539bdac786scislac * <dt>meta (Object)</dt> <dd>Parsed meta data.</dd>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @protected
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh _defResponseFn: function(e, o) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // Send the response back to the callback
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib * Generates a unique transaction ID and fires <code>request</code> event.
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @method sendRequest
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @param request {Object} Request.
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @param callback {Object} An object literal with the following properties:
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib * <dt><code>success</code></dt>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * <dd>The function to call when the data is ready.</dd>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * <dt><code>failure</code></dt>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * <dd>The function to call upon a response failure condition.</dd>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * <dt><code>scope</code></dt>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * <dd>The object to serve as the scope for the success and failure handlers.</dd>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * <dt><code>argument</code></dt>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * <dd>Arbitrary data payload that will be passed back to the success and failure handlers.</dd>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @return {Number} Transaction ID.
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh this.fire("request", null, {tId:tId, request:request,callback:callback});
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Y.log("Transaction " + tId + " sent request: " + Y.dump(request), "info", this.toString());
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * The DataSource utility provides a common configurable interface for widgets to
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * access a variety of data, from JavaScript arrays to online database servers.
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @module datasource-xhr
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @requires datasource-base
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @title DataSource XHR Submodule
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * XHR subclass for the YUI DataSource utility.
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @class DataSource.XHR
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @extends DataSource
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @constructor
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshvar DSXHR = function() {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh DSXHR.superclass.constructor.apply(this, arguments);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh /////////////////////////////////////////////////////////////////////////////
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // DataSource.XHR static properties
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh /////////////////////////////////////////////////////////////////////////////
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * Class name.
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @property DataSource.XHR.NAME
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @type String
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @value "DataSource.XHR"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh /////////////////////////////////////////////////////////////////////////////
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen // DataSource.XHR Attributes
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen /////////////////////////////////////////////////////////////////////////////
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * Pointer to IO Utility.
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @attribute io
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @type Y.io
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @default Y.io
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * Passes query string to IO. Fires <code>response</code> event when
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * response is received asynchronously.
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @method _defRequestFn
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @param e {Event.Facade} Event Facade.
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @param o {Object} Object with the following properties:
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * <dt>request (Object)</dt> <dd>The request.</dd>
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib * <dt>callback (Object)</dt> <dd>The callback object.</dd>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @protected
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh _defRequestFn: function(e, o) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Y.log("Received XHR data response for \"" + o.request + "\"", "info", this.toString());
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh //{tId:args.tId, request:args.request, callback:args.callback, response:response}
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh //this.handleResponse(args.tId, args.request, args.callback, response);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh this.fire("error", null, Y.mix(o, {data:response}));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Y.log("Received XHR data response for \"" + o.request + "\"", "info", this.toString());
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh //{tId:args.tId, request:args.request, callback:args.callback, response:response}
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh //this.handleResponse(args.tId, args.request, args.callback, response);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib * Extends DataSource with caching functionality.
861fa436e7a6d6ff3eaa889b2298e0b82a0b238ctheadib * @module datasource-cache
861fa436e7a6d6ff3eaa889b2298e0b82a0b238ctheadib * @requires plugin, datasource-base, cache
861fa436e7a6d6ff3eaa889b2298e0b82a0b238ctheadib * @title DataSource Cache Plugin
6c3e745a94ef6b25a4ef9f018d350a7535aa45afTed Gould * Adds cacheability to the YUI DataSource utility.
d5ad05ac17abfd7d2eae333a8c1233971e1c1a8fAbhishek Sharma Public * @class DataSourceCache
3bd80e038b72ad220f218d7053a9089685fab17cTed Gouldvar DataSourceCache = function() {
3bd80e038b72ad220f218d7053a9089685fab17cTed Gould DataSourceCache.superclass.constructor.apply(this, arguments);
479ed85bac2b7467a6678bae572404e33465a5d9acspike * The namespace for the plugin. This will be the property on the host which
63d6ddd517060979dd8b8fd41aad3faca7be3c5cTed Gould * references the plugin instance.
3bd80e038b72ad220f218d7053a9089685fab17cTed Gould * @property NS
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib * @type String
3bd80e038b72ad220f218d7053a9089685fab17cTed Gould * @value "cache"
63d6ddd517060979dd8b8fd41aad3faca7be3c5cTed Gould * Class name.
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib * @property DataParser.Base.NAME
45d0b0d0dc24df8e321cbe8a085ab9b1f60b4a42theadib * @type String
63d6ddd517060979dd8b8fd41aad3faca7be3c5cTed Gould * @value "DataSourceCache"
63d6ddd517060979dd8b8fd41aad3faca7be3c5cTed Gould /////////////////////////////////////////////////////////////////////////////
63d6ddd517060979dd8b8fd41aad3faca7be3c5cTed Gould // DataSourceCache Attributes
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib /////////////////////////////////////////////////////////////////////////////
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib * @method initializer
63d6ddd517060979dd8b8fd41aad3faca7be3c5cTed Gould * @description Internal init() handler.
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib this.doBefore("_defRequestFn", this._beforeDefRequestFn);
63d6ddd517060979dd8b8fd41aad3faca7be3c5cTed Gould this.doBefore("_defResponseFn", this._beforeDefResponseFn);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib * First look for cached response, then send request to live data.
63d6ddd517060979dd8b8fd41aad3faca7be3c5cTed Gould * @method _beforeDefRequestFn
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @param e {Event.Facade} Event Facade.
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @param o {Object} Object with the following properties:
1babefb17e4c8157ca2a0f588625a8ac0258dc53buliabyak * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
1babefb17e4c8157ca2a0f588625a8ac0258dc53buliabyak * <dt>request (Object)</dt> <dd>The request.</dd>
1babefb17e4c8157ca2a0f588625a8ac0258dc53buliabyak * <dt>callback (Object)</dt> <dd>The callback object.</dd>
45d0b0d0dc24df8e321cbe8a085ab9b1f60b4a42theadib * @protected
45d0b0d0dc24df8e321cbe8a085ab9b1f60b4a42theadib _beforeDefRequestFn: function(e, o) {
45d0b0d0dc24df8e321cbe8a085ab9b1f60b4a42theadib // Is response already in the Cache?
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh this._owner.fire("response", null, Y.mix(o, entry.response));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh return new Y.Do.Halt("DataSourceCache plugin halted _defRequestFn");
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh //BASE.issueCallback(entry.response);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh //return new Y.Do.Halt("msg", "newRetVal");
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * Adds data to cache before returning data.
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @method _beforeResponse
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @param e {Event.Facade} Event Facade.
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @param o {Object} Object with the following properties:
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * <dt>request (Object)</dt> <dd>The request.</dd>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * <dt>callback (Object)</dt> <dd>The callback object.</dd>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * <dt>data (Object)</dt> <dd>Raw data.</dd>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * <dt>results (Object)</dt> <dd>Parsed results.</dd>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * <dt>meta (Object)</dt> <dd>Parsed meta data.</dd>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @protected
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh _beforeDefResponseFn: function(e, o) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // Add to Cache before returning
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh this.add(o.request, o, (o.callback && o.callback.argument));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh}, '@VERSION@' ,{requires:['plugin', 'datasource-base', 'cache']});
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * Extends DataSource with schema-based JSON parsing functionality.
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @module datasource-jsonparser
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @requires plugin, datasource-base, dataparser-json
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @title DataSource JSONParser Plugin
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * Adds parsability to the YUI DataSource utility.
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @class DataSourceJSONParser
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshvar DataSourceJSONParser = function() {
e66a49aa774c6770e99591a19873105bfeb5ce74Johan Engelen DataSourceJSONParser.superclass.constructor.apply(this, arguments);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * The namespace for the plugin. This will be the property on the host which
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * references the plugin instance.
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @property NS
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @type String
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @value "cache"
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen * Class name.
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @property DataParser.Base.NAME
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @type String
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @value "DataSourceCache"
09ba3247163582bf2e30e17c4c154aa259ce038acilix /////////////////////////////////////////////////////////////////////////////
6825a6097da27fdfdf22859c0f81c208e7e22bb4Johan Engelen // DataSourceCache Attributes
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh /////////////////////////////////////////////////////////////////////////////
e9b6af083e34e2397a8ddbe9781920733d09d151Ted Gould * @method initializer
e9b6af083e34e2397a8ddbe9781920733d09d151Ted Gould * @description Internal init() handler.
e9b6af083e34e2397a8ddbe9781920733d09d151Ted Gould this.doBefore("_defDataFn", this._beforeDefDataFn);
16dc3cff4d07c7f5afdd8c74cf34530b0a6ee93btavmjong * Parses raw data into a normalized response.
e9b6af083e34e2397a8ddbe9781920733d09d151Ted Gould * @method _defDataFn
ddc1f1d1291eb21b244c7328d260c7d4a43be2fcbuliabyak * @param e {Event.Facade} Event Facade.
e9b6af083e34e2397a8ddbe9781920733d09d151Ted Gould * @param o {Object} Object with the following properties:
d703e5d08553a3dd5eb4f0a11040de79071bdcfbKrzysztof Kosiński * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
d703e5d08553a3dd5eb4f0a11040de79071bdcfbKrzysztof Kosiński * <dt>request (Object)</dt> <dd>The request.</dd>
d703e5d08553a3dd5eb4f0a11040de79071bdcfbKrzysztof Kosiński * <dt>callback (Object)</dt> <dd>The callback object.</dd>
d703e5d08553a3dd5eb4f0a11040de79071bdcfbKrzysztof Kosiński * <dt>data (Object)</dt> <dd>The raw response.</dd>
ddc1f1d1291eb21b244c7328d260c7d4a43be2fcbuliabyak _beforeDefDataFn: function(e, o) {
ddc1f1d1291eb21b244c7328d260c7d4a43be2fcbuliabyak var response = (this.get("parser").parse(this.get("schema"), o.data));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh this._owner.fire("response", null, Y.mix(o, response));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh return new Y.Do.Halt("DataSourceJSONParser plugin halted _defDataFn");
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshY.plugin.DataSourceJSONParser = DataSourceJSONParser;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh}, '@VERSION@' ,{requires:['plugin', 'datasource-base', 'dataparser-json']});
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen * Extends DataSource with polling functionality.
3955580a5a68a873b098921626f5b9d841b964ecjaspervdg * @module datasource-polling
3955580a5a68a873b098921626f5b9d841b964ecjaspervdg * @requires datasource-base
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @title DataSource Polling Extension
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * Adds polling to the YUI DataSource utility.
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @class Pollable
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Pollable = function() {};
bf7069a487ba218c4542e4adc5497ebd746ab929buliabyak * @property _intervals
bf7069a487ba218c4542e4adc5497ebd746ab929buliabyak * @description Array of polling interval IDs that have been enabled,
bf7069a487ba218c4542e4adc5497ebd746ab929buliabyak * stored here to be able to clear all intervals.
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * Sets up a polling mechanism to send requests at set intervals and forward
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * responses to given callback.
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @method setInterval
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @param msec {Number} Length of interval in milliseconds.
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @param request {Object} Request object.
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @param callback {Object} An object literal with the following properties:
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * <dt><code>success</code></dt>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * <dd>The function to call when the data is ready.</dd>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * <dt><code>failure</code></dt>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * <dd>The function to call upon a response failure condition.</dd>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * <dt><code>scope</code></dt>
63d6ddd517060979dd8b8fd41aad3faca7be3c5cTed Gould * <dd>The object to serve as the scope for the success and failure handlers.</dd>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * <dt><code>argument</code></dt>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * <dd>Arbitrary data that will be passed back to the success and failure handlers.</dd>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @return {Number} Interval ID.
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Y.log("Enabling polling to live data for \"" + Y.dump(request) + "\" at interval " + msec, "info", this.toString());
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh var self = this,
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh //self._makeConnection(request, callback);
533909ea7bb06d8f0658b7d448fa4283afd3f52ftavmjong Y.log("Could not enable polling to live data for \"" + Y.dump(request) + "\" at interval " + msec, "info", this.toString());
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * Disables polling mechanism associated with the given interval ID.
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @method clearInterval
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * @param id {Number} Interval ID.
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // Remove from tracker if there
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh for(; i>-1; i--) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshY.Base.build(Y.DataSource.Local.NAME, Y.DataSource.Local, [Pollable], {dynamic:false});
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshYUI.add('datasource', function(Y){}, '@VERSION@' ,{use:['datasource-base','datasource-xhr','datasource-cache','datasource-jsonparser','datasource-polling']});