NOBUG: Fixed file access permissions
[moodle.git] / lib / yuilib / 3.13.0 / datasource-arrayschema / datasource-arrayschema.js
blob2d869bdcb5747ad086cb269e034c517c32ad795d
1 /*
2 YUI 3.13.0 (build 508226d)
3 Copyright 2013 Yahoo! Inc. All rights reserved.
4 Licensed under the BSD License.
5 http://yuilibrary.com/license/
6 */
8 YUI.add('datasource-arrayschema', function (Y, NAME) {
10 /**
11  * Extends DataSource with schema-parsing on array data.
12  *
13  * @module datasource
14  * @submodule datasource-arrayschema
15  */
17 /**
18  * Adds schema-parsing to the DataSource Utility.
19  * @class DataSourceArraySchema
20  * @extends Plugin.Base
21  */
22 var DataSourceArraySchema = function() {
23     DataSourceArraySchema.superclass.constructor.apply(this, arguments);
26 Y.mix(DataSourceArraySchema, {
27     /**
28      * The namespace for the plugin. This will be the property on the host which
29      * references the plugin instance.
30      *
31      * @property NS
32      * @type String
33      * @static
34      * @final
35      * @value "schema"
36      */
37     NS: "schema",
39     /**
40      * Class name.
41      *
42      * @property NAME
43      * @type String
44      * @static
45      * @final
46      * @value "dataSourceArraySchema"
47      */
48     NAME: "dataSourceArraySchema",
50     /////////////////////////////////////////////////////////////////////////////
51     //
52     // DataSourceArraySchema Attributes
53     //
54     /////////////////////////////////////////////////////////////////////////////
56     ATTRS: {
57         schema: {
58             //value: {}
59         }
60     }
61 });
63 Y.extend(DataSourceArraySchema, Y.Plugin.Base, {
64     /**
65     * Internal init() handler.
66     *
67     * @method initializer
68     * @param config {Object} Config object.
69     * @private
70     */
71     initializer: function(config) {
72         this.doBefore("_defDataFn", this._beforeDefDataFn);
73     },
75     /**
76      * Parses raw data into a normalized response.
77      *
78      * @method _beforeDefDataFn
79      * @param tId {Number} Unique transaction ID.
80      * @param request {Object} The request.
81      * @param callback {Object} The callback object with the following properties:
82      *     <dl>
83      *         <dt>success (Function)</dt> <dd>Success handler.</dd>
84      *         <dt>failure (Function)</dt> <dd>Failure handler.</dd>
85      *     </dl>
86      * @param data {Object} Raw data.
87      * @protected
88      */
89     _beforeDefDataFn: function(e) {
90         var data = (Y.DataSource.IO && (this.get("host") instanceof Y.DataSource.IO) && Y.Lang.isString(e.data.responseText)) ? e.data.responseText : e.data,
91             response = Y.DataSchema.Array.apply.call(this, this.get("schema"), data),
92             payload = e.details[0];
94         // Default
95         if (!response) {
96             response = {
97                 meta: {},
98                 results: data
99             };
100         }
102         payload.response = response;
104         this.get("host").fire("response", payload);
106         return new Y.Do.Halt("DataSourceArraySchema plugin halted _defDataFn");
107     }
110 Y.namespace('Plugin').DataSourceArraySchema = DataSourceArraySchema;
113 }, '3.13.0', {"requires": ["datasource-local", "plugin", "dataschema-array"]});