datasource-arrayschema.js revision 32b6fd78d1787b0afecb1970111f14a46a569aa7
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNicoYUI.add('datasource-arrayschema', function(Y) {
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico/**
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * Extends DataSource with schema-parsing on array data.
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico *
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @module datasource
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @submodule datasource-arrayschema
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico */
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico/**
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico * Adds schema-parsing to the YUI DataSource utility.
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico * @class DataSourceArraySchema
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico * @extends Plugin.Base
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico */
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNicovar DataSourceArraySchema = function() {
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico DataSourceArraySchema.superclass.constructor.apply(this, arguments);
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico};
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNicoY.mix(DataSourceArraySchema, {
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico /**
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * The namespace for the plugin. This will be the property on the host which
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * references the plugin instance.
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico *
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @property NS
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @type String
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @static
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @final
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico * @value "schema"
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico */
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico NS: "schema",
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico /**
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico * Class name.
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico *
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico * @property NAME
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico * @type String
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico * @static
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @final
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico * @value "dataSourceArraySchema"
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico */
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico NAME: "dataSourceArraySchema",
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico /////////////////////////////////////////////////////////////////////////////
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico //
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico // DataSourceArraySchema Attributes
c544ac2705cf516901c8455356d56b52c8615525mfloryan //
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico /////////////////////////////////////////////////////////////////////////////
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico ATTRS: {
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico schema: {
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico //value: {}
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico }
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico }
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico});
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNicoY.extend(DataSourceArraySchema, Y.Plugin.Base, {
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico /**
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * Internal init() handler.
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico *
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @method initializer
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico * @param config {Object} Config object.
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @private
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico */
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico initializer: function(config) {
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico this.doBefore("_defDataFn", this._beforeDefDataFn);
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico },
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico /**
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * Parses raw data into a normalized response.
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico *
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico * @method _beforeDefDataFn
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * <dl>
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico * <dt>request (Object)</dt> <dd>The request.</dd>
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico * <dt>callback (Object)</dt> <dd>The callback object with the following properties:
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * <dl>
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * <dt>success (Function)</dt> <dd>Success handler.</dd>
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * <dt>failure (Function)</dt> <dd>Failure handler.</dd>
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * </dl>
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * </dd>
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico * <dt>data (Object)</dt> <dd>Raw data.</dd>
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico * </dl>
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico * @protected
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico */
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico _beforeDefDataFn: function(e) {
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico var data = (Y.DataSource.IO && (this.get("host") instanceof Y.DataSource.IO) && Y.Lang.isString(e.data.responseText)) ? e.data.responseText : e.data,
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico response = Y.DataSchema.Array.apply(this.get("schema"), data);
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico // Default
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico if(!response) {
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico response = {
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico meta: {},
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico results: data
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico };
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico }
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico this.get("host").fire("response", Y.mix({response:response}, e));
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico return new Y.Do.Halt("DataSourceArraySchema plugin halted _defDataFn");
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico }
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico});
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNicoY.namespace('Plugin').DataSourceArraySchema = DataSourceArraySchema;
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico
646e07284c35ae746e8a0cf0698098e116ebb5a3JazzyNico
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico}, '@VERSION@' ,{requires:['plugin', 'datasource-local', 'dataschema-array']});
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico