3
Copyright 2011 Yahoo! Inc. All rights reserved.
4
Licensed under the BSD License.
5
http://yuilibrary.com/license/
7
YUI.add('datasource-arrayschema', function(Y) {
10
* Extends DataSource with schema-parsing on array data.
13
* @submodule datasource-arrayschema
17
* Adds schema-parsing to the DataSource Utility.
18
* @class DataSourceArraySchema
19
* @extends Plugin.Base
21
var DataSourceArraySchema = function() {
22
DataSourceArraySchema.superclass.constructor.apply(this, arguments);
25
Y.mix(DataSourceArraySchema, {
27
* The namespace for the plugin. This will be the property on the host which
28
* references the plugin instance.
45
* @value "dataSourceArraySchema"
47
NAME: "dataSourceArraySchema",
49
/////////////////////////////////////////////////////////////////////////////
51
// DataSourceArraySchema Attributes
53
/////////////////////////////////////////////////////////////////////////////
62
Y.extend(DataSourceArraySchema, Y.Plugin.Base, {
64
* Internal init() handler.
67
* @param config {Object} Config object.
70
initializer: function(config) {
71
this.doBefore("_defDataFn", this._beforeDefDataFn);
75
* Parses raw data into a normalized response.
77
* @method _beforeDefDataFn
78
* @param tId {Number} Unique transaction ID.
79
* @param request {Object} The request.
80
* @param callback {Object} The callback object with the following properties:
82
* <dt>success (Function)</dt> <dd>Success handler.</dd>
83
* <dt>failure (Function)</dt> <dd>Failure handler.</dd>
85
* @param data {Object} Raw data.
88
_beforeDefDataFn: function(e) {
89
var data = (Y.DataSource.IO && (this.get("host") instanceof Y.DataSource.IO) && Y.Lang.isString(e.data.responseText)) ? e.data.responseText : e.data,
90
response = Y.DataSchema.Array.apply.call(this, this.get("schema"), data),
91
payload = e.details[0];
101
payload.response = response;
103
this.get("host").fire("response", payload);
105
return new Y.Do.Halt("DataSourceArraySchema plugin halted _defDataFn");
109
Y.namespace('Plugin').DataSourceArraySchema = DataSourceArraySchema;
112
}, '3.4.1' ,{requires:['datasource-local', 'plugin', 'dataschema-array']});