1
/* YUI 3.9.1 (build 5852) Copyright 2013 Yahoo! Inc. http://yuilibrary.com/license/ */
2
YUI.add('datasource-io', function (Y, NAME) {
5
* Provides a DataSource implementation which can be used to retrieve data via the IO Utility.
8
* @submodule datasource-io
12
* IO subclass for the DataSource Utility.
13
* @class DataSource.IO
14
* @extends DataSource.Local
17
var DSIO = function() {
18
DSIO.superclass.constructor.apply(this, arguments);
22
/////////////////////////////////////////////////////////////////////////////
24
// DataSource.IO static properties
26
/////////////////////////////////////////////////////////////////////////////
35
* @value "dataSourceIO"
40
/////////////////////////////////////////////////////////////////////////////
42
// DataSource.IO Attributes
44
/////////////////////////////////////////////////////////////////////////////
48
* Pointer to IO Utility.
56
cloneDefaultValue: false
72
Y.extend(DSIO, Y.DataSource.Local, {
74
* Internal init() handler.
77
* @param config {Object} Config object.
80
initializer: function(config) {
81
this._queue = {interval:null, conn:null, requests:[]};
85
* IO success callback.
87
* @method successHandler
88
* @param id {String} Transaction ID.
89
* @param response {String} Response.
90
* @param e {Event.Facade} Event facade.
93
successHandler: function (id, response, e) {
94
var defIOConfig = this.get("ioConfig"),
95
payload = e.details[0];
97
delete Y.DataSource.Local.transactions[e.tId];
99
payload.data = response;
100
this.fire("data", payload);
103
if (defIOConfig && defIOConfig.on && defIOConfig.on.success) {
104
defIOConfig.on.success.apply(defIOConfig.context || Y, arguments);
109
* IO failure callback.
111
* @method failureHandler
112
* @param id {String} Transaction ID.
113
* @param response {String} Response.
114
* @param e {Event.Facade} Event facade.
117
failureHandler: function (id, response, e) {
118
var defIOConfig = this.get("ioConfig"),
119
payload = e.details[0];
121
delete Y.DataSource.Local.transactions[e.tId];
123
payload.error = new Error("IO data failure");
125
payload.data = response;
126
this.fire("data", payload);
129
if (defIOConfig && defIOConfig.on && defIOConfig.on.failure) {
130
defIOConfig.on.failure.apply(defIOConfig.context || Y, arguments);
136
* @description Object literal to manage asynchronous request/response
137
* cycles enabled if queue needs to be managed (asyncMode/ioConnMode):
139
* <dt>interval {Number}</dt>
140
* <dd>Interval ID of in-progress queue.</dd>
142
* <dd>In-progress connection identifier (if applicable).</dd>
143
* <dt>requests {Object[]}</dt>
144
* <dd>Array of queued request objects: {request:request, callback:callback}.</dd>
147
* @default {interval:null, conn:null, requests:[]}
153
* Passes query string to IO. Fires <code>response</code> event when
154
* response is received asynchronously.
156
* @method _defRequestFn
157
* @param e {Event.Facade} Event Facade with the following properties:
159
* <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
160
* <dt>request (Object)</dt> <dd>The request.</dd>
161
* <dt>callback (Object)</dt> <dd>The callback object with the following properties:
163
* <dt>success (Function)</dt> <dd>Success handler.</dd>
164
* <dt>failure (Function)</dt> <dd>Failure handler.</dd>
167
* <dt>cfg (Object)</dt> <dd>Configuration object.</dd>
171
_defRequestFn: function(e) {
172
var uri = this.get("source"),
174
defIOConfig = this.get("ioConfig"),
176
cfg = Y.merge(defIOConfig, e.cfg, {
177
on: Y.merge(defIOConfig, {
178
success: this.successHandler,
179
failure: this.failureHandler
185
// Support for POST transactions
186
if(Y.Lang.isString(request)) {
187
if(cfg.method && (cfg.method.toUpperCase() === "POST")) {
188
cfg.data = cfg.data ? cfg.data+request : request;
194
Y.DataSource.Local.transactions[e.tId] = io(uri, cfg);
199
Y.DataSource.IO = DSIO;
202
}, '3.9.1', {"requires": ["datasource-local", "io-base"]});