datasource.js revision cfbefb0190a726e75555eb731e4b73a49573eff9
63fcfdd800e1773bb54462cff066db6a312a99bbJames PhillpottsYUI.add('datasource-local', function(Y) {
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts/**
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * The DataSource utility provides a common configurable interface for widgets to
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * access a variety of data, from JavaScript arrays to online database servers.
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts *
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * @module datasource
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts */
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpottsvar LANG = Y.Lang,
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts/**
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * Base class for the YUI DataSource utility.
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * @class DataSource.Local
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * @extends Base
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * @constructor
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts */
63fcfdd800e1773bb54462cff066db6a312a99bbJames PhillpottsDSLocal = function() {
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts DSLocal.superclass.constructor.apply(this, arguments);
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts};
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts /////////////////////////////////////////////////////////////////////////////
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts //
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts // DataSource static properties
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts //
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts /////////////////////////////////////////////////////////////////////////////
63fcfdd800e1773bb54462cff066db6a312a99bbJames PhillpottsY.mix(DSLocal, {
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts /**
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * Class name.
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts *
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * @property NAME
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * @type String
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * @static
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * @final
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * @value "dataSourceLocal"
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts */
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts NAME: "dataSourceLocal",
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts /////////////////////////////////////////////////////////////////////////////
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts //
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts // DataSource Attributes
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts //
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts /////////////////////////////////////////////////////////////////////////////
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts ATTRS: {
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna /**
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * @attribute source
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * @description Pointer to live data.
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * @type MIXED
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * @default null
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna */
608e02664686ce4f4ca3743d81a889d14142a222Andrew Forrest source: {
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts value: null
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts }
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts },
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts /**
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * Global transaction counter.
4d07f71d21aed86fc86bb8f7a047e4138d39c4f4James Phillpotts *
4d07f71d21aed86fc86bb8f7a047e4138d39c4f4James Phillpotts * @property DataSource._tId
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * @type Number
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * @static
4d07f71d21aed86fc86bb8f7a047e4138d39c4f4James Phillpotts * @private
4d07f71d21aed86fc86bb8f7a047e4138d39c4f4James Phillpotts * @default 0
4d07f71d21aed86fc86bb8f7a047e4138d39c4f4James Phillpotts */
4d07f71d21aed86fc86bb8f7a047e4138d39c4f4James Phillpotts _tId: 0,
4d07f71d21aed86fc86bb8f7a047e4138d39c4f4James Phillpotts
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna /**
4d07f71d21aed86fc86bb8f7a047e4138d39c4f4James Phillpotts * Executes a given callback. The third param determines whether to execute
4d07f71d21aed86fc86bb8f7a047e4138d39c4f4James Phillpotts *
4d07f71d21aed86fc86bb8f7a047e4138d39c4f4James Phillpotts * @method DataSource.issueCallback
4d07f71d21aed86fc86bb8f7a047e4138d39c4f4James Phillpotts * @param callback {Object} The callback object.
4d07f71d21aed86fc86bb8f7a047e4138d39c4f4James Phillpotts * @param params {Array} params to be passed to the callback method
4d07f71d21aed86fc86bb8f7a047e4138d39c4f4James Phillpotts * @param error {Boolean} whether an error occurred
4d07f71d21aed86fc86bb8f7a047e4138d39c4f4James Phillpotts * @static
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna */
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna issueCallback: function (e) {
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna if(e.callback) {
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna var callbackFunc = (e.error && e.callback.failure) || e.callback.success;
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna if (callbackFunc) {
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna callbackFunc(e);
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna }
4d07f71d21aed86fc86bb8f7a047e4138d39c4f4James Phillpotts }
4d07f71d21aed86fc86bb8f7a047e4138d39c4f4James Phillpotts }
4d07f71d21aed86fc86bb8f7a047e4138d39c4f4James Phillpotts});
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid LunaY.extend(DSLocal, Y.Base, {
4d07f71d21aed86fc86bb8f7a047e4138d39c4f4James Phillpotts /**
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * Internal init() handler.
19624c21a7388e51e52731151ffb20ddf6597bf7James Phillpotts *
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * @method initializer
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * @param config {Object} Config object.
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * @private
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna */
608e02664686ce4f4ca3743d81a889d14142a222Andrew Forrest initializer: function(config) {
b4bc0f6f0effcc65edf83eec1e8747d5fce55752David Luna this._initEvents();
608e02664686ce4f4ca3743d81a889d14142a222Andrew Forrest },
608e02664686ce4f4ca3743d81a889d14142a222Andrew Forrest
608e02664686ce4f4ca3743d81a889d14142a222Andrew Forrest /**
b4bc0f6f0effcc65edf83eec1e8747d5fce55752David Luna * This method creates all the events for this module.
608e02664686ce4f4ca3743d81a889d14142a222Andrew Forrest * @method _initEvents
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * @private
608e02664686ce4f4ca3743d81a889d14142a222Andrew Forrest */
b4bc0f6f0effcc65edf83eec1e8747d5fce55752David Luna _initEvents: function() {
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna /**
608e02664686ce4f4ca3743d81a889d14142a222Andrew Forrest * Fired when a data request is received.
b4bc0f6f0effcc65edf83eec1e8747d5fce55752David Luna *
b4bc0f6f0effcc65edf83eec1e8747d5fce55752David Luna * @event request
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * @param e {Event.Facade} Event Facade with the following properties:
b4bc0f6f0effcc65edf83eec1e8747d5fce55752David Luna * <dl>
b4bc0f6f0effcc65edf83eec1e8747d5fce55752David Luna * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * <dt>request (Object)</dt> <dd>The request.</dd>
b4bc0f6f0effcc65edf83eec1e8747d5fce55752David Luna * <dt>callback (Object)</dt> <dd>The callback object.</dd>
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * <dt>cfg (Object)</dt> <dd>Configuration object.</dd>
608e02664686ce4f4ca3743d81a889d14142a222Andrew Forrest * </dl>
b4bc0f6f0effcc65edf83eec1e8747d5fce55752David Luna * @preventable _defRequestFn
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna */
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna this.publish("request", {defaultFn: Y.bind("_defRequestFn", this), queuable:true});
b4bc0f6f0effcc65edf83eec1e8747d5fce55752David Luna
b4bc0f6f0effcc65edf83eec1e8747d5fce55752David Luna /**
608e02664686ce4f4ca3743d81a889d14142a222Andrew Forrest * Fired when raw data is received.
608e02664686ce4f4ca3743d81a889d14142a222Andrew Forrest *
608e02664686ce4f4ca3743d81a889d14142a222Andrew Forrest * @event data
608e02664686ce4f4ca3743d81a889d14142a222Andrew Forrest * @param e {Event.Facade} Event Facade with the following properties:
608e02664686ce4f4ca3743d81a889d14142a222Andrew Forrest * <dl>
608e02664686ce4f4ca3743d81a889d14142a222Andrew Forrest * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
608e02664686ce4f4ca3743d81a889d14142a222Andrew Forrest * <dt>request (Object)</dt> <dd>The request.</dd>
608e02664686ce4f4ca3743d81a889d14142a222Andrew Forrest * <dt>callback (Object)</dt> <dd>The callback object with the following properties:
608e02664686ce4f4ca3743d81a889d14142a222Andrew Forrest * <dl>
608e02664686ce4f4ca3743d81a889d14142a222Andrew Forrest * <dt>success (Function)</dt> <dd>Success handler.</dd>
608e02664686ce4f4ca3743d81a889d14142a222Andrew Forrest * <dt>failure (Function)</dt> <dd>Failure handler.</dd>
608e02664686ce4f4ca3743d81a889d14142a222Andrew Forrest * </dl>
608e02664686ce4f4ca3743d81a889d14142a222Andrew Forrest * </dd>
608e02664686ce4f4ca3743d81a889d14142a222Andrew Forrest * <dt>cfg (Object)</dt> <dd>Configuration object.</dd>
608e02664686ce4f4ca3743d81a889d14142a222Andrew Forrest * <dt>data (Object)</dt> <dd>Raw data.</dd>
608e02664686ce4f4ca3743d81a889d14142a222Andrew Forrest * </dl>
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * @preventable _defDataFn
608e02664686ce4f4ca3743d81a889d14142a222Andrew Forrest */
608e02664686ce4f4ca3743d81a889d14142a222Andrew Forrest this.publish("data", {defaultFn: Y.bind("_defDataFn", this), queuable:true});
608e02664686ce4f4ca3743d81a889d14142a222Andrew Forrest
608e02664686ce4f4ca3743d81a889d14142a222Andrew Forrest /**
608e02664686ce4f4ca3743d81a889d14142a222Andrew Forrest * Fired when response is returned.
608e02664686ce4f4ca3743d81a889d14142a222Andrew Forrest *
608e02664686ce4f4ca3743d81a889d14142a222Andrew Forrest * @event response
608e02664686ce4f4ca3743d81a889d14142a222Andrew Forrest * @param e {Event.Facade} Event Facade with the following properties:
608e02664686ce4f4ca3743d81a889d14142a222Andrew Forrest * <dl>
608e02664686ce4f4ca3743d81a889d14142a222Andrew Forrest * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
608e02664686ce4f4ca3743d81a889d14142a222Andrew Forrest * <dt>request (Object)</dt> <dd>The request.</dd>
608e02664686ce4f4ca3743d81a889d14142a222Andrew Forrest * <dt>callback (Object)</dt> <dd>The callback object with the following properties:
608e02664686ce4f4ca3743d81a889d14142a222Andrew Forrest * <dl>
608e02664686ce4f4ca3743d81a889d14142a222Andrew Forrest * <dt>success (Function)</dt> <dd>Success handler.</dd>
608e02664686ce4f4ca3743d81a889d14142a222Andrew Forrest * <dt>failure (Function)</dt> <dd>Failure handler.</dd>
d46a704b0f38f27472258f8a39b76f812155245fDavid Luna * </dl>
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * </dd>
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * <dt>cfg (Object)</dt> <dd>Configuration object.</dd>
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * <dt>data (Object)</dt> <dd>Raw data.</dd>
19624c21a7388e51e52731151ffb20ddf6597bf7James Phillpotts * <dt>response (Object)</dt> <dd>Normalized resopnse object with the following properties:
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * <dl>
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * <dt>results (Object)</dt> <dd>Parsed results.</dd>
608e02664686ce4f4ca3743d81a889d14142a222Andrew Forrest * <dt>meta (Object)</dt> <dd>Parsed meta data.</dd>
608e02664686ce4f4ca3743d81a889d14142a222Andrew Forrest * <dt>error (Boolean)</dt> <dd>Error flag.</dd>
608e02664686ce4f4ca3743d81a889d14142a222Andrew Forrest * </dl>
608e02664686ce4f4ca3743d81a889d14142a222Andrew Forrest * </dd>
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * </dl>
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * @preventable _defResponseFn
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna */
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna this.publish("response", {defaultFn: Y.bind("_defResponseFn", this), queuable:true});
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna /**
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * Fired when an error is encountered.
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna *
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * @event error
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * @param e {Event.Facade} Event Facade with the following properties:
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * <dl>
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * <dt>request (Object)</dt> <dd>The request.</dd>
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * <dt>callback (Object)</dt> <dd>The callback object with the following properties:
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * <dl>
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * <dt>success (Function)</dt> <dd>Success handler.</dd>
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * <dt>failure (Function)</dt> <dd>Failure handler.</dd>
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * </dl>
d46a704b0f38f27472258f8a39b76f812155245fDavid Luna * </dd>
d46a704b0f38f27472258f8a39b76f812155245fDavid Luna * <dt>cfg (Object)</dt> <dd>Configuration object.</dd>
d46a704b0f38f27472258f8a39b76f812155245fDavid Luna * <dt>data (Object)</dt> <dd>Raw data.</dd>
d46a704b0f38f27472258f8a39b76f812155245fDavid Luna * <dt>response (Object)</dt> <dd>Normalized resopnse object with the following properties:
d46a704b0f38f27472258f8a39b76f812155245fDavid Luna * <dl>
d46a704b0f38f27472258f8a39b76f812155245fDavid Luna * <dt>results (Object)</dt> <dd>Parsed results.</dd>
d46a704b0f38f27472258f8a39b76f812155245fDavid Luna * <dt>meta (Object)</dt> <dd>Parsed meta data.</dd>
b4bc0f6f0effcc65edf83eec1e8747d5fce55752David Luna * <dt>error (Object)</dt> <dd>Error object.</dd>
b4bc0f6f0effcc65edf83eec1e8747d5fce55752David Luna * </dl>
b4bc0f6f0effcc65edf83eec1e8747d5fce55752David Luna * </dd>
b4bc0f6f0effcc65edf83eec1e8747d5fce55752David Luna * </dl>
b4bc0f6f0effcc65edf83eec1e8747d5fce55752David Luna */
b4bc0f6f0effcc65edf83eec1e8747d5fce55752David Luna
b4bc0f6f0effcc65edf83eec1e8747d5fce55752David Luna },
b4bc0f6f0effcc65edf83eec1e8747d5fce55752David Luna
b4bc0f6f0effcc65edf83eec1e8747d5fce55752David Luna /**
19624c21a7388e51e52731151ffb20ddf6597bf7James Phillpotts * Manages request/response transaction. Must fire <code>response</code>
d46a704b0f38f27472258f8a39b76f812155245fDavid Luna * event when response is received. This method should be implemented by
b4bc0f6f0effcc65edf83eec1e8747d5fce55752David Luna * subclasses to achieve more complex behavior such as accessing remote data.
b4bc0f6f0effcc65edf83eec1e8747d5fce55752David Luna *
b4bc0f6f0effcc65edf83eec1e8747d5fce55752David Luna * @method _defRequestFn
b4bc0f6f0effcc65edf83eec1e8747d5fce55752David Luna * @param e {Event.Facade} Event Facadewith the following properties:
b4bc0f6f0effcc65edf83eec1e8747d5fce55752David Luna * <dl>
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * <dt>request (Object)</dt> <dd>The request.</dd>
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * <dt>callback (Object)</dt> <dd>The callback object with the following properties:
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * <dl>
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * <dt>success (Function)</dt> <dd>Success handler.</dd>
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * <dt>failure (Function)</dt> <dd>Failure handler.</dd>
19624c21a7388e51e52731151ffb20ddf6597bf7James Phillpotts * </dl>
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * </dd>
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * <dt>cfg (Object)</dt> <dd>Configuration object.</dd>
4d07f71d21aed86fc86bb8f7a047e4138d39c4f4James Phillpotts * </dl>
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * @protected
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna */
4d07f71d21aed86fc86bb8f7a047e4138d39c4f4James Phillpotts _defRequestFn: function(e) {
4d07f71d21aed86fc86bb8f7a047e4138d39c4f4James Phillpotts var data = this.get("source");
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna // Problematic data
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna if(LANG.isUndefined(data)) {
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna e.error = new Error("Local source undefined");
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna }
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna if(e.error) {
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna this.fire("error", e);
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna }
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna this.fire("data", Y.mix({data:data}, e));
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna },
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna /**
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * Normalizes raw data into a response that includes results and meta properties.
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna *
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * @method _defDataFn
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * @param e {Event.Facade} Event Facade with the following properties:
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * <dl>
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * <dt>request (Object)</dt> <dd>The request.</dd>
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * <dt>callback (Object)</dt> <dd>The callback object with the following properties:
4d07f71d21aed86fc86bb8f7a047e4138d39c4f4James Phillpotts * <dl>
4d07f71d21aed86fc86bb8f7a047e4138d39c4f4James Phillpotts * <dt>success (Function)</dt> <dd>Success handler.</dd>
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * <dt>failure (Function)</dt> <dd>Failure handler.</dd>
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * </dl>
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * </dd>
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * <dt>cfg (Object)</dt> <dd>Configuration object.</dd>
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * <dt>data (Object)</dt> <dd>Raw data.</dd>
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * </dl>
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * @protected
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna */
4d07f71d21aed86fc86bb8f7a047e4138d39c4f4James Phillpotts _defDataFn: function(e) {
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna var data = e.data,
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna meta = e.meta,
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna response = {
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna results: (LANG.isArray(data)) ? data : [data],
d46a704b0f38f27472258f8a39b76f812155245fDavid Luna meta: (meta) ? meta : {}
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna };
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna this.fire("response", Y.mix({response: response}, e));
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna },
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna
4d07f71d21aed86fc86bb8f7a047e4138d39c4f4James Phillpotts /**
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * Sends data as a normalized response to callback.
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna *
4d07f71d21aed86fc86bb8f7a047e4138d39c4f4James Phillpotts * @method _defResponseFn
4d07f71d21aed86fc86bb8f7a047e4138d39c4f4James Phillpotts * @param e {Event.Facade} Event Facade with the following properties:
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * <dl>
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * <dt>request (Object)</dt> <dd>The request.</dd>
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * <dt>callback (Object)</dt> <dd>The callback object with the following properties:
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * <dl>
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * <dt>success (Function)</dt> <dd>Success handler.</dd>
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * <dt>failure (Function)</dt> <dd>Failure handler.</dd>
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * </dl>
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * </dd>
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * <dt>cfg (Object)</dt> <dd>Configuration object.</dd>
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * <dt>data (Object)</dt> <dd>Raw data.</dd>
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * <dt>response (Object)</dt> <dd>Normalized resopnse object with the following properties:
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * <dl>
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * <dt>results (Object)</dt> <dd>Parsed results.</dd>
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * <dt>meta (Object)</dt> <dd>Parsed meta data.</dd>
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * <dt>error (Boolean)</dt> <dd>Error flag.</dd>
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * </dl>
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * </dd>
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * </dl>
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * @protected
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts */
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts _defResponseFn: function(e) {
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts // Send the response back to the callback
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts DSLocal.issueCallback(e);
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts },
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts /**
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * Generates a unique transaction ID and fires <code>request</code> event.
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts *
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * @method sendRequest
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * @param request {Object} Request.
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * @param callback {Object} An object literal with the following properties:
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * <dl>
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * <dt><code>success</code></dt>
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * <dd>The function to call when the data is ready.</dd>
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * <dt><code>failure</code></dt>
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * <dd>The function to call upon a response failure condition.</dd>
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * <dt><code>argument</code></dt>
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * <dd>Arbitrary data payload that will be passed back to the success and failure handlers.</dd>
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * </dl>
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * @param cfg {Object} Configuration object
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * @return {Number} Transaction ID.
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts */
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts sendRequest: function(request, callback, cfg) {
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts var tId = DSLocal._tId++;
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts this.fire("request", {tId:tId, request:request, callback:callback, cfg:cfg || {}});
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts return tId;
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts }
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts});
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts
63fcfdd800e1773bb54462cff066db6a312a99bbJames PhillpottsY.namespace("DataSource").Local = DSLocal;
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts}, '@VERSION@' ,{requires:['base']});
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts
63fcfdd800e1773bb54462cff066db6a312a99bbJames PhillpottsYUI.add('datasource-xhr', function(Y) {
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts/**
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * The DataSource utility provides a common configurable interface for widgets to
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * access a variety of data, from JavaScript arrays to online database servers.
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts *
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * @module datasource
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts */
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts/**
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * XHR subclass for the YUI DataSource utility.
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * @class DataSource.XHR
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * @extends DataSource.Local
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * @constructor
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts */
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpottsvar DSXHR = function() {
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts DSXHR.superclass.constructor.apply(this, arguments);
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts};
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts /////////////////////////////////////////////////////////////////////////////
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts //
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts // DataSource.XHR static properties
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts //
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts /////////////////////////////////////////////////////////////////////////////
63fcfdd800e1773bb54462cff066db6a312a99bbJames PhillpottsY.mix(DSXHR, {
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts /**
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * Class name.
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts *
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * @property NAME
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * @type String
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * @static
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * @final
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna * @value "dataSourceXHR"
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna */
c4329510051cce0c6b3efc1fae122ec4c5d61efaDavid Luna NAME: "dataSourceXHR",
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts /////////////////////////////////////////////////////////////////////////////
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts //
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts // DataSource.XHR Attributes
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts //
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts /////////////////////////////////////////////////////////////////////////////
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts ATTRS: {
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts /**
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * Pointer to IO Utility.
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts *
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * @attribute io
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * @type Y.io
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * @default Y.io
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts */
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts io: {
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts value: Y.io,
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts cloneDefaultValue: false
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts }
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts }
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts});
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts
63fcfdd800e1773bb54462cff066db6a312a99bbJames PhillpottsY.extend(DSXHR, Y.DataSource.Local, {
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts /**
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * Internal init() handler.
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts *
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * @method initializer
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * @param config {Object} Config object.
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * @private
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts */
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts initializer: function(config) {
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts this._queue = {interval:null, conn:null, requests:[]};
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts },
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts /**
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * @property _queue
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * @description Object literal to manage asynchronous request/response
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * cycles enabled if queue needs to be managed (asyncMode/xhrConnMode):
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * <dl>
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * <dt>interval {Number}</dt>
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * <dd>Interval ID of in-progress queue.</dd>
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * <dt>conn</dt>
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * <dd>In-progress connection identifier (if applicable).</dd>
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * <dt>requests {Object[]}</dt>
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * <dd>Array of queued request objects: {request:oRequest, callback:_xhrCallback}.</dd>
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * </dl>
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * @type Object
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * @default {interval:null, conn:null, requests:[]}
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * @private
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts */
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts _queue: null,
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts /**
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * Passes query string to IO. Fires <code>response</code> event when
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * response is received asynchronously.
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts *
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * @method _defRequestFn
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * @param e {Event.Facade} Event Facade with the following properties:
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * <dl>
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * <dt>request (Object)</dt> <dd>The request.</dd>
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * <dt>callback (Object)</dt> <dd>The callback object with the following properties:
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * <dl>
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * <dt>success (Function)</dt> <dd>Success handler.</dd>
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * <dt>failure (Function)</dt> <dd>Failure handler.</dd>
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * </dl>
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * </dd>
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * <dt>cfg (Object)</dt> <dd>Configuration object.</dd>
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * </dl>
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * @protected
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts */
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts _defRequestFn: function(e) {
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts var uri = this.get("source"),
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts cfg = Y.mix(e.cfg, {
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts on: {
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts success: function (id, response, e) {
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts this.fire("data", Y.mix({data:response}, e));
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts },
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts failure: function (id, response, e) {
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts e.error = new Error("XHR data failure");
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts this.fire("error", Y.mix({data:response}, e));
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts this.fire("data", Y.mix({data:response}, e));
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts }
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts },
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts context: this,
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts arguments: e
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts });
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts this.get("io")(uri, cfg);
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts return e.tId;
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts }
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts});
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts
63fcfdd800e1773bb54462cff066db6a312a99bbJames PhillpottsY.DataSource.XHR = DSXHR;
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts}, '@VERSION@' ,{requires:['datasource-local', 'io']});
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts
63fcfdd800e1773bb54462cff066db6a312a99bbJames PhillpottsYUI.add('datasource-scriptnode', function(Y) {
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts/**
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * The DataSource utility provides a common configurable interface for widgets to
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * access a variety of data, from JavaScript arrays to online database servers.
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts *
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * @module datasource
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts */
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts/**
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * Dynamic script node subclass for the YUI DataSource utility.
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * @class DataSource.ScriptNode
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * @extends DataSource.Local
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * @constructor
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts */
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpottsvar DSSN = function() {
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts DSSN.superclass.constructor.apply(this, arguments);
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts};
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts /////////////////////////////////////////////////////////////////////////////
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts //
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts // DataSource.ScriptNode static properties
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts //
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts /////////////////////////////////////////////////////////////////////////////
63fcfdd800e1773bb54462cff066db6a312a99bbJames PhillpottsY.mix(DSSN, {
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts /**
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * Class name.
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts *
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * @property NAME
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * @type String
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * @static
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * @final
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts * @value "dataSourceScriptNode"
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts */
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts NAME: "dataSourceScriptNode",
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts /////////////////////////////////////////////////////////////////////////////
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts //
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts // DataSource.ScriptNode Attributes
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts //
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts /////////////////////////////////////////////////////////////////////////////
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts ATTRS: {
63fcfdd800e1773bb54462cff066db6a312a99bbJames Phillpotts /**
* Pointer to Get Utility.
*
* @attribute get
* @type Y.Get
* @default Y.Get
*/
get: {
value: Y.Get,
cloneDefaultValue: false
},
/**
* Defines request/response management in the following manner:
* <dl>
* <!--<dt>queueRequests</dt>
* <dd>If a request is already in progress, wait until response is returned before sending the next request.</dd>
* <dt>cancelStaleRequests</dt>
* <dd>If a request is already in progress, cancel it before sending the next request.</dd>-->
* <dt>ignoreStaleResponses</dt>
* <dd>Send all requests, but handle only the response for the most recently sent request.</dd>
* <dt>allowAll</dt>
* <dd>Send all requests and handle all responses.</dd>
* </dl>
*
* @property asyncMode
* @type String
* @default "allowAll"
*/
asyncMode: {
value: "allowAll"
},
/**
* Callback string parameter name sent to the remote script. By default,
* requests are sent to
* &#60;URI&#62;?&#60;scriptCallbackParam&#62;=callbackFunction
*
* @property scriptCallbackParam
* @type String
* @default "callback"
*/
scriptCallbackParam : {
value: "callback"
},
/**
* Creates a request callback that gets appended to the script URI. Implementers
* can customize this string to match their server's query syntax.
*
* @method generateRequestCallback
* @return {String} String fragment that gets appended to script URI that
* specifies the callback function
*/
generateRequestCallback : {
value: function(self, id) {
return "&" + self.get("scriptCallbackParam") + "=YUI.Env.DataSource.callbacks["+id+"]" ;
}
}
},
/**
* Global array of callback functions, one for each request sent.
*
* @property callbacks
* @type Function[]
* @static
*/
callbacks : [],
/**
* Unique ID to track requests.
*
* @property _tId
* @type Number
* @private
* @static
*/
_tId : 0
});
Y.extend(DSSN, Y.DataSource.Local, {
/**
* Passes query string to Get Utility. Fires <code>response</code> event when
* response is received asynchronously.
*
* @method _defRequestFn
* @param e {Event.Facade} Event Facade with the following properties:
* <dl>
* <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
* <dt>request (Object)</dt> <dd>The request.</dd>
* <dt>callback (Object)</dt> <dd>The callback object with the following properties:
* <dl>
* <dt>success (Function)</dt> <dd>Success handler.</dd>
* <dt>failure (Function)</dt> <dd>Failure handler.</dd>
* </dl>
* </dd>
* <dt>cfg (Object)</dt> <dd>Configuration object.</dd>
* </dl>
* @protected
*/
_defRequestFn: function(e) {
var uri = this.get("source"),
get = this.get("get"),
id = DSSN._tId++,
self = this;
// Dynamically add handler function with a closure to the callback stack
YUI.Env.DataSource.callbacks[id] = Y.rbind(function(response) {
if((self.get("asyncMode") !== "ignoreStaleResponses")||
(id === DSSN.callbacks.length-1)) { // Must ignore stale responses
self.fire("data", Y.mix({data:response}, e));
}
else {
}
delete DSSN.callbacks[id];
}, this, id);
// We are now creating a request
uri += e.request + this.get("generateRequestCallback")(this, id);
//uri = this.doBeforeGetScriptNode(sUri);
get.script(uri, {
autopurge: true,
// Works in Firefox only....
onFailure: Y.bind(function(e) {
e.error = new Error("Script node data failure");
this.fire("error", e);
}, this, e)
});
return e.tId;
}
});
Y.DataSource.ScriptNode = DSSN;
YUI.namespace("Env.DataSource.callbacks");
}, '@VERSION@' ,{requires:['datasource-local', 'get']});
YUI.add('datasource-function', function(Y) {
/**
* The DataSource utility provides a common configurable interface for widgets to
* access a variety of data, from JavaScript arrays to online database servers.
*
* @module datasource
*/
var LANG = Y.Lang,
/**
* Function subclass for the YUI DataSource utility.
* @class DataSource.Function
* @extends DataSource.Local
* @constructor
*/
DSFn = function() {
DSFn.superclass.constructor.apply(this, arguments);
};
/////////////////////////////////////////////////////////////////////////////
//
// DataSource.Function static properties
//
/////////////////////////////////////////////////////////////////////////////
Y.mix(DSFn, {
/**
* Class name.
*
* @property NAME
* @type String
* @static
* @final
* @value "dataSourceFunction"
*/
NAME: "dataSourceFunction",
/////////////////////////////////////////////////////////////////////////////
//
// DataSource.Function Attributes
//
/////////////////////////////////////////////////////////////////////////////
ATTRS: {
/**
* @attribute source
* @description Pointer to live data.
* @type MIXED
* @default null
*/
source: {
validator: LANG.isFunction
}
}
});
Y.extend(DSFn, Y.DataSource.Local, {
/**
* Passes query string to IO. Fires <code>response</code> event when
* response is received asynchronously.
*
* @method _defRequestFn
* @param e {Event.Facade} Event Facade with the following properties:
* <dl>
* <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
* <dt>request (Object)</dt> <dd>The request.</dd>
* <dt>callback (Object)</dt> <dd>The callback object with the following properties:
* <dl>
* <dt>success (Function)</dt> <dd>Success handler.</dd>
* <dt>failure (Function)</dt> <dd>Failure handler.</dd>
* </dl>
* </dd>
* <dt>cfg (Object)</dt> <dd>Configuration object.</dd>
* </dl>
* @protected
*/
_defRequestFn: function(e) {
var fn = this.get("source"),
response;
if(fn) {
response = fn(e.request, this, e);
this.fire("data", Y.mix({data:response}, e));
}
else {
e.error = new Error("Function data failure");
this.fire("error", e);
}
return e.tId;
}
});
Y.DataSource.Function = DSFn;
}, '@VERSION@' ,{requires:['datasource-local']});
YUI.add('datasource-cache', function(Y) {
/**
* Extends DataSource with caching functionality.
*
* @module datasource
* @submodule datasource-cache
*/
/**
* Adds cacheability to the YUI DataSource utility.
* @class DataSourceCache
* @extends Cache
*/
var DataSourceCache = function() {
DataSourceCache.superclass.constructor.apply(this, arguments);
};
Y.mix(DataSourceCache, {
/**
* The namespace for the plugin. This will be the property on the host which
* references the plugin instance.
*
* @property NS
* @type String
* @static
* @final
* @value "cache"
*/
NS: "cache",
/**
* Class name.
*
* @property NAME
* @type String
* @static
* @final
* @value "dataSourceCache"
*/
NAME: "dataSourceCache",
/////////////////////////////////////////////////////////////////////////////
//
// DataSourceCache Attributes
//
/////////////////////////////////////////////////////////////////////////////
ATTRS: {
}
});
Y.extend(DataSourceCache, Y.Cache, {
/**
* Internal init() handler.
*
* @method initializer
* @param config {Object} Config object.
* @private
*/
initializer: function(config) {
this.doBefore("_defRequestFn", this._beforeDefRequestFn);
this.doBefore("_defResponseFn", this._beforeDefResponseFn);
},
/**
* First look for cached response, then send request to live data.
*
* @method _beforeDefRequestFn
* @param e {Event.Facade} Event Facade with the following properties:
* <dl>
* <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
* <dt>request (Object)</dt> <dd>The request.</dd>
* <dt>callback (Object)</dt> <dd>The callback object.</dd>
* <dt>cfg (Object)</dt> <dd>Configuration object.</dd>
* </dl>
* @protected
*/
_beforeDefRequestFn: function(e) {
// Is response already in the Cache?
var entry = (this.retrieve(e.request)) || null;
if(entry && entry.response) {
this.get("host").fire("response", Y.mix({response: entry.response}, e));
return new Y.Do.Halt("DataSourceCache plugin halted _defRequestFn");
}
},
/**
* Adds data to cache before returning data.
*
* @method _beforeDefResponseFn
* @param e {Event.Facade} Event Facade with the following properties:
* <dl>
* <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
* <dt>request (Object)</dt> <dd>The request.</dd>
* <dt>callback (Object)</dt> <dd>The callback object with the following properties:
* <dl>
* <dt>success (Function)</dt> <dd>Success handler.</dd>
* <dt>failure (Function)</dt> <dd>Failure handler.</dd>
* </dl>
* </dd>
* <dt>data (Object)</dt> <dd>Raw data.</dd>
* <dt>response (Object)</dt> <dd>Normalized resopnse object with the following properties:
* <dl>
* <dt>results (Object)</dt> <dd>Parsed results.</dd>
* <dt>meta (Object)</dt> <dd>Parsed meta data.</dd>
* <dt>error (Object)</dt> <dd>Error object.</dd>
* </dl>
* </dd>
* <dt>cfg (Object)</dt> <dd>Configuration object.</dd>
* </dl>
* @protected
*/
_beforeDefResponseFn: function(e) {
// Add to Cache before returning
this.add(e.request, e.response, (e.callback && e.callback.argument));
}
});
Y.namespace('Plugin').DataSourceCache = DataSourceCache;
}, '@VERSION@' ,{requires:['datasource-local', 'cache']});
YUI.add('datasource-jsonschema', function(Y) {
/**
* Extends DataSource with schema-parsing on JSON data.
*
* @module datasource
* @submodule datasource-jsonschema
*/
/**
* Adds schema-parsing to the YUI DataSource utility.
* @class DataSourceJSONSchema
* @extends Plugin
*/
var DataSourceJSONSchema = function() {
DataSourceJSONSchema.superclass.constructor.apply(this, arguments);
};
Y.mix(DataSourceJSONSchema, {
/**
* The namespace for the plugin. This will be the property on the host which
* references the plugin instance.
*
* @property NS
* @type String
* @static
* @final
* @value "schema"
*/
NS: "schema",
/**
* Class name.
*
* @property NAME
* @type String
* @static
* @final
* @value "dataSourceJSONSchema"
*/
NAME: "dataSourceJSONSchema",
/////////////////////////////////////////////////////////////////////////////
//
// DataSourceJSONSchema Attributes
//
/////////////////////////////////////////////////////////////////////////////
ATTRS: {
schema: {
//value: {}
}
}
});
Y.extend(DataSourceJSONSchema, Y.Plugin.Base, {
/**
* Internal init() handler.
*
* @method initializer
* @param config {Object} Config object.
* @private
*/
initializer: function(config) {
this.doBefore("_defDataFn", this._beforeDefDataFn);
},
/**
* Parses raw data into a normalized response.
*
* @method _beforeDefDataFn
* <dl>
* <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
* <dt>request (Object)</dt> <dd>The request.</dd>
* <dt>callback (Object)</dt> <dd>The callback object with the following properties:
* <dl>
* <dt>success (Function)</dt> <dd>Success handler.</dd>
* <dt>failure (Function)</dt> <dd>Failure handler.</dd>
* </dl>
* </dd>
* <dt>data (Object)</dt> <dd>Raw data.</dd>
* </dl>
* @protected
*/
_beforeDefDataFn: function(e) {
var data = (Y.DataSource.XHR && (this.get("host") instanceof Y.DataSource.XHR) && Y.Lang.isString(e.data.responseText)) ? e.data.responseText : e.data,
response = Y.DataSchema.JSON.apply(this.get("schema"), data);
// Default
if(!response) {
response = {
meta: {},
results: data
};
}
this.get("host").fire("response", Y.mix({response:response}, e));
return new Y.Do.Halt("DataSourceJSONSchema plugin halted _defDataFn");
}
});
Y.namespace('Plugin').DataSourceJSONSchema = DataSourceJSONSchema;
}, '@VERSION@' ,{requires:['plugin', 'datasource-local', 'dataschema-json']});
YUI.add('datasource-xmlschema', function(Y) {
/**
* Extends DataSource with schema-parsing on XML data.
*
* @module datasource
* @submodule datasource-xmlschema
*/
/**
* Adds schema-parsing to the YUI DataSource utility.
* @class DataSourceXMLSchema
* @extends Plugin
*/
var DataSourceXMLSchema = function() {
DataSourceXMLSchema.superclass.constructor.apply(this, arguments);
};
Y.mix(DataSourceXMLSchema, {
/**
* The namespace for the plugin. This will be the property on the host which
* references the plugin instance.
*
* @property NS
* @type String
* @static
* @final
* @value "schema"
*/
NS: "schema",
/**
* Class name.
*
* @property NAME
* @type String
* @static
* @final
* @value "dataSourceXMLSchema"
*/
NAME: "dataSourceXMLSchema",
/////////////////////////////////////////////////////////////////////////////
//
// DataSourceXMLSchema Attributes
//
/////////////////////////////////////////////////////////////////////////////
ATTRS: {
schema: {
//value: {}
}
}
});
Y.extend(DataSourceXMLSchema, Y.Plugin.Base, {
/**
* Internal init() handler.
*
* @method initializer
* @param config {Object} Config object.
* @private
*/
initializer: function(config) {
this.doBefore("_defDataFn", this._beforeDefDataFn);
},
/**
* Parses raw data into a normalized response.
*
* @method _beforeDefDataFn
* <dl>
* <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
* <dt>request (Object)</dt> <dd>The request.</dd>
* <dt>callback (Object)</dt> <dd>The callback object with the following properties:
* <dl>
* <dt>success (Function)</dt> <dd>Success handler.</dd>
* <dt>failure (Function)</dt> <dd>Failure handler.</dd>
* </dl>
* </dd>
* <dt>data (Object)</dt> <dd>Raw data.</dd>
* </dl>
* @protected
*/
_beforeDefDataFn: function(e) {
var data = (Y.DataSource.XHR && (this.get("host") instanceof Y.DataSource.XHR) && e.data.responseXML && (e.data.responseXML.nodeType === 9)) ? e.data.responseXML : e.data,
response = Y.DataSchema.XML.apply(this.get("schema"), data);
// Default
if(!response) {
response = {
meta: {},
results: data
};
}
this.get("host").fire("response", Y.mix({response:response}, e));
return new Y.Do.Halt("DataSourceXMLSchema plugin halted _defDataFn");
}
});
Y.namespace('Plugin').DataSourceXMLSchema = DataSourceXMLSchema;
}, '@VERSION@' ,{requires:['plugin', 'datasource-local', 'dataschema-xml']});
YUI.add('datasource-arrayschema', function(Y) {
/**
* Extends DataSource with schema-parsing on array data.
*
* @module datasource
* @submodule datasource-arrayschema
*/
/**
* Adds schema-parsing to the YUI DataSource utility.
* @class DataSourceArraySchema
* @extends Plugin
*/
var DataSourceArraySchema = function() {
DataSourceArraySchema.superclass.constructor.apply(this, arguments);
};
Y.mix(DataSourceArraySchema, {
/**
* The namespace for the plugin. This will be the property on the host which
* references the plugin instance.
*
* @property NS
* @type String
* @static
* @final
* @value "schema"
*/
NS: "schema",
/**
* Class name.
*
* @property NAME
* @type String
* @static
* @final
* @value "dataSourceArraySchema"
*/
NAME: "dataSourceArraySchema",
/////////////////////////////////////////////////////////////////////////////
//
// DataSourceArraySchema Attributes
//
/////////////////////////////////////////////////////////////////////////////
ATTRS: {
schema: {
//value: {}
}
}
});
Y.extend(DataSourceArraySchema, Y.Plugin.Base, {
/**
* Internal init() handler.
*
* @method initializer
* @param config {Object} Config object.
* @private
*/
initializer: function(config) {
this.doBefore("_defDataFn", this._beforeDefDataFn);
},
/**
* Parses raw data into a normalized response.
*
* @method _beforeDefDataFn
* <dl>
* <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
* <dt>request (Object)</dt> <dd>The request.</dd>
* <dt>callback (Object)</dt> <dd>The callback object with the following properties:
* <dl>
* <dt>success (Function)</dt> <dd>Success handler.</dd>
* <dt>failure (Function)</dt> <dd>Failure handler.</dd>
* </dl>
* </dd>
* <dt>data (Object)</dt> <dd>Raw data.</dd>
* </dl>
* @protected
*/
_beforeDefDataFn: function(e) {
var data = ((this.get("host") instanceof Y.DataSource.XHR) && Y.Lang.isString(e.data.responseText)) ? e.data.responseText : e.data,
response = Y.DataSchema.Array.apply(this.get("schema"), data);
// Default
if(!response) {
response = {
meta: {},
results: data
};
}
this.get("host").fire("response", Y.mix({response:response}, e));
return new Y.Do.Halt("DataSourceArraySchema plugin halted _defDataFn");
}
});
Y.namespace('Plugin').DataSourceArraySchema = DataSourceArraySchema;
}, '@VERSION@' ,{requires:['plugin', 'datasource-local', 'dataschema-array']});
YUI.add('datasource-textschema', function(Y) {
/**
* Extends DataSource with schema-parsing on text data.
*
* @module datasource
* @submodule datasource-textschema
*/
/**
* Adds schema-parsing to the YUI DataSource utility.
* @class DataSourceTextSchema
* @extends Plugin
*/
var DataSourceTextSchema = function() {
DataSourceTextSchema.superclass.constructor.apply(this, arguments);
};
Y.mix(DataSourceTextSchema, {
/**
* The namespace for the plugin. This will be the property on the host which
* references the plugin instance.
*
* @property NS
* @type String
* @static
* @final
* @value "schema"
*/
NS: "schema",
/**
* Class name.
*
* @property NAME
* @type String
* @static
* @final
* @value "dataSourceTextSchema"
*/
NAME: "dataSourceTextSchema",
/////////////////////////////////////////////////////////////////////////////
//
// DataSourceTextSchema Attributes
//
/////////////////////////////////////////////////////////////////////////////
ATTRS: {
schema: {
//value: {}
}
}
});
Y.extend(DataSourceTextSchema, Y.Plugin.Base, {
/**
* Internal init() handler.
*
* @method initializer
* @param config {Object} Config object.
* @private
*/
initializer: function(config) {
this.doBefore("_defDataFn", this._beforeDefDataFn);
},
/**
* Parses raw data into a normalized response.
*
* @method _beforeDefDataFn
* <dl>
* <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
* <dt>request (Object)</dt> <dd>The request.</dd>
* <dt>callback (Object)</dt> <dd>The callback object with the following properties:
* <dl>
* <dt>success (Function)</dt> <dd>Success handler.</dd>
* <dt>failure (Function)</dt> <dd>Failure handler.</dd>
* </dl>
* </dd>
* <dt>data (Object)</dt> <dd>Raw data.</dd>
* </dl>
* @protected
*/
_beforeDefDataFn: function(e) {
var data = (Y.DataSource.XHR && (this.get("host") instanceof Y.DataSource.XHR) && Y.Lang.isString(e.data.responseText)) ? e.data.responseText : e.data,
response = Y.DataSchema.Text.apply(this.get("schema"), data);
// Default
if(!response) {
response = {
meta: {},
results: data
};
}
this.get("host").fire("response", Y.mix({response:response}, e));
return new Y.Do.Halt("DataSourceTextSchema plugin halted _defDataFn");
}
});
Y.namespace('Plugin').DataSourceTextSchema = DataSourceTextSchema;
}, '@VERSION@' ,{requires:['plugin', 'datasource-local', 'dataschema-text']});
YUI.add('datasource-polling', function(Y) {
/**
* Extends DataSource with polling functionality.
*
* @module datasource
* @submodule datasource-polling
*/
var LANG = Y.Lang,
/**
* Adds polling to the YUI DataSource utility.
* @class Pollable
* @extends DataSource.Local
*/
Pollable = function() {
this._intervals = {};
};
Pollable.prototype = {
/**
* @property _intervals
* @description Hash of polling interval IDs that have been enabled,
* stored here to be able to clear all intervals.
* @private
*/
_intervals: null,
/**
* Sets up a polling mechanism to send requests at set intervals and forward
* responses to given callback.
*
* @method setInterval
* @param msec {Number} Length of interval in milliseconds.
* @param request {Object} Request object.
* @param callback {Object} An object literal with the following properties:
* <dl>
* <dt><code>success</code></dt>
* <dd>The function to call when the data is ready.</dd>
* <dt><code>failure</code></dt>
* <dd>The function to call upon a response failure condition.</dd>
* <dt><code>argument</code></dt>
* <dd>Arbitrary data that will be passed back to the success and failure handlers.</dd>
* </dl>
* @return {Number} Interval ID.
*/
setInterval: function(msec, request, callback) {
var x = Y.later(msec, this, this.sendRequest, [request, callback], true);
this._intervals[x.id] = x;
return x.id;
},
/**
* Disables polling mechanism associated with the given interval ID.
*
* @method clearInterval
* @param id {Number} Interval ID.
*/
clearInterval: function(id, key) {
// In case of being called by clearAllIntervals()
id = key || id;
if(this._intervals[id]) {
// Clear the interval
this._intervals[id].cancel();
// Clear from tracker
delete this._intervals[id];
}
},
/**
* Clears all intervals.
*
* @method clearAllIntervals
*/
clearAllIntervals: function() {
Y.each(this._intervals, this.clearInterval, this);
}
};
Y.augment(Y.DataSource.Local, Pollable);
}, '@VERSION@' ,{requires:['datasource-local']});
YUI.add('datasource', function(Y){}, '@VERSION@' ,{use:['datasource-local','datasource-xhr','datasource-scriptnode','datasource-function','datasource-cache','datasource-jsonschema','datasource-xmlschema','datasource-arrayschema','datasource-textschema','datasource-polling']});