datasource-xhr.js revision 9e58396d3563168e91dc995170288bc18b84ab6f
93298460d1839a963f1f5979e90ee59dccf5b855Matt SweeneyYUI.add('datasource-xhr', function(Y) {
d592e9155bb1ceb2b977abd5008e7474b214a2b2Eric Ferraiuolo
93298460d1839a963f1f5979e90ee59dccf5b855Matt Sweeney/**
2fdf8d4f1ad797aaf0bfd3af88e4c04402b9ce3bMatt Sweeney * The DataSource utility provides a common configurable interface for widgets to
2fdf8d4f1ad797aaf0bfd3af88e4c04402b9ce3bMatt Sweeney * access a variety of data, from JavaScript arrays to online database servers.
2fdf8d4f1ad797aaf0bfd3af88e4c04402b9ce3bMatt Sweeney *
2fdf8d4f1ad797aaf0bfd3af88e4c04402b9ce3bMatt Sweeney * @module datasource-xhr
2fdea3dd40cb6e0b382e7c0387a76f5290cadd27Luke Smith * @requires datasource-base
2fdf8d4f1ad797aaf0bfd3af88e4c04402b9ce3bMatt Sweeney * @title DataSource XHR Submodule
2fdf8d4f1ad797aaf0bfd3af88e4c04402b9ce3bMatt Sweeney */
feb1dc670b0d4e1c6fcff58b35b36da3dfc5f18cJenny Donnelly
feb1dc670b0d4e1c6fcff58b35b36da3dfc5f18cJenny Donnelly /**
feb1dc670b0d4e1c6fcff58b35b36da3dfc5f18cJenny Donnelly * XHR subclass for the YUI DataSource utility.
feb1dc670b0d4e1c6fcff58b35b36da3dfc5f18cJenny Donnelly * @class DataSource.XHR
feb1dc670b0d4e1c6fcff58b35b36da3dfc5f18cJenny Donnelly * @extends DataSource
93298460d1839a963f1f5979e90ee59dccf5b855Matt Sweeney * @constructor
93298460d1839a963f1f5979e90ee59dccf5b855Matt Sweeney */
93298460d1839a963f1f5979e90ee59dccf5b855Matt Sweeney var XHR = function() {
feb1dc670b0d4e1c6fcff58b35b36da3dfc5f18cJenny Donnelly XHR.superclass.constructor.apply(this, arguments);
93298460d1839a963f1f5979e90ee59dccf5b855Matt Sweeney };
93298460d1839a963f1f5979e90ee59dccf5b855Matt Sweeney
93298460d1839a963f1f5979e90ee59dccf5b855Matt Sweeney
93298460d1839a963f1f5979e90ee59dccf5b855Matt Sweeney /////////////////////////////////////////////////////////////////////////////
93298460d1839a963f1f5979e90ee59dccf5b855Matt Sweeney //
93298460d1839a963f1f5979e90ee59dccf5b855Matt Sweeney // DataSource.XHR static properties
93298460d1839a963f1f5979e90ee59dccf5b855Matt Sweeney //
93298460d1839a963f1f5979e90ee59dccf5b855Matt Sweeney /////////////////////////////////////////////////////////////////////////////
93298460d1839a963f1f5979e90ee59dccf5b855Matt SweeneyY.mix(XHR, {
93298460d1839a963f1f5979e90ee59dccf5b855Matt Sweeney /**
93298460d1839a963f1f5979e90ee59dccf5b855Matt Sweeney * Class name.
93298460d1839a963f1f5979e90ee59dccf5b855Matt Sweeney *
feb1dc670b0d4e1c6fcff58b35b36da3dfc5f18cJenny Donnelly * @property DataSource.XHR.NAME
93298460d1839a963f1f5979e90ee59dccf5b855Matt Sweeney * @type String
93298460d1839a963f1f5979e90ee59dccf5b855Matt Sweeney * @static
93298460d1839a963f1f5979e90ee59dccf5b855Matt Sweeney * @final
93298460d1839a963f1f5979e90ee59dccf5b855Matt Sweeney * @value "DataSource.XHR"
93298460d1839a963f1f5979e90ee59dccf5b855Matt Sweeney */
feb1dc670b0d4e1c6fcff58b35b36da3dfc5f18cJenny Donnelly NAME: "DataSource.XHR",
93298460d1839a963f1f5979e90ee59dccf5b855Matt Sweeney
93298460d1839a963f1f5979e90ee59dccf5b855Matt Sweeney
93298460d1839a963f1f5979e90ee59dccf5b855Matt Sweeney /////////////////////////////////////////////////////////////////////////////
93298460d1839a963f1f5979e90ee59dccf5b855Matt Sweeney //
93298460d1839a963f1f5979e90ee59dccf5b855Matt Sweeney // DataSource.XHR Attributes
93298460d1839a963f1f5979e90ee59dccf5b855Matt Sweeney //
feb1dc670b0d4e1c6fcff58b35b36da3dfc5f18cJenny Donnelly /////////////////////////////////////////////////////////////////////////////
93298460d1839a963f1f5979e90ee59dccf5b855Matt Sweeney
93298460d1839a963f1f5979e90ee59dccf5b855Matt Sweeney ATTRS: {
93298460d1839a963f1f5979e90ee59dccf5b855Matt Sweeney /**
93298460d1839a963f1f5979e90ee59dccf5b855Matt Sweeney * Pointer to IO Utility.
feb1dc670b0d4e1c6fcff58b35b36da3dfc5f18cJenny Donnelly *
93298460d1839a963f1f5979e90ee59dccf5b855Matt Sweeney * @attribute io
93298460d1839a963f1f5979e90ee59dccf5b855Matt Sweeney * @type Y.io
* @default Y.io
*/
io: {
value: Y.io
}
}
});
Y.extend(XHR, Y.DataSource, {
/**
* Overriding <code>request</code> event handler passes query string to IO. Fires
* <code>response</code> event when response is received.
*
* @method _handleRequest
* @param e {Event.Facade} Event Facade.
* @param o {Object} Object 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
*/
_handleRequest: function(e, o) {
var uri = this.get("source"),
cfg = {
on: {
success: function (id, response, o) {
this.fire("data", null, Y.mix(o, {data:response}));
//{tId:args.tId, request:args.request, callback:args.callback, response:response}
//this.handleResponse(args.tId, args.request, args.callback, response);
},
failure: function (id, response, o) {
o.error = true;
this.fire("error", null, Y.mix(o, {data:response}));
this.fire("data", null, Y.mix(o, {data:response}));
//{tId:args.tId, request:args.request, callback:args.callback, response:response}
//this.handleResponse(args.tId, args.request, args.callback, response);
}
},
context: this,
arguments: {
tId: o.tId,
request: o.request,
callback: o.callback
}
};
this.get("io")(uri, cfg);
return o.tId;
}
});
Y.DataSource.XHR = XHR;
}, '@VERSION@' ,{requires:['datasource-base']});