2 Copyright (c) 2010, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.com/yui/license.html
8 YUI.add('datasource-textschema', function(Y) {
11 * Extends DataSource with schema-parsing on text data.
14 * @submodule datasource-textschema
18 * Adds schema-parsing to the DataSource Utility.
19 * @class DataSourceTextSchema
20 * @extends Plugin.Base
22 var DataSourceTextSchema = function() {
23 DataSourceTextSchema.superclass.constructor.apply(this, arguments);
26 Y.mix(DataSourceTextSchema, {
28 * The namespace for the plugin. This will be the property on the host which
29 * references the plugin instance.
46 * @value "dataSourceTextSchema"
48 NAME: "dataSourceTextSchema",
50 /////////////////////////////////////////////////////////////////////////////
52 // DataSourceTextSchema Attributes
54 /////////////////////////////////////////////////////////////////////////////
63 Y.extend(DataSourceTextSchema, Y.Plugin.Base, {
65 * Internal init() handler.
68 * @param config {Object} Config object.
71 initializer: function(config) {
72 this.doBefore("_defDataFn", this._beforeDefDataFn);
76 * Parses raw data into a normalized response.
78 * @method _beforeDefDataFn
80 * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
81 * <dt>request (Object)</dt> <dd>The request.</dd>
82 * <dt>callback (Object)</dt> <dd>The callback object with the following properties:
84 * <dt>success (Function)</dt> <dd>Success handler.</dd>
85 * <dt>failure (Function)</dt> <dd>Failure handler.</dd>
88 * <dt>data (Object)</dt> <dd>Raw data.</dd>
92 _beforeDefDataFn: function(e) {
93 var data = (Y.DataSource.IO && (this.get("host") instanceof Y.DataSource.IO) && Y.Lang.isString(e.data.responseText)) ? e.data.responseText : e.data,
94 response = Y.DataSchema.Text.apply.call(this, this.get("schema"), data);
104 this.get("host").fire("response", Y.mix({response:response}, e));
105 return new Y.Do.Halt("DataSourceTextSchema plugin halted _defDataFn");
109 Y.namespace('Plugin').DataSourceTextSchema = DataSourceTextSchema;
113 }, '3.3.0' ,{requires:['datasource-local', 'plugin', 'dataschema-text']});