2 YUI 3.13.0 (build 508226d)
3 Copyright 2013 Yahoo! Inc. All rights reserved.
4 Licensed under the BSD License.
5 http://yuilibrary.com/license/
8 YUI.add('datasource-textschema', function (Y, NAME) {
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
79 * @param tId {Number} Unique transaction ID.
80 * @param request {Object} The request.
81 * @param callback {Object} The callback object with the following properties:
83 * <dt>success (Function)</dt> <dd>Success handler.</dd>
84 * <dt>failure (Function)</dt> <dd>Failure handler.</dd>
86 * @param data {Object} Raw data.
89 _beforeDefDataFn: function(e) {
90 var schema = this.get('schema'),
91 payload = e.details[0],
92 // TODO: Do I need to sniff for DS.IO + isString(responseText)?
93 data = e.data.responseText || e.data;
95 payload.response = Y.DataSchema.Text.apply.call(this, schema, data) || {
100 this.get("host").fire("response", payload);
102 return new Y.Do.Halt("DataSourceTextSchema plugin halted _defDataFn");
106 Y.namespace('Plugin').DataSourceTextSchema = DataSourceTextSchema;
109 }, '3.13.0', {"requires": ["datasource-local", "plugin", "dataschema-text"]});