Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
YUI.add('datasource-textschema', function (Y, NAME) {
2
 
3
/**
4
 * Extends DataSource with schema-parsing on text data.
5
 *
6
 * @module datasource
7
 * @submodule datasource-textschema
8
 */
9
 
10
/**
11
 * Adds schema-parsing to the DataSource Utility.
12
 * @class DataSourceTextSchema
13
 * @extends Plugin.Base
14
 */
15
var DataSourceTextSchema = function() {
16
    DataSourceTextSchema.superclass.constructor.apply(this, arguments);
17
};
18
 
19
Y.mix(DataSourceTextSchema, {
20
    /**
21
     * The namespace for the plugin. This will be the property on the host which
22
     * references the plugin instance.
23
     *
24
     * @property NS
25
     * @type String
26
     * @static
27
     * @final
28
     * @value "schema"
29
     */
30
    NS: "schema",
31
 
32
    /**
33
     * Class name.
34
     *
35
     * @property NAME
36
     * @type String
37
     * @static
38
     * @final
39
     * @value "dataSourceTextSchema"
40
     */
41
    NAME: "dataSourceTextSchema",
42
 
43
    /////////////////////////////////////////////////////////////////////////////
44
    //
45
    // DataSourceTextSchema Attributes
46
    //
47
    /////////////////////////////////////////////////////////////////////////////
48
 
49
    ATTRS: {
50
        schema: {
51
            //value: {}
52
        }
53
    }
54
});
55
 
56
Y.extend(DataSourceTextSchema, Y.Plugin.Base, {
57
    /**
58
    * Internal init() handler.
59
    *
60
    * @method initializer
61
    * @param config {Object} Config object.
62
    * @private
63
    */
64
    initializer: function(config) {
65
        this.doBefore("_defDataFn", this._beforeDefDataFn);
66
    },
67
 
68
    /**
69
     * Parses raw data into a normalized response.
70
     *
71
     * @method _beforeDefDataFn
72
     * @param tId {Number} Unique transaction ID.
73
     * @param request {Object} The request.
74
     * @param callback {Object} The callback object with the following properties:
75
     *     <dl>
76
     *         <dt>success (Function)</dt> <dd>Success handler.</dd>
77
     *         <dt>failure (Function)</dt> <dd>Failure handler.</dd>
78
     *     </dl>
79
     * @param data {Object} Raw data.
80
     * @protected
81
     */
82
    _beforeDefDataFn: function(e) {
83
        var schema = this.get('schema'),
84
            payload = e.details[0],
85
            // TODO: Do I need to sniff for DS.IO + isString(responseText)?
86
            data = e.data.responseText || e.data;
87
 
88
        payload.response = Y.DataSchema.Text.apply.call(this, schema, data) || {
89
            meta: {},
90
            results: data
91
        };
92
 
93
        this.get("host").fire("response", payload);
94
 
95
        return new Y.Do.Halt("DataSourceTextSchema plugin halted _defDataFn");
96
    }
97
});
98
 
99
Y.namespace('Plugin').DataSourceTextSchema = DataSourceTextSchema;
100
 
101
 
102
}, '3.18.1', {"requires": ["datasource-local", "plugin", "dataschema-text"]});