datasource-textschema-debug.js revision 2634b0e23224a943745ebee1c4b016a207ab0564
964N/AYUI.add('datasource-textschema', function(Y) {
964N/A
964N/A/**
964N/A * Extends DataSource with schema-parsing on text data.
964N/A *
964N/A * @module datasource
964N/A * @submodule datasource-textschema
964N/A */
964N/A
964N/A/**
964N/A * Adds schema-parsing to the YUI DataSource utility.
964N/A * @class DataSourceTextSchema
964N/A * @extends Plugin
964N/A */
964N/Avar DataSourceTextSchema = function() {
964N/A DataSourceTextSchema.superclass.constructor.apply(this, arguments);
964N/A};
964N/A
964N/AY.mix(DataSourceTextSchema, {
964N/A /**
964N/A * The namespace for the plugin. This will be the property on the host which
964N/A * references the plugin instance.
964N/A *
964N/A * @property NS
964N/A * @type String
964N/A * @static
964N/A * @final
964N/A * @value "schema"
964N/A */
964N/A NS: "schema",
964N/A
964N/A /**
964N/A * Class name.
964N/A *
964N/A * @property NAME
964N/A * @type String
964N/A * @static
964N/A * @final
964N/A * @value "DataSourceTextSchema"
964N/A */
964N/A NAME: "DataSourceTextSchema",
964N/A
964N/A /////////////////////////////////////////////////////////////////////////////
964N/A //
964N/A // DataSourceTextSchema Attributes
964N/A //
964N/A /////////////////////////////////////////////////////////////////////////////
964N/A
964N/A ATTRS: {
964N/A schema: {
964N/A //value: {}
964N/A }
964N/A }
964N/A});
964N/A
964N/AY.extend(DataSourceTextSchema, Y.Plugin.Base, {
964N/A /**
964N/A * Internal init() handler.
964N/A *
964N/A * @method initializer
964N/A * @param config {Object} Config object.
964N/A * @private
964N/A */
964N/A initializer: function(config) {
964N/A this.doBefore("_defDataFn", this._beforeDefDataFn);
964N/A },
982N/A
964N/A /**
964N/A * Parses raw data into a normalized response.
964N/A *
964N/A * @method _beforeDefDataFn
964N/A * <dl>
964N/A * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
964N/A * <dt>request (Object)</dt> <dd>The request.</dd>
964N/A * <dt>callback (Object)</dt> <dd>The callback object with the following properties:
964N/A * <dl>
964N/A * <dt>success (Function)</dt> <dd>Success handler.</dd>
964N/A * <dt>failure (Function)</dt> <dd>Failure handler.</dd>
964N/A * <dt>scope (Object)</dt> <dd>Execution context.</dd>
964N/A * </dl>
964N/A * </dd>
964N/A * <dt>data (Object)</dt> <dd>Raw data.</dd>
964N/A * </dl>
964N/A * @protected
964N/A */
964N/A _beforeDefDataFn: function(e) {
964N/A var data = ((this.get("host") instanceof Y.DataSource.XHR) && Y.Lang.isString(e.data.responseText)) ? e.data.responseText : e.data,
964N/A response = Y.DataSchema.Text.apply(this.get("schema"), data);
964N/A
964N/A // Default
964N/A if(!response) {
964N/A response = {
964N/A meta: {},
964N/A results: data
964N/A };
964N/A }
964N/A
964N/A this.get("host").fire("response", Y.mix({response:response}, e));
964N/A return new Y.Do.Halt("DataSourceTextSchema plugin halted _defDataFn");
964N/A }
964N/A});
964N/A
Y.namespace('plugin').DataSourceTextSchema = DataSourceTextSchema;
}, '@VERSION@' ,{requires:['plugin', 'datasource-local', 'dataschema-text']});