~landscape/lazr-js/trunk

« back to all changes in this revision

Viewing changes to src-js/lazrjs/yui/3.0.0/build/datasource/datasource-io-debug.js

  • Committer: Sidnei da Silva
  • Date: 2009-10-21 21:43:07 UTC
  • mfrom: (120.2.15 yui-3.0.0)
  • mto: (124.5.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 126.
  • Revision ID: sidnei.da.silva@canonical.com-20091021214307-mpul9404n317puk5
- Merge from yui-3.0.0, resolving conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright (c) 2009, Yahoo! Inc. All rights reserved.
 
3
Code licensed under the BSD License:
 
4
http://developer.yahoo.net/yui/license.txt
 
5
version: 3.0.0
 
6
build: 1549
 
7
*/
 
8
YUI.add('datasource-io', function(Y) {
 
9
 
 
10
/**
 
11
 * Provides a DataSource implementation which can be used to retrieve data via the IO Utility.
 
12
 *
 
13
 * @module datasource
 
14
 * @submodule datasource-io
 
15
 */
 
16
 
 
17
/**
 
18
 * IO subclass for the DataSource Utility.
 
19
 * @class DataSource.IO
 
20
 * @extends DataSource.Local
 
21
 * @constructor
 
22
 */    
 
23
var DSIO = function() {
 
24
    DSIO.superclass.constructor.apply(this, arguments);
 
25
};
 
26
    
 
27
 
 
28
    /////////////////////////////////////////////////////////////////////////////
 
29
    //
 
30
    // DataSource.IO static properties
 
31
    //
 
32
    /////////////////////////////////////////////////////////////////////////////
 
33
Y.mix(DSIO, {
 
34
    /**
 
35
     * Class name.
 
36
     *
 
37
     * @property NAME
 
38
     * @type String
 
39
     * @static     
 
40
     * @final
 
41
     * @value "dataSourceIO"
 
42
     */
 
43
    NAME: "dataSourceIO",
 
44
 
 
45
 
 
46
    /////////////////////////////////////////////////////////////////////////////
 
47
    //
 
48
    // DataSource.IO Attributes
 
49
    //
 
50
    /////////////////////////////////////////////////////////////////////////////
 
51
 
 
52
    ATTRS: {
 
53
        /**
 
54
         * Pointer to IO Utility.
 
55
         *
 
56
         * @attribute io
 
57
         * @type Y.io
 
58
         * @default Y.io
 
59
         */
 
60
        io: {
 
61
            value: Y.io,
 
62
            cloneDefaultValue: false
 
63
        }
 
64
    }
 
65
});
 
66
    
 
67
Y.extend(DSIO, Y.DataSource.Local, {
 
68
    /**
 
69
    * Internal init() handler.
 
70
    *
 
71
    * @method initializer
 
72
    * @param config {Object} Config object.
 
73
    * @private
 
74
    */
 
75
    initializer: function(config) {
 
76
        this._queue = {interval:null, conn:null, requests:[]};
 
77
    },
 
78
 
 
79
    /**
 
80
    * @property _queue
 
81
    * @description Object literal to manage asynchronous request/response
 
82
    * cycles enabled if queue needs to be managed (asyncMode/ioConnMode):
 
83
    * <dl>
 
84
    *     <dt>interval {Number}</dt>
 
85
    *         <dd>Interval ID of in-progress queue.</dd>
 
86
    *     <dt>conn</dt>
 
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>
 
90
    * </dl>
 
91
    * @type Object
 
92
    * @default {interval:null, conn:null, requests:[]}
 
93
    * @private
 
94
    */
 
95
    _queue: null,
 
96
 
 
97
    /**
 
98
     * Passes query string to IO. Fires <code>response</code> event when
 
99
     * response is received asynchronously.
 
100
     *
 
101
     * @method _defRequestFn
 
102
     * @param e {Event.Facade} Event Facade with the following properties:
 
103
     * <dl>
 
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:
 
107
     *     <dl>
 
108
     *         <dt>success (Function)</dt> <dd>Success handler.</dd>
 
109
     *         <dt>failure (Function)</dt> <dd>Failure handler.</dd>
 
110
     *     </dl>
 
111
     * </dd>
 
112
     * <dt>cfg (Object)</dt> <dd>Configuration object.</dd>
 
113
     * </dl>
 
114
     * @protected
 
115
     */
 
116
    _defRequestFn: function(e) {
 
117
        var uri = this.get("source"),
 
118
            io = this.get("io"),
 
119
            request = e.request,
 
120
            cfg = Y.mix(e.cfg, {
 
121
                on: {
 
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");
 
125
                    },
 
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");
 
131
                    }
 
132
                },
 
133
                context: this,
 
134
                arguments: e
 
135
            });
 
136
        
 
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;
 
141
            }
 
142
            else {
 
143
                uri += request;
 
144
            }
 
145
        }
 
146
        io(uri, cfg);
 
147
        return e.tId;
 
148
    }
 
149
});
 
150
  
 
151
Y.DataSource.IO = DSIO;
 
152
    
 
153
 
 
154
 
 
155
 
 
156
}, '3.0.0' ,{requires:['datasource-local', 'io']});