datasource-debug.js revision f3536609fa6dce3dde52193dd52d2ffa1c443e43
0N/A * The DataSource utility provides a common configurable interface for widgets to 0N/A * access a variety of data, from JavaScript arrays to online database servers. 0N/A * @module datasource 0N/A * Provides the base DataSource implementation, which can be extended to 0N/A * create DataSources for specific data protocols, such as the IO Utility, the 0N/A * Get Utility, or custom functions. 0N/A * @module datasource 0N/A * @submodule datasource-local 2362N/A * Base class for the DataSource Utility. 0N/A ///////////////////////////////////////////////////////////////////////////// 0N/A // DataSource static properties 0N/A ///////////////////////////////////////////////////////////////////////////// * @value "dataSourceLocal" ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// * @description Pointer to live data. * Global transaction counter. * @property DataSource._tId * Global in-progress transaction objects. * @property DataSource.transactions * Returns data to callback. * @method DataSource.issueCallback * @param e {EventFacade} Event Facade. * @param caller {DataSource} Calling DataSource instance. * Internal init() handler. * @param config {Object} Config object. * This method creates all the events for this module. * Fired when a data request is received. * @param e {Event.Facade} Event Facade with the following properties: * <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> * @preventable _defRequestFn * Fired when raw data is received. * @param e {Event.Facade} Event Facade with the following properties: * <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: * <dt>success (Function)</dt> <dd>Success handler.</dd> * <dt>failure (Function)</dt> <dd>Failure handler.</dd> * <dt>cfg (Object)</dt> <dd>Configuration object.</dd> * <dt>data (Object)</dt> <dd>Raw data.</dd> * @preventable _defDataFn * Fired when response is returned. * @param e {Event.Facade} Event Facade with the following properties: * <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: * <dt>success (Function)</dt> <dd>Success handler.</dd> * <dt>failure (Function)</dt> <dd>Failure handler.</dd> * <dt>cfg (Object)</dt> <dd>Configuration object.</dd> * <dt>data (Object)</dt> <dd>Raw data.</dd> * <dt>response (Object)</dt> <dd>Normalized response object with the following properties: * <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> * @preventable _defResponseFn * Fired when an error is encountered. * @param e {Event.Facade} Event Facade with the following properties: * <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: * <dt>success (Function)</dt> <dd>Success handler.</dd> * <dt>failure (Function)</dt> <dd>Failure handler.</dd> * <dt>cfg (Object)</dt> <dd>Configuration object.</dd> * <dt>data (Object)</dt> <dd>Raw data.</dd> * <dt>response (Object)</dt> <dd>Normalized response object with the following properties: * <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> * event when response is received. This method should be implemented by * subclasses to achieve more complex behavior such as accessing remote data. * @param e {Event.Facade} Event Facadewith the following properties: * <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: * <dt>success (Function)</dt> <dd>Success handler.</dd> * <dt>failure (Function)</dt> <dd>Failure handler.</dd> * <dt>cfg (Object)</dt> <dd>Configuration object.</dd> Y.
log(
"Local source undefined",
"error",
"datasource-local");
Y.
log(
"Transaction " + e.
tId +
" complete. Request: " +
* Normalizes raw data into a response that includes results and meta properties. * @param e {Event.Facade} Event Facade with the following properties: * <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: * <dt>success (Function)</dt> <dd>Success handler.</dd> * <dt>failure (Function)</dt> <dd>Failure handler.</dd> * <dt>cfg (Object)</dt> <dd>Configuration object.</dd> * <dt>data (Object)</dt> <dd>Raw data.</dd> * Sends data as a normalized response to callback. * @param e {Event.Facade} Event Facade with the following properties: * <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: * <dt>success (Function)</dt> <dd>Success handler.</dd> * <dt>failure (Function)</dt> <dd>Failure handler.</dd> * <dt>cfg (Object)</dt> <dd>Configuration object.</dd> * <dt>data (Object)</dt> <dd>Raw data.</dd> * <dt>response (Object)</dt> <dd>Normalized response object with the following properties: * <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> // Send the response back to the callback * Generates a unique transaction ID and fires <code>request</code> event. * @param request {Object} An object literal with the following properties: * <dt><code>request</code></dt> * <dd>The request to send to the live data source, if any.</dd> * <dt><code>callback</code></dt> * <dd>An object literal with the following properties: * <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 payload that will be passed back to the success and failure handlers.</dd> * <dt><code>cfg</code></dt> * <dd>Configuration object, if any.</dd> * @return {Number} Transaction ID. YUI.
add(
'datasource-io',
function(Y) {
* Provides a DataSource implementation which can be used to retrieve data via the IO Utility. * @submodule datasource-io * IO subclass for the DataSource Utility. * @extends DataSource.Local ///////////////////////////////////////////////////////////////////////////// // DataSource.IO static properties ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // DataSource.IO Attributes ///////////////////////////////////////////////////////////////////////////// * Internal init() handler. * @param config {Object} Config object. * @param id {String} Transaction ID. * @param response {String} Response. * @param e {Event.Facade} Event facade. Y.
log(
"Received IO data response for \"" + e.
request +
"\"",
"info",
"datasource-io");
* @param id {String} Transaction ID. * @param response {String} Response. * @param e {Event.Facade} Event facade. Y.
log(
"IO data failure",
"error",
"datasource-io");
Y.
log(
"Received IO data failure for \"" + e.
request +
"\"",
"info",
"datasource-io");
* <dt>interval {Number}</dt> * <dd>Interval ID of in-progress queue.</dd> * <dd>In-progress connection identifier (if applicable).</dd> * <dt>requests {Object[]}</dt> * <dd>Array of queued request objects: {request:request, callback:callback}.</dd> * @default {interval:null, conn:null, requests:[]} * Passes query string to IO. Fires <code>response</code> event when * response is received asynchronously. * @param e {Event.Facade} Event Facade with the following properties: * <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: * <dt>success (Function)</dt> <dd>Success handler.</dd> * <dt>failure (Function)</dt> <dd>Failure handler.</dd> * <dt>cfg (Object)</dt> <dd>Configuration object.</dd> // Support for POST transactions },
'@VERSION@' ,{
requires:[
'datasource-local',
'io-base']});
YUI.
add(
'datasource-get',
function(Y) {
* Provides a DataSource implementation which can be used to retrieve data via the Get Utility. * @submodule datasource-get * Get Utility subclass for the DataSource Utility. * @extends DataSource.Local * Passes query string to Get Utility. Fires <code>response</code> event when * response is received asynchronously. * @param e {Event.Facade} Event Facade with the following properties: * <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: * <dt>success (Function)</dt> <dd>Success handler.</dd> * <dt>failure (Function)</dt> <dd>Failure handler.</dd> * <dt>cfg (Object)</dt> <dd>Configuration object.</dd> * Stores the most recent request id for validation against stale // Dynamically add handler function with a closure to the callback stack var process =
this.
get(
'asyncMode') !==
"ignoreStaleResponses" ||
Y.
log(
"DataSource ignored stale response for id " + e.
tId +
"(" + e.
request +
")",
"info",
"datasource-get");
// Add the callback param to the request url Y.
log(
"DataSource is querying URL " +
uri,
"info",
"datasource-get");
// Works in Firefox only.... Y.
log(
"Script node data failure",
"error",
"datasource-get");
Y.
log(
"Script node data timeout",
"error",
"datasource-get");
* Default method for adding callback param to url. See * generateRequestCallback attribute. * @method _generateRequest * @param guid {String} unique identifier for callback function wrapper return "&" +
this.
get(
"scriptCallbackParam") +
"=YUI.Env.DataSource.callbacks." +
guid;
//////////////////////////////////////////////////////////////////////////// // DataSource.Get Attributes //////////////////////////////////////////////////////////////////////////// * Pointer to Get Utility. * <!--<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> * <dd>Send all requests and handle all responses.</dd> * Callback string parameter name sent to the remote script. By default, * <URI>?<scriptCallbackParam>=callbackFunction * @attribute scriptCallbackParam * Accepts the DataSource instance and a callback ID, and returns a callback * param/value string that gets appended to the script URI. Implementers * can customize this string to match their server's query syntax. * @attribute generateRequestCallback },
'@VERSION@' ,{
requires:[
'datasource-local',
'get']});
YUI.
add(
'datasource-function',
function(Y) {
* Provides a DataSource implementation which can be used to retrieve data from a custom function. * @submodule datasource-function * Function subclass for the DataSource Utility. * @class DataSource.Function * @extends DataSource.Local ///////////////////////////////////////////////////////////////////////////// // DataSource.Function static properties ///////////////////////////////////////////////////////////////////////////// * @value "dataSourceFunction" NAME:
"dataSourceFunction",
///////////////////////////////////////////////////////////////////////////// // DataSource.Function Attributes ///////////////////////////////////////////////////////////////////////////// * @description Pointer to live data. * Passes query string to IO. Fires <code>response</code> event when * response is received asynchronously. * @param e {Event.Facade} Event Facade with the following properties: * <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: * <dt>success (Function)</dt> <dd>Success handler.</dd> * <dt>failure (Function)</dt> <dd>Failure handler.</dd> * <dt>cfg (Object)</dt> <dd>Configuration object.</dd> var fn =
this.
get(
"source"),
Y.
log(
"Function execution failure",
"error",
"datasource-function");
Y.
log(
"Function data failure",
"error",
"datasource-function");
},
'@VERSION@' ,{
requires:[
'datasource-local']});
YUI.
add(
'datasource-cache',
function(Y) {
* Plugs DataSource with caching functionality. * @submodule datasource-cache * DataSourceCache extension binds Cache to DataSource. * @class DataSourceCacheExtension * The namespace for the plugin. This will be the property on the host which * references the plugin instance. * @value "dataSourceCacheExtension" NAME:
"dataSourceCacheExtension" * Internal init() handler. * @param config {Object} Config object. * First look for cached response, then send request to live data. * @method _beforeDefRequestFn * @param e {Event.Facade} Event Facade with the following properties: * <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> // Is response already in the Cache? return new Y.
Do.
Halt(
"DataSourceCache extension halted _defRequestFn");
* Adds data to cache before returning data. * @method _beforeDefResponseFn * @param e {Event.Facade} Event Facade with the following properties: * <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: * <dt>success (Function)</dt> <dd>Success handler.</dd> * <dt>failure (Function)</dt> <dd>Failure handler.</dd> * <dt>data (Object)</dt> <dd>Raw data.</dd> * <dt>response (Object)</dt> <dd>Normalized response object with the following properties: * <dt>cached (Object)</dt> <dd>True when response is cached.</dd> * <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> * <dt>cfg (Object)</dt> <dd>Configuration object.</dd> // Add to Cache before returning * DataSource plugin adds cache functionality. * @uses Plugin.Base, DataSourceCachePlugin * The namespace for the plugin. This will be the property on the host which * references the plugin instance. * @value "dataSourceCache" },
'@VERSION@' ,{
requires:[
'datasource-local',
'cache-base',
'plugin']});
YUI.
add(
'datasource-jsonschema',
function(Y) {
* Extends DataSource with schema-parsing on JSON data. * @submodule datasource-jsonschema * Adds schema-parsing to the DataSource Utility. * @class DataSourceJSONSchema * The namespace for the plugin. This will be the property on the host which * references the plugin instance. * @value "dataSourceJSONSchema" NAME:
"dataSourceJSONSchema",
///////////////////////////////////////////////////////////////////////////// // DataSourceJSONSchema Attributes ///////////////////////////////////////////////////////////////////////////// * Internal init() handler. * @param config {Object} Config object. * Parses raw data into a normalized response. To accommodate XHR responses, * will first look for data in data.responseText. Otherwise will just work * @method _beforeDefDataFn * @param tId {Number} Unique transaction ID. * @param request {Object} The request. * @param callback {Object} The callback object with the following properties: * <dt>success (Function)</dt> <dd>Success handler.</dd> * <dt>failure (Function)</dt> <dd>Failure handler.</dd> * @param data {Object} Raw data. return new Y.
Do.
Halt(
"DataSourceJSONSchema plugin halted _defDataFn");
},
'@VERSION@' ,{
requires:[
'datasource-local',
'plugin',
'dataschema-json']});
YUI.
add(
'datasource-xmlschema',
function(Y) {
* Extends DataSource with schema-parsing on XML data. * @submodule datasource-xmlschema * Adds schema-parsing to the DataSource Utility. * @class DataSourceXMLSchema * The namespace for the plugin. This will be the property on the host which * references the plugin instance. * @value "dataSourceXMLSchema" NAME:
"dataSourceXMLSchema",
///////////////////////////////////////////////////////////////////////////// // DataSourceXMLSchema Attributes ///////////////////////////////////////////////////////////////////////////// * Internal init() handler. * @param config {Object} Config object. * Parses raw data into a normalized response. * @method _beforeDefDataFn * @param tId {Number} Unique transaction ID. * @param request {Object} The request. * @param callback {Object} The callback object with the following properties: * <dt>success (Function)</dt> <dd>Success handler.</dd> * <dt>failure (Function)</dt> <dd>Failure handler.</dd> * @param data {Object} Raw data. return new Y.
Do.
Halt(
"DataSourceXMLSchema plugin halted _defDataFn");
},
'@VERSION@' ,{
requires:[
'datasource-local',
'plugin',
'dataschema-xml']});
YUI.
add(
'datasource-arrayschema',
function(Y) {
* Extends DataSource with schema-parsing on array data. * @submodule datasource-arrayschema * Adds schema-parsing to the DataSource Utility. * @class DataSourceArraySchema * The namespace for the plugin. This will be the property on the host which * references the plugin instance. * @value "dataSourceArraySchema" NAME:
"dataSourceArraySchema",
///////////////////////////////////////////////////////////////////////////// // DataSourceArraySchema Attributes ///////////////////////////////////////////////////////////////////////////// * Internal init() handler. * @param config {Object} Config object. * Parses raw data into a normalized response. * @method _beforeDefDataFn * @param tId {Number} Unique transaction ID. * @param request {Object} The request. * @param callback {Object} The callback object with the following properties: * <dt>success (Function)</dt> <dd>Success handler.</dd> * <dt>failure (Function)</dt> <dd>Failure handler.</dd> * @param data {Object} Raw data. return new Y.
Do.
Halt(
"DataSourceArraySchema plugin halted _defDataFn");
},
'@VERSION@' ,{
requires:[
'datasource-local',
'plugin',
'dataschema-array']});
YUI.
add(
'datasource-textschema',
function(Y) {
* Extends DataSource with schema-parsing on text data. * @submodule datasource-textschema * Adds schema-parsing to the DataSource Utility. * @class DataSourceTextSchema * The namespace for the plugin. This will be the property on the host which * references the plugin instance. * @value "dataSourceTextSchema" NAME:
"dataSourceTextSchema",
///////////////////////////////////////////////////////////////////////////// // DataSourceTextSchema Attributes ///////////////////////////////////////////////////////////////////////////// * Internal init() handler. * @param config {Object} Config object. * Parses raw data into a normalized response. * @method _beforeDefDataFn * @param tId {Number} Unique transaction ID. * @param request {Object} The request. * @param callback {Object} The callback object with the following properties: * <dt>success (Function)</dt> <dd>Success handler.</dd> * <dt>failure (Function)</dt> <dd>Failure handler.</dd> * @param data {Object} Raw data. return new Y.
Do.
Halt(
"DataSourceTextSchema plugin halted _defDataFn");
},
'@VERSION@' ,{
requires:[
'datasource-local',
'plugin',
'dataschema-text']});
YUI.
add(
'datasource-polling',
function(Y) {
* Extends DataSource with polling functionality. * @submodule datasource-polling * Adds polling to the DataSource Utility. * @extends DataSource.Local * @description Hash of polling interval IDs that have been enabled, * stored here to be able to clear all intervals. * Sets up a polling mechanism to send requests at set intervals and * forward responses to given callback. * @param msec {Number} Length of interval in milliseconds. * @param request {Object} An object literal with the following properties: * <dt><code>request</code></dt> * <dd>The request to send to the live data source, if any.</dd> * <dt><code>callback</code></dt> * <dd>An object literal with the following properties: * <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 payload that will be passed back to the success and failure handlers.</dd> * <dt><code>cfg</code></dt> * <dd>Configuration object, if any.</dd> * @return {Number} Interval ID. * Disables polling mechanism associated with the given interval ID. * @param id {Number} Interval ID. // In case of being called by clearAllIntervals() * @method clearAllIntervals },
'@VERSION@' ,{
requires:[
'datasource-local']});
YUI.
add(
'datasource',
function(Y){},
'@VERSION@' ,{
use:[
'datasource-local',
'datasource-io',
'datasource-get',
'datasource-function',
'datasource-cache',
'datasource-jsonschema',
'datasource-xmlschema',
'datasource-arrayschema',
'datasource-textschema',
'datasource-polling']});