datasource-jsonparser-debug.js revision d878e6ff2cceb987580db5144f8d0e6fdc18f78a
1024N/AYUI.add('datasource-jsonparser', function(Y) {
1024N/A
1024N/A/**
1024N/A * Extends DataSource with schema-based JSON parsing functionality.
1024N/A *
1024N/A * @module datasource-jsonparser
1024N/A * @requires plugin, datasource-base, dataparser-json
1024N/A * @title DataSource JSONParser Plugin
1024N/A */
1024N/A
1024N/A/**
1024N/A * Adds parsability to the YUI DataSource utility.
1024N/A * @class DataSourceJSONParser
1024N/A */
1024N/Avar DataSourceJSONParser = function() {
1024N/A DataSourceJSONParser.superclass.constructor.apply(this, arguments);
1024N/A};
1024N/A
1024N/AY.mix(DataSourceJSONParser, {
1024N/A /**
1024N/A * The namespace for the plugin. This will be the property on the host which
1024N/A * references the plugin instance.
1024N/A *
1024N/A * @property NS
150N/A * @type String
150N/A * @static
150N/A * @final
257N/A * @value "cache"
257N/A */
257N/A NS: "parser",
257N/A
257N/A /**
257N/A * Class name.
257N/A *
150N/A * @property DataParser.Base.NAME
257N/A * @type String
670N/A * @static
257N/A * @final
257N/A * @value "DataSourceCache"
200N/A */
150N/A NAME: "DataSourceJSONParser",
210N/A
150N/A /////////////////////////////////////////////////////////////////////////////
150N/A //
150N/A // DataSourceCache Attributes
150N/A //
150N/A /////////////////////////////////////////////////////////////////////////////
150N/A
150N/A ATTRS: {
150N/A parser: {
150N/A readOnly: true,
150N/A value: Y.DataParser.JSON,
150N/A useRef: true
150N/A },
150N/A schema: {
150N/A //value: {}
150N/A }
150N/A }
200N/A});
200N/A
200N/AY.extend(DataSourceJSONParser, Y.Plugin, {
200N/A /**
200N/A * @method initializer
1024N/A * @description Internal init() handler.
200N/A * @private
200N/A */
1024N/A initializer: function(config) {
200N/A this.doBefore("_defDataFn", this._beforeDefDataFn);
200N/A },
200N/A
150N/A /**
210N/A * Parses raw data into a normalized response.
210N/A *
953N/A * @method _defDataFn
1024N/A * @param e {Event.Facade} Event Facade.
953N/A * @param o {Object} Object with the following properties:
953N/A * <dl>
953N/A * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
953N/A * <dt>request (Object)</dt> <dd>The request.</dd>
953N/A * <dt>callback (Object)</dt> <dd>The callback object.</dd>
956N/A * <dt>data (Object)</dt> <dd>The raw response.</dd>
953N/A * </dl>
953N/A * @protected
953N/A */
210N/A _beforeDefDataFn: function(e, o) {
210N/A var response = (this.get("parser").parse(this.get("schema"), o.data));
210N/A if(!response) {
210N/A response = {
210N/A meta: {},
210N/A results: o.data
210N/A };
210N/A }
210N/A this._owner.fire("response", null, Y.mix(o, response));
210N/A return new Y.Do.Halt("DataSourceJSONParser plugin halted _defDataFn");
210N/A }
210N/A});
210N/A
210N/AY.namespace('plugin');
210N/AY.plugin.DataSourceJSONParser = DataSourceJSONParser;
210N/A
210N/A
210N/A
257N/A}, '@VERSION@' ,{requires:['plugin', 'datasource-base', 'dataparser-json']});
257N/A