datasource-debug.js revision 2fd0020b39d0935dd53b83d78bc7b3ca4007ed79
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek GathrightYUI.add('datasource-local', function(Y) {
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright/**
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * The DataSource utility provides a common configurable interface for widgets to
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * access a variety of data, from JavaScript arrays to online database servers.
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright *
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @module datasource
78ac1ef5c64e9e95a94bbfe859662da6d21b243aEric Ferraiuolo */
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathrightvar LANG = Y.Lang,
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright/**
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * Base class for the YUI DataSource utility.
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @class DataSource.Local
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @extends Base
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @constructor
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright */
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek GathrightDSLocal = function() {
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright DSLocal.superclass.constructor.apply(this, arguments);
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright};
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright /////////////////////////////////////////////////////////////////////////////
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright //
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright // DataSource static properties
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright //
a7e9ca67d735ae1bcdc1f7deb35ab98dd9c9f614Derek Gathright /////////////////////////////////////////////////////////////////////////////
78ac1ef5c64e9e95a94bbfe859662da6d21b243aEric FerraiuoloY.mix(DSLocal, {
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright /**
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright * Class name.
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright *
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @property NAME
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @type String
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @static
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @final
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @value "DataSource.Local"
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright */
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright NAME: "DataSource.Local",
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright
78ac1ef5c64e9e95a94bbfe859662da6d21b243aEric Ferraiuolo /////////////////////////////////////////////////////////////////////////////
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright //
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright // DataSource Attributes
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright //
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright /////////////////////////////////////////////////////////////////////////////
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright ATTRS: {
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright /**
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright * @attribute source
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @description Pointer to live data.
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @type MIXED
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @default null
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright */
78ac1ef5c64e9e95a94bbfe859662da6d21b243aEric Ferraiuolo source: {
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright value: null
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright }
78ac1ef5c64e9e95a94bbfe859662da6d21b243aEric Ferraiuolo },
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright /**
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * Global transaction counter.
f6eaca952977579049a77179dc827c5fc1d6c808Derek Gathright *
f6eaca952977579049a77179dc827c5fc1d6c808Derek Gathright * @property DataSource._tId
f6eaca952977579049a77179dc827c5fc1d6c808Derek Gathright * @type Number
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright * @static
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright * @private
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @default 0
f6eaca952977579049a77179dc827c5fc1d6c808Derek Gathright */
78ac1ef5c64e9e95a94bbfe859662da6d21b243aEric Ferraiuolo _tId: 0,
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright /**
f6eaca952977579049a77179dc827c5fc1d6c808Derek Gathright * Executes a given callback. The third param determines whether to execute
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright *
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright * @method DataSource.issueCallback
78ac1ef5c64e9e95a94bbfe859662da6d21b243aEric Ferraiuolo * @param callback {Object} The callback object.
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @param params {Array} params to be passed to the callback method
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @param error {Boolean} whether an error occurred
78ac1ef5c64e9e95a94bbfe859662da6d21b243aEric Ferraiuolo * @static
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright */
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright issueCallback: function (e) {
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright if(e.callback) {
f6eaca952977579049a77179dc827c5fc1d6c808Derek Gathright var scope = e.callback.scope || this,
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright callbackFunc = (e.error && e.callback.failure) || e.callback.success;
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright if (callbackFunc) {
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright callbackFunc.apply(scope, [e]);
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright }
78ac1ef5c64e9e95a94bbfe859662da6d21b243aEric Ferraiuolo }
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright }
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright});
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright
f6eaca952977579049a77179dc827c5fc1d6c808Derek GathrightY.extend(DSLocal, Y.Base, {
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright /**
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright * Internal init() handler.
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright *
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @method initializer
78ac1ef5c64e9e95a94bbfe859662da6d21b243aEric Ferraiuolo * @param config {Object} Config object.
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @private
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright */
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright initializer: function(config) {
f6eaca952977579049a77179dc827c5fc1d6c808Derek Gathright this._initEvents();
22084377ce30892c9fd181dada2d206969298e07Eric Ferraiuolo },
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright /**
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * Internal destroy() handler.
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright *
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @method destructor
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @private
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright */
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright destructor: function() {
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright },
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright /**
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * This method creates all the events for this module.
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @method _initEvents
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @private
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright */
78ac1ef5c64e9e95a94bbfe859662da6d21b243aEric Ferraiuolo _initEvents: function() {
78ac1ef5c64e9e95a94bbfe859662da6d21b243aEric Ferraiuolo /**
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * Fired when a data request is received.
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright *
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @event request
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @param e {Event.Facade} Event Facade.
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @param o {Object} Object with the following properties:
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dl>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dt>request (Object)</dt> <dd>The request.</dd>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dt>callback (Object)</dt> <dd>The callback object.</dd>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * </dl>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @preventable _defRequestFn
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright */
78ac1ef5c64e9e95a94bbfe859662da6d21b243aEric Ferraiuolo //this.publish("request", {defaultFn: this._defRequestFn});
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright //this.publish("request", {defaultFn:function(e){
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright // this._defRequestFn(e);
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright //}});
78ac1ef5c64e9e95a94bbfe859662da6d21b243aEric Ferraiuolo this.publish("request", {defaultFn: Y.bind("_defRequestFn", this)});
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright /**
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * Fired when raw data is received.
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright *
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright * @event data
78ac1ef5c64e9e95a94bbfe859662da6d21b243aEric Ferraiuolo * @param e {Event.Facade} Event Facade with the following properties:
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dl>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dt>request (Object)</dt> <dd>The request.</dd>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dt>callback (Object)</dt> <dd>The callback object with the following properties:
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dl>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dt>success (Function)</dt> <dd>Success handler.</dd>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dt>failure (Function)</dt> <dd>Failure handler.</dd>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dt>scope (Object)</dt> <dd>Execution context.</dd>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * </dl>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * </dd>
f6eaca952977579049a77179dc827c5fc1d6c808Derek Gathright * <dt>data (Object)</dt> <dd>Raw data.</dd>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * </dl>
78ac1ef5c64e9e95a94bbfe859662da6d21b243aEric Ferraiuolo * @preventable _defDataFn
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright */
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright //this.publish("data", {defaultFn: this._defDataFn});
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright //this.publish("data", {defaultFn:function(e){
78ac1ef5c64e9e95a94bbfe859662da6d21b243aEric Ferraiuolo // this._defDataFn(e);
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright //}});
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright this.publish("data", {defaultFn: Y.bind("_defDataFn", this)});
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright /**
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright * Fired when response is returned.
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright *
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @event response
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @param e {Event.Facade} Event Facade with the following properties:
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dl>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dt>request (Object)</dt> <dd>The request.</dd>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dt>callback (Object)</dt> <dd>The callback object with the following properties:
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dl>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dt>success (Function)</dt> <dd>Success handler.</dd>
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright * <dt>failure (Function)</dt> <dd>Failure handler.</dd>
a7e9ca67d735ae1bcdc1f7deb35ab98dd9c9f614Derek Gathright * <dt>scope (Object)</dt> <dd>Execution context.</dd>
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright * </dl>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * </dd>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dt>data (Object)</dt> <dd>Raw data.</dd>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dt>response (Object)</dt> <dd>Normalized resopnse object with the following properties:
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dl>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dt>results (Object)</dt> <dd>Parsed results.</dd>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dt>meta (Object)</dt> <dd>Parsed meta data.</dd>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dt>error (Boolean)</dt> <dd>Error flag.</dd>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * </dl>
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright * </dd>
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright * </dl>
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright * @preventable _defResponseFn
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright */
a7e9ca67d735ae1bcdc1f7deb35ab98dd9c9f614Derek Gathright //this.publish("response", {defaultFn: this._defResponseFn});
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright //this.publish("response", {defaultFn:function(e){
a7e9ca67d735ae1bcdc1f7deb35ab98dd9c9f614Derek Gathright // this._defResponseFn(e);
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright //}});
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright this.publish("response", {defaultFn: Y.bind("_defResponseFn", this)});
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright /**
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * Fired when an error is encountered.
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright *
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @event error
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @param e {Event.Facade} Event Facade with the following properties:
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dl>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dt>request (Object)</dt> <dd>The request.</dd>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dt>callback (Object)</dt> <dd>The callback object with the following properties:
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dl>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dt>success (Function)</dt> <dd>Success handler.</dd>
78ac1ef5c64e9e95a94bbfe859662da6d21b243aEric Ferraiuolo * <dt>failure (Function)</dt> <dd>Failure handler.</dd>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dt>scope (Object)</dt> <dd>Execution context.</dd>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * </dl>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * </dd>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dt>data (Object)</dt> <dd>Raw data.</dd>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * <dt>response (Object)</dt> <dd>Normalized resopnse object with the following properties:
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright * <dl>
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright * <dt>results (Object)</dt> <dd>Parsed results.</dd>
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright * <dt>meta (Object)</dt> <dd>Parsed meta data.</dd>
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright * <dt>error (Object)</dt> <dd>Error object.</dd>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * </dl>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * </dd>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * </dl>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright */
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright },
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright /**
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright * Manages request/response transaction. Must fire <code>response</code>
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * event when response is received. This method should be implemented by
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * subclasses to achieve more complex behavior such as accessing remote data.
78ac1ef5c64e9e95a94bbfe859662da6d21b243aEric Ferraiuolo *
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @method _defRequestFn
b2e3e4e5b9ad601bb552e859ade3329168457dd6Derek Gathright * @param e {Event.Facade} Event Facadewith the following properties:
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright * <dl>
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright * <dt>request (Object)</dt> <dd>The request.</dd>
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright * <dt>callback (Object)</dt> <dd>The callback object with the following properties:
78ac1ef5c64e9e95a94bbfe859662da6d21b243aEric Ferraiuolo * <dl>
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright * <dt>success (Function)</dt> <dd>Success handler.</dd>
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright * <dt>failure (Function)</dt> <dd>Failure handler.</dd>
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright * <dt>scope (Object)</dt> <dd>Execution context.</dd>
d8a453d703387a8f8168c110b3a052dc60e4a794Derek Gathright * </dl>
a7e9ca67d735ae1bcdc1f7deb35ab98dd9c9f614Derek Gathright * </dd>
a7e9ca67d735ae1bcdc1f7deb35ab98dd9c9f614Derek Gathright * </dl>
22084377ce30892c9fd181dada2d206969298e07Eric Ferraiuolo * @protected
*/
_defRequestFn: function(e) {
var data = this.get("source");
// Problematic data
if(LANG.isUndefined(data)) {
e.error = new Error(this.toString() + " Source undefined");
}
if(e.error) {
this.fire("error", e);
Y.log("Error in response", "error", this.toString());
}
this.fire("data", Y.mix({data:data}, e));
Y.log("Transaction " + e.tId + " complete. Request: " +
Y.dump(e.request) + " . Response: " + Y.dump(e.response), "info", this.toString());
},
/**
* Normalizes raw data into a response that includes results and meta properties.
*
* @method _defDataFn
* @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>
* <dt>scope (Object)</dt> <dd>Execution context.</dd>
* </dl>
* </dd>
* <dt>data (Object)</dt> <dd>Raw data.</dd>
* </dl>
* @protected
*/
_defDataFn: function(e) {
var data = e.data,
meta = e.meta,
response = {
results: (LANG.isArray(data)) ? data : [data],
meta: (meta) ? meta : {}
};
this.fire("response", Y.mix({response: response}, e));
},
/**
* Sends data as a normalized response to callback.
*
* @method _defResponseFn
* @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>
* <dt>scope (Object)</dt> <dd>Execution context.</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 (Boolean)</dt> <dd>Error flag.</dd>
* </dl>
* </dd>
* </dl>
* @protected
*/
_defResponseFn: function(e) {
// Send the response back to the callback
DSLocal.issueCallback(e);
},
/**
* Generates a unique transaction ID and fires <code>request</code> event.
*
* @method sendRequest
* @param request {Object} Request.
* @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>scope</code></dt>
* <dd>The object to serve as the scope for the success and failure handlers.</dd>
* <dt><code>argument</code></dt>
* <dd>Arbitrary data payload that will be passed back to the success and failure handlers.</dd>
* </dl>
* @return {Number} Transaction ID.
*/
sendRequest: function(request, callback) {
var tId = DSLocal._tId++;
this.fire("request", {tId:tId, request:request,callback:callback});
Y.log("Transaction " + tId + " sent request: " + Y.dump(request), "info", this.toString());
return tId;
}
});
Y.namespace("DataSource").Local = DSLocal;
}, '@VERSION@' ,{requires:['base']});
YUI.add('datasource-xhr', 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
*/
/**
* XHR subclass for the YUI DataSource utility.
* @class DataSource.XHR
* @extends DataSource.Local
* @constructor
*/
var DSXHR = function() {
DSXHR.superclass.constructor.apply(this, arguments);
};
/////////////////////////////////////////////////////////////////////////////
//
// DataSource.XHR static properties
//
/////////////////////////////////////////////////////////////////////////////
Y.mix(DSXHR, {
/**
* Class name.
*
* @property NAME
* @type String
* @static
* @final
* @value "DataSource.XHR"
*/
NAME: "DataSource.XHR",
/////////////////////////////////////////////////////////////////////////////
//
// DataSource.XHR Attributes
//
/////////////////////////////////////////////////////////////////////////////
ATTRS: {
/**
* Pointer to IO Utility.
*
* @attribute io
* @type Y.io
* @default Y.io
*/
io: {
value: Y.io
}
}
});
Y.extend(DSXHR, Y.DataSource.Local, {
/**
* Internal init() handler.
*
* @method initializer
* @param config {Object} Config object.
* @private
*/
initializer: function(config) {
this._queue = {interval:null, conn:null, requests:[]};
},
/**
* @property _queue
* @description Object literal to manage asynchronous request/response
* cycles enabled if queue needs to be managed (asyncMode/xhrConnMode):
* <dl>
* <dt>interval {Number}</dt>
* <dd>Interval ID of in-progress queue.</dd>
* <dt>conn</dt>
* <dd>In-progress connection identifier (if applicable).</dd>
* <dt>requests {Object[]}</dt>
* <dd>Array of queued request objects: {request:oRequest, callback:_xhrCallback}.</dd>
* </dl>
* @type Object
* @default {interval:null, conn:null, requests:[]}
* @private
*/
_queue: null,
/**
* 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>
* <dt>scope (Object)</dt> <dd>Execution context.</dd>
* </dl>
* </dd>
* </dl>
* @protected
*/
_defRequestFn: function(e) {
var uri = this.get("source"),
cfg = {
on: {
success: function (id, response, e) {
this.fire("data", Y.mix({data:response}, e));
Y.log("Received XHR data response for \"" + e.request + "\"", "info", this.toString());
//{tId:args.tId, request:args.request, callback:args.callback, response:response}
//this.handleResponse(args.tId, args.request, args.callback, response);
},
failure: function (id, response, e) {
e.error = new Error(this.toString() + " Data failure");
this.fire("error", Y.mix({data:response}, e));
this.fire("data", Y.mix({data:response}, e));
Y.log("Received XHR data response for \"" + e.request + "\"", "info", this.toString());
//{tId:args.tId, request:args.request, callback:args.callback, response:response}
//this.handleResponse(args.tId, args.request, args.callback, response);
}
},
context: this,
arguments: e
};
this.get("io")(uri, cfg);
return e.tId;
}
});
Y.DataSource.XHR = DSXHR;
}, '@VERSION@' ,{requires:['datasource-base']});
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>
* </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>
* <dt>scope (Object)</dt> <dd>Execution context.</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>
* </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:['plugin', 'datasource-base', '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, {
/**
* 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>
* <dt>scope (Object)</dt> <dd>Execution context.</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.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-base', '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, {
/**
* 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>
* <dt>scope (Object)</dt> <dd>Execution context.</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) && 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-base', 'dataschema-xml']});
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>scope</code></dt>
* <dd>The object to serve as the scope for the success and failure handlers.</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-base']});
YUI.add('datasource', function(Y){}, '@VERSION@' ,{use:['datasource-local','datasource-xhr','datasource-cache','datasource-jsonschema','datasource-xmlschema','datasource-polling']});