datasource-io.js revision 32b6fd78d1787b0afecb1970111f14a46a569aa7
fa8e90e05f99c1976a887a4c2aa045cf719914d1isaacsYUI.add('datasource-io', function(Y) {
fa8e90e05f99c1976a887a4c2aa045cf719914d1isaacs
43e43f09389e9281bf353a8e420dccdcabfc8774isaacs/**
43e43f09389e9281bf353a8e420dccdcabfc8774isaacs * The DataSource utility provides a common configurable interface for widgets to
7db4608010d002a14b0f1871d6ac387f5af95be6Reid Burke * access a variety of data, from JavaScript arrays to online database servers.
7db4608010d002a14b0f1871d6ac387f5af95be6Reid Burke *
7db4608010d002a14b0f1871d6ac387f5af95be6Reid Burke * @module datasource
7db4608010d002a14b0f1871d6ac387f5af95be6Reid Burke */
7db4608010d002a14b0f1871d6ac387f5af95be6Reid Burke
7db4608010d002a14b0f1871d6ac387f5af95be6Reid Burke/**
7db4608010d002a14b0f1871d6ac387f5af95be6Reid Burke * IO subclass for the YUI DataSource utility.
7db4608010d002a14b0f1871d6ac387f5af95be6Reid Burke * @class DataSource.IO
7db4608010d002a14b0f1871d6ac387f5af95be6Reid Burke * @extends DataSource.Local
43e43f09389e9281bf353a8e420dccdcabfc8774isaacs * @constructor
7db4608010d002a14b0f1871d6ac387f5af95be6Reid Burke */
43e43f09389e9281bf353a8e420dccdcabfc8774isaacsvar DSIO = function() {
43e43f09389e9281bf353a8e420dccdcabfc8774isaacs DSIO.superclass.constructor.apply(this, arguments);
7db4608010d002a14b0f1871d6ac387f5af95be6Reid Burke};
43e43f09389e9281bf353a8e420dccdcabfc8774isaacs
43e43f09389e9281bf353a8e420dccdcabfc8774isaacs
7db4608010d002a14b0f1871d6ac387f5af95be6Reid Burke /////////////////////////////////////////////////////////////////////////////
7db4608010d002a14b0f1871d6ac387f5af95be6Reid Burke //
7db4608010d002a14b0f1871d6ac387f5af95be6Reid Burke // DataSource.IO static properties
7db4608010d002a14b0f1871d6ac387f5af95be6Reid Burke //
43e43f09389e9281bf353a8e420dccdcabfc8774isaacs /////////////////////////////////////////////////////////////////////////////
43e43f09389e9281bf353a8e420dccdcabfc8774isaacsY.mix(DSIO, {
fa8e90e05f99c1976a887a4c2aa045cf719914d1isaacs /**
* Class name.
*
* @property NAME
* @type String
* @static
* @final
* @value "dataSourceIO"
*/
NAME: "dataSourceIO",
/////////////////////////////////////////////////////////////////////////////
//
// DataSource.IO Attributes
//
/////////////////////////////////////////////////////////////////////////////
ATTRS: {
/**
* Pointer to IO Utility.
*
* @attribute io
* @type Y.io
* @default Y.io
*/
io: {
value: Y.io,
cloneDefaultValue: false
}
}
});
Y.extend(DSIO, 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/ioConnMode):
* <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:request, callback:callback}.</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>
* </dl>
* </dd>
* <dt>cfg (Object)</dt> <dd>Configuration object.</dd>
* </dl>
* @protected
*/
_defRequestFn: function(e) {
var uri = this.get("source"),
cfg = Y.mix(e.cfg, {
on: {
success: function (id, response, e) {
this.fire("data", Y.mix({data:response}, e));
},
failure: function (id, response, e) {
e.error = new Error("IO data failure");
this.fire("error", Y.mix({data:response}, e));
this.fire("data", Y.mix({data:response}, e));
}
},
context: this,
arguments: e
});
this.get("io")(uri, cfg);
return e.tId;
}
});
Y.DataSource.IO = DSIO;
}, '@VERSION@' ,{requires:['datasource-local', 'io']});