2
Copyright (c) 2009, Yahoo! Inc. All rights reserved.
3
Code licensed under the BSD License:
4
http://developer.yahoo.net/yui/license.txt
8
YUI.add('datasource-io', function(Y) {
11
* Provides a DataSource implementation which can be used to retrieve data via the IO Utility.
14
* @submodule datasource-io
18
* IO subclass for the DataSource Utility.
19
* @class DataSource.IO
20
* @extends DataSource.Local
23
var DSIO = function() {
24
DSIO.superclass.constructor.apply(this, arguments);
28
/////////////////////////////////////////////////////////////////////////////
30
// DataSource.IO static properties
32
/////////////////////////////////////////////////////////////////////////////
41
* @value "dataSourceIO"
46
/////////////////////////////////////////////////////////////////////////////
48
// DataSource.IO Attributes
50
/////////////////////////////////////////////////////////////////////////////
54
* Pointer to IO Utility.
62
cloneDefaultValue: false
67
Y.extend(DSIO, Y.DataSource.Local, {
69
* Internal init() handler.
72
* @param config {Object} Config object.
75
initializer: function(config) {
76
this._queue = {interval:null, conn:null, requests:[]};
81
* @description Object literal to manage asynchronous request/response
82
* cycles enabled if queue needs to be managed (asyncMode/ioConnMode):
84
* <dt>interval {Number}</dt>
85
* <dd>Interval ID of in-progress queue.</dd>
87
* <dd>In-progress connection identifier (if applicable).</dd>
88
* <dt>requests {Object[]}</dt>
89
* <dd>Array of queued request objects: {request:request, callback:callback}.</dd>
92
* @default {interval:null, conn:null, requests:[]}
98
* Passes query string to IO. Fires <code>response</code> event when
99
* response is received asynchronously.
101
* @method _defRequestFn
102
* @param e {Event.Facade} Event Facade with the following properties:
104
* <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
105
* <dt>request (Object)</dt> <dd>The request.</dd>
106
* <dt>callback (Object)</dt> <dd>The callback object with the following properties:
108
* <dt>success (Function)</dt> <dd>Success handler.</dd>
109
* <dt>failure (Function)</dt> <dd>Failure handler.</dd>
112
* <dt>cfg (Object)</dt> <dd>Configuration object.</dd>
116
_defRequestFn: function(e) {
117
var uri = this.get("source"),
122
success: function (id, response, e) {
123
this.fire("data", Y.mix({data:response}, e));
124
Y.log("Received IO data response for \"" + request + "\"", "info", "datasource-io");
126
failure: function (id, response, e) {
127
e.error = new Error("IO data failure");
128
this.fire("error", Y.mix({data:response}, e));
129
this.fire("data", Y.mix({data:response}, e));
130
Y.log("Received IO data failure for \"" + request + "\"", "info", "datasource-io");
137
// Support for POST transactions
138
if(Y.Lang.isString(request)) {
139
if(cfg.method && (cfg.method.toUpperCase() === "POST")) {
140
cfg.data = cfg.data ? cfg.data+request : request;
151
Y.DataSource.IO = DSIO;
156
}, '3.0.0' ,{requires:['datasource-local', 'io']});