| 1 | efrain | 1 | YUI.add('datasource-xmlschema', function (Y, NAME) {
 | 
        
           |  |  | 2 |   | 
        
           |  |  | 3 | /**
 | 
        
           |  |  | 4 |  * Extends DataSource with schema-parsing on XML data.
 | 
        
           |  |  | 5 |  *
 | 
        
           |  |  | 6 |  * @module datasource
 | 
        
           |  |  | 7 |  * @submodule datasource-xmlschema
 | 
        
           |  |  | 8 |  */
 | 
        
           |  |  | 9 |   | 
        
           |  |  | 10 | /**
 | 
        
           |  |  | 11 |  * Adds schema-parsing to the DataSource Utility.
 | 
        
           |  |  | 12 |  * @class DataSourceXMLSchema
 | 
        
           |  |  | 13 |  * @extends Plugin.Base
 | 
        
           |  |  | 14 |  */
 | 
        
           |  |  | 15 | var DataSourceXMLSchema = function() {
 | 
        
           |  |  | 16 |     DataSourceXMLSchema.superclass.constructor.apply(this, arguments);
 | 
        
           |  |  | 17 | };
 | 
        
           |  |  | 18 |   | 
        
           |  |  | 19 | Y.mix(DataSourceXMLSchema, {
 | 
        
           |  |  | 20 |     /**
 | 
        
           |  |  | 21 |      * The namespace for the plugin. This will be the property on the host which
 | 
        
           |  |  | 22 |      * references the plugin instance.
 | 
        
           |  |  | 23 |      *
 | 
        
           |  |  | 24 |      * @property NS
 | 
        
           |  |  | 25 |      * @type String
 | 
        
           |  |  | 26 |      * @static
 | 
        
           |  |  | 27 |      * @final
 | 
        
           |  |  | 28 |      * @value "schema"
 | 
        
           |  |  | 29 |      */
 | 
        
           |  |  | 30 |     NS: "schema",
 | 
        
           |  |  | 31 |   | 
        
           |  |  | 32 |     /**
 | 
        
           |  |  | 33 |      * Class name.
 | 
        
           |  |  | 34 |      *
 | 
        
           |  |  | 35 |      * @property NAME
 | 
        
           |  |  | 36 |      * @type String
 | 
        
           |  |  | 37 |      * @static
 | 
        
           |  |  | 38 |      * @final
 | 
        
           |  |  | 39 |      * @value "dataSourceXMLSchema"
 | 
        
           |  |  | 40 |      */
 | 
        
           |  |  | 41 |     NAME: "dataSourceXMLSchema",
 | 
        
           |  |  | 42 |   | 
        
           |  |  | 43 |     /////////////////////////////////////////////////////////////////////////////
 | 
        
           |  |  | 44 |     //
 | 
        
           |  |  | 45 |     // DataSourceXMLSchema Attributes
 | 
        
           |  |  | 46 |     //
 | 
        
           |  |  | 47 |     /////////////////////////////////////////////////////////////////////////////
 | 
        
           |  |  | 48 |   | 
        
           |  |  | 49 |     ATTRS: {
 | 
        
           |  |  | 50 |         schema: {
 | 
        
           |  |  | 51 |             //value: {}
 | 
        
           |  |  | 52 |         }
 | 
        
           |  |  | 53 |     }
 | 
        
           |  |  | 54 | });
 | 
        
           |  |  | 55 |   | 
        
           |  |  | 56 | Y.extend(DataSourceXMLSchema, Y.Plugin.Base, {
 | 
        
           |  |  | 57 |     /**
 | 
        
           |  |  | 58 |     * Internal init() handler.
 | 
        
           |  |  | 59 |     *
 | 
        
           |  |  | 60 |     * @method initializer
 | 
        
           |  |  | 61 |     * @param config {Object} Config object.
 | 
        
           |  |  | 62 |     * @private
 | 
        
           |  |  | 63 |     */
 | 
        
           |  |  | 64 |     initializer: function(config) {
 | 
        
           |  |  | 65 |         this.doBefore("_defDataFn", this._beforeDefDataFn);
 | 
        
           |  |  | 66 |     },
 | 
        
           |  |  | 67 |   | 
        
           |  |  | 68 |     /**
 | 
        
           |  |  | 69 |      * Parses raw data into a normalized response.
 | 
        
           |  |  | 70 |      *
 | 
        
           |  |  | 71 |      * @method _beforeDefDataFn
 | 
        
           |  |  | 72 |      * @param tId {Number} Unique transaction ID.
 | 
        
           |  |  | 73 |      * @param request {Object} The request.
 | 
        
           |  |  | 74 |      * @param callback {Object} The callback object with the following properties:
 | 
        
           |  |  | 75 |      *     <dl>
 | 
        
           |  |  | 76 |      *         <dt>success (Function)</dt> <dd>Success handler.</dd>
 | 
        
           |  |  | 77 |      *         <dt>failure (Function)</dt> <dd>Failure handler.</dd>
 | 
        
           |  |  | 78 |      *     </dl>
 | 
        
           |  |  | 79 |      * @param data {Object} Raw data.
 | 
        
           |  |  | 80 |      * @protected
 | 
        
           |  |  | 81 |      */
 | 
        
           |  |  | 82 |     _beforeDefDataFn: function(e) {
 | 
        
           |  |  | 83 |         var schema = this.get('schema'),
 | 
        
           |  |  | 84 |             payload = e.details[0],
 | 
        
           |  |  | 85 |             // TODO: Do I need to sniff for DS.IO + responseXML.nodeType 9?
 | 
        
           |  |  | 86 |             data = Y.XML.parse(e.data.responseText) || e.data;
 | 
        
           |  |  | 87 |   | 
        
           |  |  | 88 |         payload.response = Y.DataSchema.XML.apply.call(this, schema, data) || {
 | 
        
           |  |  | 89 |             meta: {},
 | 
        
           |  |  | 90 |             results: data
 | 
        
           |  |  | 91 |         };
 | 
        
           |  |  | 92 |   | 
        
           |  |  | 93 |         this.get("host").fire("response", payload);
 | 
        
           |  |  | 94 |   | 
        
           |  |  | 95 |         return new Y.Do.Halt("DataSourceXMLSchema plugin halted _defDataFn");
 | 
        
           |  |  | 96 |     }
 | 
        
           |  |  | 97 | });
 | 
        
           |  |  | 98 |   | 
        
           |  |  | 99 | Y.namespace('Plugin').DataSourceXMLSchema = DataSourceXMLSchema;
 | 
        
           |  |  | 100 |   | 
        
           |  |  | 101 |   | 
        
           |  |  | 102 | }, '3.18.1', {"requires": ["datasource-local", "plugin", "datatype-xml", "dataschema-xml"]});
 |