src/cm/media/js/lib/yui/yui_3.0.0b1/build/datasource/datasource-function.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-function', function(Y) {
       
     9 
       
    10 /**
       
    11  * Provides a DataSource implementation which can be used to retrieve data from a custom function.
       
    12  *
       
    13  * @module datasource
       
    14  * @submodule datasource-function
       
    15  */
       
    16 
       
    17 /**
       
    18  * Function subclass for the DataSource Utility.
       
    19  * @class DataSource.Function
       
    20  * @extends DataSource.Local
       
    21  * @constructor
       
    22  */    
       
    23 var LANG = Y.Lang,
       
    24 
       
    25     DSFn = function() {
       
    26         DSFn.superclass.constructor.apply(this, arguments);
       
    27     };
       
    28     
       
    29 
       
    30     /////////////////////////////////////////////////////////////////////////////
       
    31     //
       
    32     // DataSource.Function static properties
       
    33     //
       
    34     /////////////////////////////////////////////////////////////////////////////
       
    35 Y.mix(DSFn, {
       
    36     /**
       
    37      * Class name.
       
    38      *
       
    39      * @property NAME
       
    40      * @type String
       
    41      * @static     
       
    42      * @final
       
    43      * @value "dataSourceFunction"
       
    44      */
       
    45     NAME: "dataSourceFunction",
       
    46 
       
    47 
       
    48     /////////////////////////////////////////////////////////////////////////////
       
    49     //
       
    50     // DataSource.Function Attributes
       
    51     //
       
    52     /////////////////////////////////////////////////////////////////////////////
       
    53 
       
    54     ATTRS: {
       
    55         /**
       
    56         * @attribute source
       
    57         * @description Pointer to live data.
       
    58         * @type MIXED
       
    59         * @default null
       
    60         */
       
    61         source: {
       
    62             validator: LANG.isFunction
       
    63         }
       
    64     }
       
    65 });
       
    66     
       
    67 Y.extend(DSFn, Y.DataSource.Local, {
       
    68     /**
       
    69      * Passes query string to IO. Fires <code>response</code> event when
       
    70      * response is received asynchronously.
       
    71      *
       
    72      * @method _defRequestFn
       
    73      * @param e {Event.Facade} Event Facade with the following properties:
       
    74      * <dl>
       
    75      * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
       
    76      * <dt>request (Object)</dt> <dd>The request.</dd>
       
    77      * <dt>callback (Object)</dt> <dd>The callback object with the following properties:
       
    78      *     <dl>
       
    79      *         <dt>success (Function)</dt> <dd>Success handler.</dd>
       
    80      *         <dt>failure (Function)</dt> <dd>Failure handler.</dd>
       
    81      *     </dl>
       
    82      * </dd>
       
    83      * <dt>cfg (Object)</dt> <dd>Configuration object.</dd>
       
    84      * </dl>
       
    85      * @protected
       
    86      */
       
    87     _defRequestFn: function(e) {
       
    88         var fn = this.get("source"),
       
    89             response;
       
    90             
       
    91             if(fn) {
       
    92                 response = fn(e.request, this, e);
       
    93                 this.fire("data", Y.mix({data:response}, e));
       
    94             }
       
    95             else {
       
    96                 e.error = new Error("Function data failure");
       
    97                 this.fire("error", e);
       
    98             }
       
    99             
       
   100         return e.tId;
       
   101     }
       
   102 });
       
   103   
       
   104 Y.DataSource.Function = DSFn;
       
   105     
       
   106 
       
   107 
       
   108 
       
   109 }, '3.0.0b1' ,{requires:['datasource-local']});