3
Copyright 2011 Yahoo! Inc. All rights reserved.
4
Licensed under the BSD License.
5
http://yuilibrary.com/license/
7
YUI.add('datasource-jsonschema', function(Y) {
10
* Extends DataSource with schema-parsing on JSON data.
13
* @submodule datasource-jsonschema
17
* Adds schema-parsing to the DataSource Utility.
18
* @class DataSourceJSONSchema
19
* @extends Plugin.Base
21
var DataSourceJSONSchema = function() {
22
DataSourceJSONSchema.superclass.constructor.apply(this, arguments);
25
Y.mix(DataSourceJSONSchema, {
27
* The namespace for the plugin. This will be the property on the host which
28
* references the plugin instance.
45
* @value "dataSourceJSONSchema"
47
NAME: "dataSourceJSONSchema",
49
/////////////////////////////////////////////////////////////////////////////
51
// DataSourceJSONSchema Attributes
53
/////////////////////////////////////////////////////////////////////////////
62
Y.extend(DataSourceJSONSchema, 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. To accommodate XHR responses,
76
* will first look for data in data.responseText. Otherwise will just work
79
* @method _beforeDefDataFn
80
* @param tId {Number} Unique transaction ID.
81
* @param request {Object} The request.
82
* @param callback {Object} The callback object with the following properties:
84
* <dt>success (Function)</dt> <dd>Success handler.</dd>
85
* <dt>failure (Function)</dt> <dd>Failure handler.</dd>
87
* @param data {Object} Raw data.
90
_beforeDefDataFn: function(e) {
91
var data = e.data && (e.data.responseText || e.data),
92
schema = this.get('schema'),
93
payload = e.details[0];
95
payload.response = Y.DataSchema.JSON.apply.call(this, schema, data) || {
100
this.get("host").fire("response", payload);
102
return new Y.Do.Halt("DataSourceJSONSchema plugin halted _defDataFn");
106
Y.namespace('Plugin').DataSourceJSONSchema = DataSourceJSONSchema;
109
}, '3.4.1' ,{requires:['datasource-local', 'plugin', 'dataschema-json']});