fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly/**
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly * Extends DataSource with schema-parsing on array data.
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly *
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly * @module datasource
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly * @submodule datasource-arrayschema
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly */
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly/**
8392a541bf432ed8d6e1985b6306b83dc898768dJenny Han Donnelly * Adds schema-parsing to the DataSource Utility.
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly * @class DataSourceArraySchema
32b6fd78d1787b0afecb1970111f14a46a569aa7Jenny Han Donnelly * @extends Plugin.Base
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly */
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnellyvar DataSourceArraySchema = function() {
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly DataSourceArraySchema.superclass.constructor.apply(this, arguments);
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly};
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han DonnellyY.mix(DataSourceArraySchema, {
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly /**
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly * The namespace for the plugin. This will be the property on the host which
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly * references the plugin instance.
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly *
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly * @property NS
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly * @type String
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly * @static
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly * @final
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly * @value "schema"
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly */
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly NS: "schema",
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly /**
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly * Class name.
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly *
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly * @property NAME
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly * @type String
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly * @static
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly * @final
1e0aa6df8881a856ec262f103bfee1c0a05d19b9Jenny Han Donnelly * @value "dataSourceArraySchema"
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly */
1e0aa6df8881a856ec262f103bfee1c0a05d19b9Jenny Han Donnelly NAME: "dataSourceArraySchema",
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly /////////////////////////////////////////////////////////////////////////////
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly //
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly // DataSourceArraySchema Attributes
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly //
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly /////////////////////////////////////////////////////////////////////////////
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly ATTRS: {
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly schema: {
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly //value: {}
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly }
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly }
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly});
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han DonnellyY.extend(DataSourceArraySchema, Y.Plugin.Base, {
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly /**
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly * Internal init() handler.
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly *
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly * @method initializer
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly * @param config {Object} Config object.
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly * @private
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly */
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly initializer: function(config) {
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly this.doBefore("_defDataFn", this._beforeDefDataFn);
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly },
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly /**
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly * Parses raw data into a normalized response.
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly *
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly * @method _beforeDefDataFn
815899c9e9780cd8b2d1c6368753c56afc5be443Ryan Grove * @param tId {Number} Unique transaction ID.
815899c9e9780cd8b2d1c6368753c56afc5be443Ryan Grove * @param request {Object} The request.
815899c9e9780cd8b2d1c6368753c56afc5be443Ryan Grove * @param callback {Object} The callback object with the following properties:
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly * <dl>
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly * <dt>success (Function)</dt> <dd>Success handler.</dd>
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly * <dt>failure (Function)</dt> <dd>Failure handler.</dd>
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly * </dl>
815899c9e9780cd8b2d1c6368753c56afc5be443Ryan Grove * @param data {Object} Raw data.
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly * @protected
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly */
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly _beforeDefDataFn: function(e) {
350839d3f8c71a522972265f77a8b5a3fbf6c82fJenny Han Donnelly var data = (Y.DataSource.IO && (this.get("host") instanceof Y.DataSource.IO) && Y.Lang.isString(e.data.responseText)) ? e.data.responseText : e.data,
2fe13ddab136a6eb6239d89e5e064e09d9e1bb92Luke Smith response = Y.DataSchema.Array.apply.call(this, this.get("schema"), data),
2fe13ddab136a6eb6239d89e5e064e09d9e1bb92Luke Smith payload = e.details[0];
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly // Default
2fe13ddab136a6eb6239d89e5e064e09d9e1bb92Luke Smith if (!response) {
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly response = {
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly meta: {},
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly results: data
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly };
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly }
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly
2fe13ddab136a6eb6239d89e5e064e09d9e1bb92Luke Smith payload.response = response;
2fe13ddab136a6eb6239d89e5e064e09d9e1bb92Luke Smith
2fe13ddab136a6eb6239d89e5e064e09d9e1bb92Luke Smith this.get("host").fire("response", payload);
2fe13ddab136a6eb6239d89e5e064e09d9e1bb92Luke Smith
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly return new Y.Do.Halt("DataSourceArraySchema plugin halted _defDataFn");
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly }
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly});
fe0eaf3c7c1942b0a300cd5f3952ada16fb18781Jenny Han Donnelly
21a3d9293597d65e84324fe57b7158e3d67a46c1Jenny Han DonnellyY.namespace('Plugin').DataSourceArraySchema = DataSourceArraySchema;