~smagoun/whoopsie/whoopsie-lp1017637

« back to all changes in this revision

Viewing changes to backend/stats/static/js/yui/build/datatable-datasource/datatable-datasource.js

  • Committer: Evan Dandrea
  • Date: 2012-05-09 05:53:45 UTC
  • Revision ID: evan.dandrea@canonical.com-20120509055345-z2j41tmcbf4as5uf
The backend now lives in lp:daisy and the website (errors.ubuntu.com) now lives in lp:errors.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
YUI 3.5.0 (build 5089)
3
 
Copyright 2012 Yahoo! Inc. All rights reserved.
4
 
Licensed under the BSD License.
5
 
http://yuilibrary.com/license/
6
 
*/
7
 
YUI.add('datatable-datasource', function(Y) {
8
 
 
9
 
/**
10
 
 * Plugs DataTable with DataSource integration.
11
 
 *
12
 
 * @module datatable
13
 
 * @submodule datatable-datasource
14
 
 */
15
 
 
16
 
/**
17
 
 * Adds DataSource integration to DataTable.
18
 
 * @class Plugin.DataTableDataSource
19
 
 * @extends Plugin.Base
20
 
 */
21
 
function DataTableDataSource() {
22
 
    DataTableDataSource.superclass.constructor.apply(this, arguments);
23
 
}
24
 
 
25
 
/////////////////////////////////////////////////////////////////////////////
26
 
//
27
 
// STATIC PROPERTIES
28
 
//
29
 
/////////////////////////////////////////////////////////////////////////////
30
 
Y.mix(DataTableDataSource, {
31
 
    /**
32
 
     * The namespace for the plugin. This will be the property on the host which
33
 
     * references the plugin instance.
34
 
     *
35
 
     * @property NS
36
 
     * @type String
37
 
     * @static
38
 
     * @final
39
 
     * @value "datasource"
40
 
     */
41
 
    NS: "datasource",
42
 
 
43
 
    /**
44
 
     * Class name.
45
 
     *
46
 
     * @property NAME
47
 
     * @type String
48
 
     * @static
49
 
     * @final
50
 
     * @value "dataTableDataSource"
51
 
     */
52
 
    NAME: "dataTableDataSource",
53
 
 
54
 
/////////////////////////////////////////////////////////////////////////////
55
 
//
56
 
// ATTRIBUTES
57
 
//
58
 
/////////////////////////////////////////////////////////////////////////////
59
 
    ATTRS: {
60
 
        /**
61
 
        * @attribute datasource
62
 
        * @description Pointer to DataSource instance.
63
 
        * @type {DataSource}
64
 
        */
65
 
        datasource: {
66
 
            setter: "_setDataSource"
67
 
        },
68
 
        
69
 
        /**
70
 
        * @attribute initialRequest
71
 
        * @description Request sent to DataSource immediately upon initialization.
72
 
        * @type Object
73
 
        */
74
 
        initialRequest: {
75
 
            setter: "_setInitialRequest"
76
 
        }
77
 
    }
78
 
});
79
 
 
80
 
/////////////////////////////////////////////////////////////////////////////
81
 
//
82
 
// PROTOTYPE
83
 
//
84
 
/////////////////////////////////////////////////////////////////////////////
85
 
Y.extend(DataTableDataSource, Y.Plugin.Base, {
86
 
    /////////////////////////////////////////////////////////////////////////////
87
 
    //
88
 
    // ATTRIBUTE HELPERS
89
 
    //
90
 
    /////////////////////////////////////////////////////////////////////////////
91
 
    /**
92
 
    * @method _setDataSource
93
 
    * @description Creates new DataSource instance if one is not provided.
94
 
    * @param ds {Object | Y.DataSource}
95
 
    * @return {DataSource}
96
 
    * @private
97
 
    */
98
 
    _setDataSource: function(ds) {
99
 
        return ds || new Y.DataSource.Local(ds);
100
 
    },
101
 
 
102
 
    /**
103
 
    * @method _setInitialRequest
104
 
    * @description Sends request to DataSource.
105
 
    * @param request {Object} DataSource request.
106
 
    * @private
107
 
    */
108
 
    _setInitialRequest: function(request) {
109
 
    },
110
 
 
111
 
    /////////////////////////////////////////////////////////////////////////////
112
 
    //
113
 
    // METHODS
114
 
    //
115
 
    /////////////////////////////////////////////////////////////////////////////
116
 
    /**
117
 
    * Initializer.
118
 
    *
119
 
    * @method initializer
120
 
    * @param config {Object} Config object.
121
 
    * @private
122
 
    */
123
 
    initializer: function(config) {
124
 
        if(!Y.Lang.isUndefined(config.initialRequest)) {
125
 
            this.load({request:config.initialRequest});
126
 
        }
127
 
    },
128
 
 
129
 
    ////////////////////////////////////////////////////////////////////////////
130
 
    //
131
 
    // DATA
132
 
    //
133
 
    ////////////////////////////////////////////////////////////////////////////
134
 
 
135
 
    /**
136
 
     * Load data by calling DataSource's sendRequest() method under the hood.
137
 
     *
138
 
     * @method load
139
 
     * @param config {object} Optional configuration parameters:
140
 
     *
141
 
     * <dl>
142
 
     * <dt>request</dt><dd>Pass in a new request, or initialRequest is used.</dd>
143
 
     * <dt>callback</dt><dd>Pass in DataSource callback object, or the following default is used:
144
 
     *    <dl>
145
 
     *      <dt>success</dt><dd>datatable.onDataReturnInitializeTable</dd>
146
 
     *      <dt>failure</dt><dd>datatable.onDataReturnInitializeTable</dd>
147
 
     *      <dt>scope</dt><dd>datatable</dd>
148
 
     *      <dt>argument</dt><dd>datatable.getState()</dd>
149
 
     *    </dl>
150
 
     * </dd>
151
 
     * <dt>datasource</dt><dd>Pass in a new DataSource instance to override the current DataSource for this transaction.</dd>
152
 
     * </dl>
153
 
     */
154
 
    load: function(config) {
155
 
        config = config || {};
156
 
        config.request = config.request || this.get("initialRequest");
157
 
        config.callback = config.callback || {
158
 
            success: Y.bind(this.onDataReturnInitializeTable, this),
159
 
            failure: Y.bind(this.onDataReturnInitializeTable, this),
160
 
            argument: this.get("host").get("state") //TODO
161
 
        };
162
 
 
163
 
        var ds = (config.datasource || this.get("datasource"));
164
 
        if(ds) {
165
 
            ds.sendRequest(config);
166
 
        }
167
 
    },
168
 
 
169
 
    /**
170
 
     * Callback function passed to DataSource's sendRequest() method populates
171
 
     * an entire DataTable with new data, clearing previous data, if any.
172
 
     *
173
 
     * @method onDataReturnInitializeTable
174
 
     * @param e {Event.Facade} DataSource Event Facade object.
175
 
     */
176
 
    onDataReturnInitializeTable : function(e) {
177
 
        var records = (e.response && e.response.results) || [];
178
 
 
179
 
        this.get("host").set("data", records);
180
 
    }
181
 
});
182
 
 
183
 
Y.namespace("Plugin").DataTableDataSource = DataTableDataSource;
184
 
 
185
 
 
186
 
}, '3.5.0' ,{requires:['datatable-base','plugin','datasource-local']});