~ubuntu-branches/ubuntu/precise/maas/precise-updates

« back to all changes in this revision

Viewing changes to src/maasserver/static/jslibs/yui/3.4.1/build/datasource-local/datasource-local-debug.js

Tags: 1.2+bzr1373+dfsg-0ubuntu1~12.04.4
* SECURITY UPDATE: failure to authenticate downloaded content (LP: #1039513)
  - debian/patches/CVE-2013-1058.patch: Authenticate downloaded files with
    GnuPG and MD5SUM files. Thanks to Julian Edwards.
  - CVE-2013-1058
* SECURITY UPDATE: configuration options may be loaded from current working
  directory (LP: #1158425)
  - debian/patches/CVE-2013-1057-1-2.patch: Do not load configuration
    options from the current working directory. Thanks to Julian Edwards.
  - CVE-2013-1057

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
YUI 3.4.1 (build 4118)
3
 
Copyright 2011 Yahoo! Inc. All rights reserved.
4
 
Licensed under the BSD License.
5
 
http://yuilibrary.com/license/
6
 
*/
7
 
YUI.add('datasource-local', function(Y) {
8
 
 
9
 
/**
10
 
 * The DataSource utility provides a common configurable interface for widgets to
11
 
 * access a variety of data, from JavaScript arrays to online database servers.
12
 
 *
13
 
 * @module datasource
14
 
 * @main datasource
15
 
 */
16
 
    
17
 
/**
18
 
 * Provides the base DataSource implementation, which can be extended to
19
 
 * create DataSources for specific data protocols, such as the IO Utility, the
20
 
 * Get Utility, or custom functions.
21
 
 *
22
 
 * @module datasource
23
 
 * @submodule datasource-local
24
 
 */
25
 
 
26
 
/**
27
 
 * Base class for the DataSource Utility.
28
 
 * @class DataSource.Local
29
 
 * @extends Base
30
 
 * @constructor
31
 
 */    
32
 
var LANG = Y.Lang,
33
 
 
34
 
DSLocal = function() {
35
 
    DSLocal.superclass.constructor.apply(this, arguments);
36
 
};
37
 
    
38
 
    /////////////////////////////////////////////////////////////////////////////
39
 
    //
40
 
    // DataSource static properties
41
 
    //
42
 
    /////////////////////////////////////////////////////////////////////////////
43
 
Y.mix(DSLocal, {
44
 
    /**
45
 
     * Class name.
46
 
     *
47
 
     * @property NAME
48
 
     * @type String
49
 
     * @static     
50
 
     * @final
51
 
     * @value "dataSourceLocal"
52
 
     */
53
 
    NAME: "dataSourceLocal",
54
 
 
55
 
    /////////////////////////////////////////////////////////////////////////////
56
 
    //
57
 
    // DataSource Attributes
58
 
    //
59
 
    /////////////////////////////////////////////////////////////////////////////
60
 
 
61
 
    ATTRS: {
62
 
        /**
63
 
        * @attribute source
64
 
        * @description Pointer to live data.
65
 
        * @type MIXED
66
 
        * @default null        
67
 
        */
68
 
        source: {
69
 
            value: null
70
 
        }
71
 
    },
72
 
 
73
 
    /**
74
 
     * Global transaction counter.
75
 
     *
76
 
     * @property _tId
77
 
     * @type Number
78
 
     * @static
79
 
     * @private
80
 
     * @default 0
81
 
     */
82
 
    _tId: 0,
83
 
 
84
 
    /**
85
 
     * Global in-progress transaction objects.
86
 
     *
87
 
     * @property transactions
88
 
     * @type Object
89
 
     * @static
90
 
     */
91
 
    transactions: {},
92
 
 
93
 
    /**
94
 
     * Returns data to callback.
95
 
     *
96
 
     * @method issueCallback
97
 
     * @param e {EventFacade} Event Facade.
98
 
     * @param caller {DataSource} Calling DataSource instance.
99
 
     * @static
100
 
     */
101
 
    issueCallback: function (e, caller) {
102
 
        var callbacks = e.on || e.callback,
103
 
            callback = callbacks && callbacks.success,
104
 
            payload = e.details[0];
105
 
 
106
 
        payload.error = (e.error || e.response.error);
107
 
 
108
 
        if (payload.error) {
109
 
            caller.fire("error", payload);
110
 
            callback = callbacks && callbacks.failure;
111
 
        }
112
 
 
113
 
        if (callback) {
114
 
            //TODO: this should be executed from a specific context
115
 
            callback(payload);
116
 
        }
117
 
    }
118
 
});
119
 
    
120
 
Y.extend(DSLocal, Y.Base, {
121
 
    /**
122
 
    * Internal init() handler.
123
 
    *
124
 
    * @method initializer
125
 
    * @param config {Object} Config object.
126
 
    * @private        
127
 
    */
128
 
    initializer: function(config) {
129
 
        this._initEvents();
130
 
    },
131
 
 
132
 
    /**
133
 
    * This method creates all the events for this module.
134
 
    * @method _initEvents
135
 
    * @private        
136
 
    */
137
 
    _initEvents: function() {
138
 
        /**
139
 
         * Fired when a data request is received.
140
 
         *
141
 
         * @event request
142
 
         * @param e {Event.Facade} Event Facade with the following properties:
143
 
         * <dl>                          
144
 
         * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
145
 
         * <dt>request (Object)</dt> <dd>The request.</dd>
146
 
         * <dt>callback (Object)</dt> <dd>The callback object
147
 
         *   (deprecated, refer to <strong>on</strong></dd>
148
 
         * <dt>on (Object)</dt> <dd>The map of configured callback
149
 
         *   functions.</dd>
150
 
         * <dt>cfg (Object)</dt> <dd>Configuration object.</dd>
151
 
         * </dl>
152
 
         * @preventable _defRequestFn
153
 
         */
154
 
        this.publish("request", {defaultFn: Y.bind("_defRequestFn", this), queuable:true});
155
 
         
156
 
        /**
157
 
         * Fired when raw data is received.
158
 
         *
159
 
         * @event data
160
 
         * @param e {Event.Facade} Event Facade with the following properties:
161
 
         * <dl>
162
 
         * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
163
 
         * <dt>request (Object)</dt> <dd>The request.</dd>
164
 
         * <dt>callback (Object)</dt> <dd>Deprecated alias for the
165
 
         *   <strong>on</strong> property</dd>
166
 
         * <dt>on (Object)</dt> <dd>The map of configured transaction
167
 
         *   callbacks.  An object with the following properties:
168
 
         *     <dl>
169
 
         *         <dt>success (Function)</dt> <dd>Success handler.</dd>
170
 
         *         <dt>failure (Function)</dt> <dd>Failure handler.</dd>
171
 
         *     </dl>
172
 
         * </dd>
173
 
         * <dt>cfg (Object)</dt> <dd>Configuration object.</dd>
174
 
         * <dt>data (Object)</dt> <dd>Raw data.</dd>
175
 
         * </dl>
176
 
         * @preventable _defDataFn
177
 
         */
178
 
        this.publish("data", {defaultFn: Y.bind("_defDataFn", this), queuable:true});
179
 
 
180
 
        /**
181
 
         * Fired when response is returned.
182
 
         *
183
 
         * @event response
184
 
         * @param e {Event.Facade} Event Facade with the following properties:
185
 
         * <dl>
186
 
         * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
187
 
         * <dt>request (Object)</dt> <dd>The request.</dd>
188
 
         * <dt>callback (Object)</dt> <dd>Deprecated alias for the
189
 
         *   <strong>on</strong> property</dd>
190
 
         * <dt>on (Object)</dt> <dd>The map of configured transaction
191
 
         *   callbacks.  An object with the following properties:
192
 
         *     <dl>
193
 
         *         <dt>success (Function)</dt> <dd>Success handler.</dd>
194
 
         *         <dt>failure (Function)</dt> <dd>Failure handler.</dd>
195
 
         *     </dl>
196
 
         * </dd>
197
 
         * <dt>cfg (Object)</dt> <dd>Configuration object.</dd>
198
 
         * <dt>data (Object)</dt> <dd>Raw data.</dd>
199
 
         * <dt>response (Object)</dt>
200
 
         *     <dd>Normalized response object with the following properties:
201
 
         *         <dl>
202
 
         *             <dt>results (Object)</dt> <dd>Parsed results.</dd>
203
 
         *             <dt>meta (Object)</dt> <dd>Parsed meta data.</dd>
204
 
         *             <dt>error (Boolean)</dt> <dd>Error flag.</dd>
205
 
         *         </dl>
206
 
         *     </dd>
207
 
         * <dt>error</dt>
208
 
         *     <dd>Any error that occurred along the transaction lifecycle.</dd>
209
 
         * </dl>
210
 
         * @preventable _defResponseFn
211
 
         */
212
 
         this.publish("response", {defaultFn: Y.bind("_defResponseFn", this), queuable:true});
213
 
 
214
 
        /**
215
 
         * Fired when an error is encountered.
216
 
         *
217
 
         * @event error
218
 
         * @param e {Event.Facade} Event Facade with the following properties:
219
 
         * <dl>
220
 
         * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
221
 
         * <dt>request (Object)</dt> <dd>The request.</dd>
222
 
         * <dt>callback (Object)</dt> <dd>Deprecated alias for the
223
 
         *   <strong>on</strong> property</dd>
224
 
         * <dt>on (Object)</dt> <dd>The map of configured transaction
225
 
         *   callbacks.  An object with the following properties:
226
 
         *     <dl>
227
 
         *         <dt>success (Function)</dt> <dd>Success handler.</dd>
228
 
         *         <dt>failure (Function)</dt> <dd>Failure handler.</dd>
229
 
         *     </dl>
230
 
         * </dd>
231
 
         * <dt>cfg (Object)</dt> <dd>Configuration object.</dd>
232
 
         * <dt>data (Object)</dt> <dd>Raw data.</dd>
233
 
         * <dt>response (Object)</dt>
234
 
         *     <dd>Normalized response object with the following properties:
235
 
         *         <dl>
236
 
         *             <dt>results (Object)</dt> <dd>Parsed results.</dd>
237
 
         *             <dt>meta (Object)</dt> <dd>Parsed meta data.</dd>
238
 
         *             <dt>error (Object)</dt> <dd>Error object.</dd>
239
 
         *         </dl>
240
 
         *     </dd>
241
 
         * <dt>error</dt>
242
 
         *     <dd>Any error that occurred along the transaction lifecycle.</dd>
243
 
         * </dl>
244
 
         */
245
 
 
246
 
    },
247
 
 
248
 
    /**
249
 
     * Manages request/response transaction. Must fire <code>response</code>
250
 
     * event when response is received. This method should be implemented by
251
 
     * subclasses to achieve more complex behavior such as accessing remote data.
252
 
     *
253
 
     * @method _defRequestFn
254
 
     * @param e {Event.Facade} Event Facadewith the following properties:
255
 
     * <dl>
256
 
     * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
257
 
     * <dt>request (Object)</dt> <dd>The request.</dd>
258
 
     * <dt>callback (Object)</dt> <dd>Deprecated alias for the
259
 
     *   <strong>on</strong> property</dd>
260
 
     * <dt>on (Object)</dt> <dd>The map of configured transaction
261
 
     *   callbacks.  An object with the following properties:
262
 
     *     <dl>
263
 
     *         <dt>success (Function)</dt> <dd>Success handler.</dd>
264
 
     *         <dt>failure (Function)</dt> <dd>Failure handler.</dd>
265
 
     *     </dl>
266
 
     * </dd>
267
 
     * <dt>cfg (Object)</dt> <dd>Configuration object.</dd>
268
 
     * </dl>
269
 
     * @protected
270
 
     */
271
 
    _defRequestFn: function(e) {
272
 
        var data = this.get("source"),
273
 
            payload = e.details[0];
274
 
        
275
 
        // Problematic data
276
 
        if(LANG.isUndefined(data)) {
277
 
            payload.error = new Error("Local source undefined");
278
 
            Y.log("Local source undefined", "error", "datasource-local");
279
 
        }
280
 
 
281
 
        payload.data = data;
282
 
        this.fire("data", payload);
283
 
        Y.log("Transaction " + e.tId + " complete. Request: " +
284
 
                Y.dump(e.request) + " . Response: " + Y.dump(e.response), "info", "datasource-local");
285
 
    },
286
 
 
287
 
    /**
288
 
     * Normalizes raw data into a response that includes results and meta properties.
289
 
     *
290
 
     * @method _defDataFn
291
 
     * @param e {Event.Facade} Event Facade with the following properties:
292
 
     * <dl>
293
 
     * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
294
 
     * <dt>request (Object)</dt> <dd>The request.</dd>
295
 
     * <dt>callback (Object)</dt> <dd>Deprecated alias for the
296
 
     *   <strong>on</strong> property</dd>
297
 
     * <dt>on (Object)</dt> <dd>The map of configured transaction
298
 
     *   callbacks.  An object with the following properties:
299
 
     *     <dl>
300
 
     *         <dt>success (Function)</dt> <dd>Success handler.</dd>
301
 
     *         <dt>failure (Function)</dt> <dd>Failure handler.</dd>
302
 
     *     </dl>
303
 
     * </dd>
304
 
     * <dt>cfg (Object)</dt> <dd>Configuration object.</dd>
305
 
     * <dt>data (Object)</dt> <dd>Raw data.</dd>
306
 
     * </dl>
307
 
     * @protected
308
 
     */
309
 
    _defDataFn: function(e) {
310
 
        var data = e.data,
311
 
            meta = e.meta,
312
 
            response = {
313
 
                results: (LANG.isArray(data)) ? data : [data],
314
 
                meta: (meta) ? meta : {}
315
 
            },
316
 
            payload = e.details[0];
317
 
 
318
 
        payload.response = response;
319
 
        this.fire("response", payload);
320
 
    },
321
 
 
322
 
    /**
323
 
     * Sends data as a normalized response to callback.
324
 
     *
325
 
     * @method _defResponseFn
326
 
     * @param e {Event.Facade} Event Facade with the following properties:
327
 
     * <dl>
328
 
     * <dt>tId (Number)</dt> <dd>Unique transaction ID.</dd>
329
 
     * <dt>request (Object)</dt> <dd>The request.</dd>
330
 
     * <dt>callback (Object)</dt> <dd>Deprecated alias for the
331
 
     *   <strong>on</strong> property</dd>
332
 
     * <dt>on (Object)</dt> <dd>The map of configured transaction
333
 
     *   callbacks.  An object with the following properties:
334
 
     *     <dl>
335
 
     *         <dt>success (Function)</dt> <dd>Success handler.</dd>
336
 
     *         <dt>failure (Function)</dt> <dd>Failure handler.</dd>
337
 
     *     </dl>
338
 
     * </dd>
339
 
     * <dt>cfg (Object)</dt> <dd>Configuration object.</dd>
340
 
     * <dt>data (Object)</dt> <dd>Raw data.</dd>
341
 
     * <dt>response (Object)</dt> <dd>Normalized response object with the following properties:
342
 
     *     <dl>
343
 
     *         <dt>results (Object)</dt> <dd>Parsed results.</dd>
344
 
     *         <dt>meta (Object)</dt> <dd>Parsed meta data.</dd>
345
 
     *         <dt>error (Boolean)</dt> <dd>Error flag.</dd>
346
 
     *     </dl>
347
 
     * </dd>
348
 
     * </dl>
349
 
     * @protected
350
 
     */
351
 
    _defResponseFn: function(e) {
352
 
        // Send the response back to the callback
353
 
        DSLocal.issueCallback(e, this);
354
 
    },
355
 
    
356
 
    /**
357
 
     * Generates a unique transaction ID and fires <code>request</code> event.
358
 
     * <strong>Note</strong>: the property <code>callback</code> is a
359
 
     * deprecated alias for the <code>on</code> transaction configuration
360
 
     * property described below.
361
 
     *
362
 
     * @method sendRequest
363
 
     * @param request {Object} An object literal with the following properties:
364
 
     *     <dl>
365
 
     *     <dt><code>request</code></dt>
366
 
     *     <dd>The request to send to the live data source, if any.</dd>
367
 
     *     <dt><code>on</code></dt>
368
 
     *     <dd>An object literal with the following properties:
369
 
     *         <dl>
370
 
     *         <dt><code>success</code></dt>
371
 
     *         <dd>The function to call when the data is ready.</dd>
372
 
     *         <dt><code>failure</code></dt>
373
 
     *         <dd>The function to call upon a response failure condition.</dd>
374
 
     *         <dt><code>argument</code></dt>
375
 
     *         <dd>Arbitrary data payload that will be passed back to the success and failure handlers.</dd>
376
 
     *         </dl>
377
 
     *     </dd>
378
 
     *     <dt><code>cfg</code></dt>
379
 
     *     <dd>Configuration object, if any.</dd>
380
 
     *     </dl>
381
 
     * @return {Number} Transaction ID.
382
 
     */
383
 
    sendRequest: function(request) {
384
 
        var tId = DSLocal._tId++,
385
 
            callbacks;
386
 
 
387
 
        request = request || {};
388
 
 
389
 
        callbacks = request.on || request.callback;
390
 
 
391
 
        this.fire("request", {
392
 
            tId: tId,
393
 
            request: request.request,
394
 
            on: callbacks,
395
 
            callback: callbacks,
396
 
            cfg: request.cfg || {}
397
 
        });
398
 
 
399
 
        Y.log("Transaction " + tId + " sent request: " + Y.dump(request.request), "info", "datasource-local");
400
 
 
401
 
        return tId;
402
 
    }
403
 
});
404
 
    
405
 
Y.namespace("DataSource").Local = DSLocal;
406
 
 
407
 
 
408
 
}, '3.4.1' ,{requires:['base']});