src/cm/media/js/lib/yui/yui_3.0.0b1/build/datasource/datasource-io-debug.js
changeset 0 40c8f766c9b8
equal deleted inserted replaced
-1:000000000000 0:40c8f766c9b8
       
     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.0b1
       
     6 build: 1163
       
     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             cfg = Y.mix(e.cfg, {
       
   119                 on: {
       
   120                     success: function (id, response, e) {
       
   121                         this.fire("data", Y.mix({data:response}, e));
       
   122                         Y.log("Received IO data response for \"" + e.request + "\"", "info", "datasource-io");
       
   123                     },
       
   124                     failure: function (id, response, e) {
       
   125                         e.error = new Error("IO data failure");
       
   126                         this.fire("error", Y.mix({data:response}, e));
       
   127                         this.fire("data", Y.mix({data:response}, e));
       
   128                         Y.log("Received IO data failure for \"" + e.request + "\"", "info", "datasource-io");
       
   129                     }
       
   130                 },
       
   131                 context: this,
       
   132                 arguments: e
       
   133             });
       
   134         
       
   135         this.get("io")(uri, cfg);
       
   136         return e.tId;
       
   137     }
       
   138 });
       
   139   
       
   140 Y.DataSource.IO = DSIO;
       
   141     
       
   142 
       
   143 
       
   144 
       
   145 }, '3.0.0b1' ,{requires:['datasource-local', 'io']});