~canonical-ci-engineering/ubuntu-ci-services-itself/graphite-web

« back to all changes in this revision

Viewing changes to webapp/content/js/ext/pkgs/data-json-debug.js

  • Committer: Package Import Robot
  • Author(s): Jonas Genannt
  • Date: 2013-03-09 16:06:34 UTC
  • Revision ID: package-import@ubuntu.com-20130309160634-p1ei8oxvm3plrbas
Tags: upstream-0.9.10+debian
ImportĀ upstreamĀ versionĀ 0.9.10+debian

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*!
 
2
 * Ext JS Library 3.3.1
 
3
 * Copyright(c) 2006-2010 Sencha Inc.
 
4
 * licensing@sencha.com
 
5
 * http://www.sencha.com/license
 
6
 */
 
7
/**
 
8
 * @class Ext.data.JsonWriter
 
9
 * @extends Ext.data.DataWriter
 
10
 * DataWriter extension for writing an array or single {@link Ext.data.Record} object(s) in preparation for executing a remote CRUD action.
 
11
 */
 
12
Ext.data.JsonWriter = Ext.extend(Ext.data.DataWriter, {
 
13
    /**
 
14
     * @cfg {Boolean} encode <p><tt>true</tt> to {@link Ext.util.JSON#encode JSON encode} the
 
15
     * {@link Ext.data.DataWriter#toHash hashed data} into a standard HTTP parameter named after this
 
16
     * Reader's <code>meta.root</code> property which, by default is imported from the associated Reader. Defaults to <tt>true</tt>.</p>
 
17
     * <p>If set to <code>false</code>, the hashed data is {@link Ext.util.JSON#encode JSON encoded}, along with
 
18
     * the associated {@link Ext.data.Store}'s {@link Ext.data.Store#baseParams baseParams}, into the POST body.</p>
 
19
     * <p>When using {@link Ext.data.DirectProxy}, set this to <tt>false</tt> since Ext.Direct.JsonProvider will perform
 
20
     * its own json-encoding.  In addition, if you're using {@link Ext.data.HttpProxy}, setting to <tt>false</tt>
 
21
     * will cause HttpProxy to transmit data using the <b>jsonData</b> configuration-params of {@link Ext.Ajax#request}
 
22
     * instead of <b>params</b>.</p>
 
23
     * <p>When using a {@link Ext.data.Store#restful} Store, some serverside frameworks are
 
24
     * tuned to expect data through the jsonData mechanism.  In those cases, one will want to set <b>encode: <tt>false</tt></b>, as in
 
25
     * let the lower-level connection object (eg: Ext.Ajax) do the encoding.</p>
 
26
     */
 
27
    encode : true,
 
28
    /**
 
29
     * @cfg {Boolean} encodeDelete False to send only the id to the server on delete, true to encode it in an object
 
30
     * literal, eg: <pre><code>
 
31
{id: 1}
 
32
 * </code></pre> Defaults to <tt>false</tt>
 
33
     */
 
34
    encodeDelete: false,
 
35
    
 
36
    constructor : function(config){
 
37
        Ext.data.JsonWriter.superclass.constructor.call(this, config);    
 
38
    },
 
39
 
 
40
    /**
 
41
     * <p>This method should not need to be called by application code, however it may be useful on occasion to
 
42
     * override it, or augment it with an {@link Function#createInterceptor interceptor} or {@link Function#createSequence sequence}.</p>
 
43
     * <p>The provided implementation encodes the serialized data representing the Store's modified Records into the Ajax request's
 
44
     * <code>params</code> according to the <code>{@link #encode}</code> setting.</p>
 
45
     * @param {Object} Ajax request params object to write into.
 
46
     * @param {Object} baseParams as defined by {@link Ext.data.Store#baseParams}.  The baseParms must be encoded by the extending class, eg: {@link Ext.data.JsonWriter}, {@link Ext.data.XmlWriter}.
 
47
     * @param {Object/Object[]} data Data object representing the serialized modified records from the Store. May be either a single object,
 
48
     * or an Array of objects - user implementations must handle both cases.
 
49
     */
 
50
    render : function(params, baseParams, data) {
 
51
        if (this.encode === true) {
 
52
            // Encode here now.
 
53
            Ext.apply(params, baseParams);
 
54
            params[this.meta.root] = Ext.encode(data);
 
55
        } else {
 
56
            // defer encoding for some other layer, probably in {@link Ext.Ajax#request}.  Place everything into "jsonData" key.
 
57
            var jdata = Ext.apply({}, baseParams);
 
58
            jdata[this.meta.root] = data;
 
59
            params.jsonData = jdata;
 
60
        }
 
61
    },
 
62
    /**
 
63
     * Implements abstract Ext.data.DataWriter#createRecord
 
64
     * @protected
 
65
     * @param {Ext.data.Record} rec
 
66
     * @return {Object}
 
67
     */
 
68
    createRecord : function(rec) {
 
69
       return this.toHash(rec);
 
70
    },
 
71
    /**
 
72
     * Implements abstract Ext.data.DataWriter#updateRecord
 
73
     * @protected
 
74
     * @param {Ext.data.Record} rec
 
75
     * @return {Object}
 
76
     */
 
77
    updateRecord : function(rec) {
 
78
        return this.toHash(rec);
 
79
 
 
80
    },
 
81
    /**
 
82
     * Implements abstract Ext.data.DataWriter#destroyRecord
 
83
     * @protected
 
84
     * @param {Ext.data.Record} rec
 
85
     * @return {Object}
 
86
     */
 
87
    destroyRecord : function(rec){
 
88
        if(this.encodeDelete){
 
89
            var data = {};
 
90
            data[this.meta.idProperty] = rec.id;
 
91
            return data;
 
92
        }else{
 
93
            return rec.id;
 
94
        }
 
95
    }
 
96
});/**
 
97
 * @class Ext.data.JsonReader
 
98
 * @extends Ext.data.DataReader
 
99
 * <p>Data reader class to create an Array of {@link Ext.data.Record} objects
 
100
 * from a JSON packet based on mappings in a provided {@link Ext.data.Record}
 
101
 * constructor.</p>
 
102
 * <p>Example code:</p>
 
103
 * <pre><code>
 
104
var myReader = new Ext.data.JsonReader({
 
105
    // metadata configuration options:
 
106
    {@link #idProperty}: 'id'
 
107
    {@link #root}: 'rows',
 
108
    {@link #totalProperty}: 'results',
 
109
    {@link Ext.data.DataReader#messageProperty}: "msg"  // The element within the response that provides a user-feedback message (optional)
 
110
 
 
111
    // the fields config option will internally create an {@link Ext.data.Record}
 
112
    // constructor that provides mapping for reading the record data objects
 
113
    {@link Ext.data.DataReader#fields fields}: [
 
114
        // map Record&#39;s 'firstname' field to data object&#39;s key of same name
 
115
        {name: 'name', mapping: 'firstname'},
 
116
        // map Record&#39;s 'job' field to data object&#39;s 'occupation' key
 
117
        {name: 'job', mapping: 'occupation'}
 
118
    ]
 
119
});
 
120
</code></pre>
 
121
 * <p>This would consume a JSON data object of the form:</p><pre><code>
 
122
{
 
123
    results: 2000, // Reader&#39;s configured {@link #totalProperty}
 
124
    rows: [        // Reader&#39;s configured {@link #root}
 
125
        // record data objects:
 
126
        { {@link #idProperty id}: 1, firstname: 'Bill', occupation: 'Gardener' },
 
127
        { {@link #idProperty id}: 2, firstname: 'Ben' , occupation: 'Horticulturalist' },
 
128
        ...
 
129
    ]
 
130
}
 
131
</code></pre>
 
132
 * <p><b><u>Automatic configuration using metaData</u></b></p>
 
133
 * <p>It is possible to change a JsonReader's metadata at any time by including
 
134
 * a <b><tt>metaData</tt></b> property in the JSON data object. If the JSON data
 
135
 * object has a <b><tt>metaData</tt></b> property, a {@link Ext.data.Store Store}
 
136
 * object using this Reader will reconfigure itself to use the newly provided
 
137
 * field definition and fire its {@link Ext.data.Store#metachange metachange}
 
138
 * event. The metachange event handler may interrogate the <b><tt>metaData</tt></b>
 
139
 * property to perform any configuration required.</p>
 
140
 * <p>Note that reconfiguring a Store potentially invalidates objects which may
 
141
 * refer to Fields or Records which no longer exist.</p>
 
142
 * <p>To use this facility you would create the JsonReader like this:</p><pre><code>
 
143
var myReader = new Ext.data.JsonReader();
 
144
</code></pre>
 
145
 * <p>The first data packet from the server would configure the reader by
 
146
 * containing a <b><tt>metaData</tt></b> property <b>and</b> the data. For
 
147
 * example, the JSON data object might take the form:</p><pre><code>
 
148
{
 
149
    metaData: {
 
150
        "{@link #idProperty}": "id",
 
151
        "{@link #root}": "rows",
 
152
        "{@link #totalProperty}": "results"
 
153
        "{@link #successProperty}": "success",
 
154
        "{@link Ext.data.DataReader#fields fields}": [
 
155
            {"name": "name"},
 
156
            {"name": "job", "mapping": "occupation"}
 
157
        ],
 
158
        // used by store to set its sortInfo
 
159
        "sortInfo":{
 
160
           "field": "name",
 
161
           "direction": "ASC"
 
162
        },
 
163
        // {@link Ext.PagingToolbar paging data} (if applicable)
 
164
        "start": 0,
 
165
        "limit": 2,
 
166
        // custom property
 
167
        "foo": "bar"
 
168
    },
 
169
    // Reader&#39;s configured {@link #successProperty}
 
170
    "success": true,
 
171
    // Reader&#39;s configured {@link #totalProperty}
 
172
    "results": 2000,
 
173
    // Reader&#39;s configured {@link #root}
 
174
    // (this data simulates 2 results {@link Ext.PagingToolbar per page})
 
175
    "rows": [ // <b>*Note:</b> this must be an Array
 
176
        { "id": 1, "name": "Bill", "occupation": "Gardener" },
 
177
        { "id": 2, "name":  "Ben", "occupation": "Horticulturalist" }
 
178
    ]
 
179
}
 
180
 * </code></pre>
 
181
 * <p>The <b><tt>metaData</tt></b> property in the JSON data object should contain:</p>
 
182
 * <div class="mdetail-params"><ul>
 
183
 * <li>any of the configuration options for this class</li>
 
184
 * <li>a <b><tt>{@link Ext.data.Record#fields fields}</tt></b> property which
 
185
 * the JsonReader will use as an argument to the
 
186
 * {@link Ext.data.Record#create data Record create method} in order to
 
187
 * configure the layout of the Records it will produce.</li>
 
188
 * <li>a <b><tt>{@link Ext.data.Store#sortInfo sortInfo}</tt></b> property
 
189
 * which the JsonReader will use to set the {@link Ext.data.Store}'s
 
190
 * {@link Ext.data.Store#sortInfo sortInfo} property</li>
 
191
 * <li>any custom properties needed</li>
 
192
 * </ul></div>
 
193
 *
 
194
 * @constructor
 
195
 * Create a new JsonReader
 
196
 * @param {Object} meta Metadata configuration options.
 
197
 * @param {Array/Object} recordType
 
198
 * <p>Either an Array of {@link Ext.data.Field Field} definition objects (which
 
199
 * will be passed to {@link Ext.data.Record#create}, or a {@link Ext.data.Record Record}
 
200
 * constructor created from {@link Ext.data.Record#create}.</p>
 
201
 */
 
202
Ext.data.JsonReader = function(meta, recordType){
 
203
    meta = meta || {};
 
204
    /**
 
205
     * @cfg {String} idProperty [id] Name of the property within a row object
 
206
     * that contains a record identifier value.  Defaults to <tt>id</tt>
 
207
     */
 
208
    /**
 
209
     * @cfg {String} successProperty [success] Name of the property from which to
 
210
     * retrieve the success attribute. Defaults to <tt>success</tt>.  See
 
211
     * {@link Ext.data.DataProxy}.{@link Ext.data.DataProxy#exception exception}
 
212
     * for additional information.
 
213
     */
 
214
    /**
 
215
     * @cfg {String} totalProperty [total] Name of the property from which to
 
216
     * retrieve the total number of records in the dataset. This is only needed
 
217
     * if the whole dataset is not passed in one go, but is being paged from
 
218
     * the remote server.  Defaults to <tt>total</tt>.
 
219
     */
 
220
    /**
 
221
     * @cfg {String} root [undefined] <b>Required</b>.  The name of the property
 
222
     * which contains the Array of row objects.  Defaults to <tt>undefined</tt>.
 
223
     * An exception will be thrown if the root property is undefined. The data
 
224
     * packet value for this property should be an empty array to clear the data
 
225
     * or show no data.
 
226
     */
 
227
    Ext.applyIf(meta, {
 
228
        idProperty: 'id',
 
229
        successProperty: 'success',
 
230
        totalProperty: 'total'
 
231
    });
 
232
 
 
233
    Ext.data.JsonReader.superclass.constructor.call(this, meta, recordType || meta.fields);
 
234
};
 
235
Ext.extend(Ext.data.JsonReader, Ext.data.DataReader, {
 
236
    /**
 
237
     * This JsonReader's metadata as passed to the constructor, or as passed in
 
238
     * the last data packet's <b><tt>metaData</tt></b> property.
 
239
     * @type Mixed
 
240
     * @property meta
 
241
     */
 
242
    /**
 
243
     * This method is only used by a DataProxy which has retrieved data from a remote server.
 
244
     * @param {Object} response The XHR object which contains the JSON data in its responseText.
 
245
     * @return {Object} data A data block which is used by an Ext.data.Store object as
 
246
     * a cache of Ext.data.Records.
 
247
     */
 
248
    read : function(response){
 
249
        var json = response.responseText;
 
250
        var o = Ext.decode(json);
 
251
        if(!o) {
 
252
            throw {message: 'JsonReader.read: Json object not found'};
 
253
        }
 
254
        return this.readRecords(o);
 
255
    },
 
256
 
 
257
    /*
 
258
     * TODO: refactor code between JsonReader#readRecords, #readResponse into 1 method.
 
259
     * there's ugly duplication going on due to maintaining backwards compat. with 2.0.  It's time to do this.
 
260
     */
 
261
    /**
 
262
     * Decode a JSON response from server.
 
263
     * @param {String} action [Ext.data.Api.actions.create|read|update|destroy]
 
264
     * @param {Object} response The XHR object returned through an Ajax server request.
 
265
     * @return {Response} A {@link Ext.data.Response Response} object containing the data response, and also status information.
 
266
     */
 
267
    readResponse : function(action, response) {
 
268
        var o = (response.responseText !== undefined) ? Ext.decode(response.responseText) : response;
 
269
        if(!o) {
 
270
            throw new Ext.data.JsonReader.Error('response');
 
271
        }
 
272
 
 
273
        var root = this.getRoot(o);
 
274
        if (action === Ext.data.Api.actions.create) {
 
275
            var def = Ext.isDefined(root);
 
276
            if (def && Ext.isEmpty(root)) {
 
277
                throw new Ext.data.JsonReader.Error('root-empty', this.meta.root);
 
278
            }
 
279
            else if (!def) {
 
280
                throw new Ext.data.JsonReader.Error('root-undefined-response', this.meta.root);
 
281
            }
 
282
        }
 
283
 
 
284
        // instantiate response object
 
285
        var res = new Ext.data.Response({
 
286
            action: action,
 
287
            success: this.getSuccess(o),
 
288
            data: (root) ? this.extractData(root, false) : [],
 
289
            message: this.getMessage(o),
 
290
            raw: o
 
291
        });
 
292
 
 
293
        // blow up if no successProperty
 
294
        if (Ext.isEmpty(res.success)) {
 
295
            throw new Ext.data.JsonReader.Error('successProperty-response', this.meta.successProperty);
 
296
        }
 
297
        return res;
 
298
    },
 
299
 
 
300
    /**
 
301
     * Create a data block containing Ext.data.Records from a JSON object.
 
302
     * @param {Object} o An object which contains an Array of row objects in the property specified
 
303
     * in the config as 'root, and optionally a property, specified in the config as 'totalProperty'
 
304
     * which contains the total size of the dataset.
 
305
     * @return {Object} data A data block which is used by an Ext.data.Store object as
 
306
     * a cache of Ext.data.Records.
 
307
     */
 
308
    readRecords : function(o){
 
309
        /**
 
310
         * After any data loads, the raw JSON data is available for further custom processing.  If no data is
 
311
         * loaded or there is a load exception this property will be undefined.
 
312
         * @type Object
 
313
         */
 
314
        this.jsonData = o;
 
315
        if(o.metaData){
 
316
            this.onMetaChange(o.metaData);
 
317
        }
 
318
        var s = this.meta, Record = this.recordType,
 
319
            f = Record.prototype.fields, fi = f.items, fl = f.length, v;
 
320
 
 
321
        var root = this.getRoot(o), c = root.length, totalRecords = c, success = true;
 
322
        if(s.totalProperty){
 
323
            v = parseInt(this.getTotal(o), 10);
 
324
            if(!isNaN(v)){
 
325
                totalRecords = v;
 
326
            }
 
327
        }
 
328
        if(s.successProperty){
 
329
            v = this.getSuccess(o);
 
330
            if(v === false || v === 'false'){
 
331
                success = false;
 
332
            }
 
333
        }
 
334
 
 
335
        // TODO return Ext.data.Response instance instead.  @see #readResponse
 
336
        return {
 
337
            success : success,
 
338
            records : this.extractData(root, true), // <-- true to return [Ext.data.Record]
 
339
            totalRecords : totalRecords
 
340
        };
 
341
    },
 
342
 
 
343
    // private
 
344
    buildExtractors : function() {
 
345
        if(this.ef){
 
346
            return;
 
347
        }
 
348
        var s = this.meta, Record = this.recordType,
 
349
            f = Record.prototype.fields, fi = f.items, fl = f.length;
 
350
 
 
351
        if(s.totalProperty) {
 
352
            this.getTotal = this.createAccessor(s.totalProperty);
 
353
        }
 
354
        if(s.successProperty) {
 
355
            this.getSuccess = this.createAccessor(s.successProperty);
 
356
        }
 
357
        if (s.messageProperty) {
 
358
            this.getMessage = this.createAccessor(s.messageProperty);
 
359
        }
 
360
        this.getRoot = s.root ? this.createAccessor(s.root) : function(p){return p;};
 
361
        if (s.id || s.idProperty) {
 
362
            var g = this.createAccessor(s.id || s.idProperty);
 
363
            this.getId = function(rec) {
 
364
                var r = g(rec);
 
365
                return (r === undefined || r === '') ? null : r;
 
366
            };
 
367
        } else {
 
368
            this.getId = function(){return null;};
 
369
        }
 
370
        var ef = [];
 
371
        for(var i = 0; i < fl; i++){
 
372
            f = fi[i];
 
373
            var map = (f.mapping !== undefined && f.mapping !== null) ? f.mapping : f.name;
 
374
            ef.push(this.createAccessor(map));
 
375
        }
 
376
        this.ef = ef;
 
377
    },
 
378
 
 
379
    /**
 
380
     * @ignore
 
381
     * TODO This isn't used anywhere??  Don't we want to use this where possible instead of complex #createAccessor?
 
382
     */
 
383
    simpleAccess : function(obj, subsc) {
 
384
        return obj[subsc];
 
385
    },
 
386
 
 
387
    /**
 
388
     * @ignore
 
389
     */
 
390
    createAccessor : function(){
 
391
        var re = /[\[\.]/;
 
392
        return function(expr) {
 
393
            if(Ext.isEmpty(expr)){
 
394
                return Ext.emptyFn;
 
395
            }
 
396
            if(Ext.isFunction(expr)){
 
397
                return expr;
 
398
            }
 
399
            var i = String(expr).search(re);
 
400
            if(i >= 0){
 
401
                return new Function('obj', 'return obj' + (i > 0 ? '.' : '') + expr);
 
402
            }
 
403
            return function(obj){
 
404
                return obj[expr];
 
405
            };
 
406
 
 
407
        };
 
408
    }(),
 
409
 
 
410
    /**
 
411
     * type-casts a single row of raw-data from server
 
412
     * @param {Object} data
 
413
     * @param {Array} items
 
414
     * @param {Integer} len
 
415
     * @private
 
416
     */
 
417
    extractValues : function(data, items, len) {
 
418
        var f, values = {};
 
419
        for(var j = 0; j < len; j++){
 
420
            f = items[j];
 
421
            var v = this.ef[j](data);
 
422
            values[f.name] = f.convert((v !== undefined) ? v : f.defaultValue, data);
 
423
        }
 
424
        return values;
 
425
    }
 
426
});
 
427
 
 
428
/**
 
429
 * @class Ext.data.JsonReader.Error
 
430
 * Error class for JsonReader
 
431
 */
 
432
Ext.data.JsonReader.Error = Ext.extend(Ext.Error, {
 
433
    constructor : function(message, arg) {
 
434
        this.arg = arg;
 
435
        Ext.Error.call(this, message);
 
436
    },
 
437
    name : 'Ext.data.JsonReader'
 
438
});
 
439
Ext.apply(Ext.data.JsonReader.Error.prototype, {
 
440
    lang: {
 
441
        'response': 'An error occurred while json-decoding your server response',
 
442
        'successProperty-response': 'Could not locate your "successProperty" in your server response.  Please review your JsonReader config to ensure the config-property "successProperty" matches the property in your server-response.  See the JsonReader docs.',
 
443
        'root-undefined-config': 'Your JsonReader was configured without a "root" property.  Please review your JsonReader config and make sure to define the root property.  See the JsonReader docs.',
 
444
        'idProperty-undefined' : 'Your JsonReader was configured without an "idProperty"  Please review your JsonReader configuration and ensure the "idProperty" is set (e.g.: "id").  See the JsonReader docs.',
 
445
        'root-empty': 'Data was expected to be returned by the server in the "root" property of the response.  Please review your JsonReader configuration to ensure the "root" property matches that returned in the server-response.  See JsonReader docs.'
 
446
    }
 
447
});
 
448
/**
 
449
 * @class Ext.data.ArrayReader
 
450
 * @extends Ext.data.JsonReader
 
451
 * <p>Data reader class to create an Array of {@link Ext.data.Record} objects from an Array.
 
452
 * Each element of that Array represents a row of data fields. The
 
453
 * fields are pulled into a Record object using as a subscript, the <code>mapping</code> property
 
454
 * of the field definition if it exists, or the field's ordinal position in the definition.</p>
 
455
 * <p>Example code:</p>
 
456
 * <pre><code>
 
457
var Employee = Ext.data.Record.create([
 
458
    {name: 'name', mapping: 1},         // "mapping" only needed if an "id" field is present which
 
459
    {name: 'occupation', mapping: 2}    // precludes using the ordinal position as the index.
 
460
]);
 
461
var myReader = new Ext.data.ArrayReader({
 
462
    {@link #idIndex}: 0
 
463
}, Employee);
 
464
</code></pre>
 
465
 * <p>This would consume an Array like this:</p>
 
466
 * <pre><code>
 
467
[ [1, 'Bill', 'Gardener'], [2, 'Ben', 'Horticulturalist'] ]
 
468
 * </code></pre>
 
469
 * @constructor
 
470
 * Create a new ArrayReader
 
471
 * @param {Object} meta Metadata configuration options.
 
472
 * @param {Array/Object} recordType
 
473
 * <p>Either an Array of {@link Ext.data.Field Field} definition objects (which
 
474
 * will be passed to {@link Ext.data.Record#create}, or a {@link Ext.data.Record Record}
 
475
 * constructor created from {@link Ext.data.Record#create}.</p>
 
476
 */
 
477
Ext.data.ArrayReader = Ext.extend(Ext.data.JsonReader, {
 
478
    /**
 
479
     * @cfg {String} successProperty
 
480
     * @hide
 
481
     */
 
482
    /**
 
483
     * @cfg {Number} id (optional) The subscript within row Array that provides an ID for the Record.
 
484
     * Deprecated. Use {@link #idIndex} instead.
 
485
     */
 
486
    /**
 
487
     * @cfg {Number} idIndex (optional) The subscript within row Array that provides an ID for the Record.
 
488
     */
 
489
    /**
 
490
     * Create a data block containing Ext.data.Records from an Array.
 
491
     * @param {Object} o An Array of row objects which represents the dataset.
 
492
     * @return {Object} data A data block which is used by an Ext.data.Store object as
 
493
     * a cache of Ext.data.Records.
 
494
     */
 
495
    readRecords : function(o){
 
496
        this.arrayData = o;
 
497
        var s = this.meta,
 
498
            sid = s ? Ext.num(s.idIndex, s.id) : null,
 
499
            recordType = this.recordType,
 
500
            fields = recordType.prototype.fields,
 
501
            records = [],
 
502
            success = true,
 
503
            v;
 
504
 
 
505
        var root = this.getRoot(o);
 
506
 
 
507
        for(var i = 0, len = root.length; i < len; i++) {
 
508
            var n = root[i],
 
509
                values = {},
 
510
                id = ((sid || sid === 0) && n[sid] !== undefined && n[sid] !== "" ? n[sid] : null);
 
511
            for(var j = 0, jlen = fields.length; j < jlen; j++) {
 
512
                var f = fields.items[j],
 
513
                    k = f.mapping !== undefined && f.mapping !== null ? f.mapping : j;
 
514
                v = n[k] !== undefined ? n[k] : f.defaultValue;
 
515
                v = f.convert(v, n);
 
516
                values[f.name] = v;
 
517
            }
 
518
            var record = new recordType(values, id);
 
519
            record.json = n;
 
520
            records[records.length] = record;
 
521
        }
 
522
 
 
523
        var totalRecords = records.length;
 
524
 
 
525
        if(s.totalProperty) {
 
526
            v = parseInt(this.getTotal(o), 10);
 
527
            if(!isNaN(v)) {
 
528
                totalRecords = v;
 
529
            }
 
530
        }
 
531
        if(s.successProperty){
 
532
            v = this.getSuccess(o);
 
533
            if(v === false || v === 'false'){
 
534
                success = false;
 
535
            }
 
536
        }
 
537
 
 
538
        return {
 
539
            success : success,
 
540
            records : records,
 
541
            totalRecords : totalRecords
 
542
        };
 
543
    }
 
544
});/**
 
545
 * @class Ext.data.ArrayStore
 
546
 * @extends Ext.data.Store
 
547
 * <p>Formerly known as "SimpleStore".</p>
 
548
 * <p>Small helper class to make creating {@link Ext.data.Store}s from Array data easier.
 
549
 * An ArrayStore will be automatically configured with a {@link Ext.data.ArrayReader}.</p>
 
550
 * <p>A store configuration would be something like:<pre><code>
 
551
var store = new Ext.data.ArrayStore({
 
552
    // store configs
 
553
    autoDestroy: true,
 
554
    storeId: 'myStore',
 
555
    // reader configs
 
556
    idIndex: 0,  
 
557
    fields: [
 
558
       'company',
 
559
       {name: 'price', type: 'float'},
 
560
       {name: 'change', type: 'float'},
 
561
       {name: 'pctChange', type: 'float'},
 
562
       {name: 'lastChange', type: 'date', dateFormat: 'n/j h:ia'}
 
563
    ]
 
564
});
 
565
 * </code></pre></p>
 
566
 * <p>This store is configured to consume a returned object of the form:<pre><code>
 
567
var myData = [
 
568
    ['3m Co',71.72,0.02,0.03,'9/1 12:00am'],
 
569
    ['Alcoa Inc',29.01,0.42,1.47,'9/1 12:00am'],
 
570
    ['Boeing Co.',75.43,0.53,0.71,'9/1 12:00am'],
 
571
    ['Hewlett-Packard Co.',36.53,-0.03,-0.08,'9/1 12:00am'],
 
572
    ['Wal-Mart Stores, Inc.',45.45,0.73,1.63,'9/1 12:00am']
 
573
];
 
574
 * </code></pre>
 
575
 * An object literal of this form could also be used as the {@link #data} config option.</p>
 
576
 * <p><b>*Note:</b> Although not listed here, this class accepts all of the configuration options of 
 
577
 * <b>{@link Ext.data.ArrayReader ArrayReader}</b>.</p>
 
578
 * @constructor
 
579
 * @param {Object} config
 
580
 * @xtype arraystore
 
581
 */
 
582
Ext.data.ArrayStore = Ext.extend(Ext.data.Store, {
 
583
    /**
 
584
     * @cfg {Ext.data.DataReader} reader @hide
 
585
     */
 
586
    constructor: function(config){
 
587
        Ext.data.ArrayStore.superclass.constructor.call(this, Ext.apply(config, {
 
588
            reader: new Ext.data.ArrayReader(config)
 
589
        }));
 
590
    },
 
591
 
 
592
    loadData : function(data, append){
 
593
        if(this.expandData === true){
 
594
            var r = [];
 
595
            for(var i = 0, len = data.length; i < len; i++){
 
596
                r[r.length] = [data[i]];
 
597
            }
 
598
            data = r;
 
599
        }
 
600
        Ext.data.ArrayStore.superclass.loadData.call(this, data, append);
 
601
    }
 
602
});
 
603
Ext.reg('arraystore', Ext.data.ArrayStore);
 
604
 
 
605
// backwards compat
 
606
Ext.data.SimpleStore = Ext.data.ArrayStore;
 
607
Ext.reg('simplestore', Ext.data.SimpleStore);/**
 
608
 * @class Ext.data.JsonStore
 
609
 * @extends Ext.data.Store
 
610
 * <p>Small helper class to make creating {@link Ext.data.Store}s from JSON data easier.
 
611
 * A JsonStore will be automatically configured with a {@link Ext.data.JsonReader}.</p>
 
612
 * <p>A store configuration would be something like:<pre><code>
 
613
var store = new Ext.data.JsonStore({
 
614
    // store configs
 
615
    autoDestroy: true,
 
616
    url: 'get-images.php',
 
617
    storeId: 'myStore',
 
618
    // reader configs
 
619
    root: 'images',
 
620
    idProperty: 'name',
 
621
    fields: ['name', 'url', {name:'size', type: 'float'}, {name:'lastmod', type:'date'}]
 
622
});
 
623
 * </code></pre></p>
 
624
 * <p>This store is configured to consume a returned object of the form:<pre><code>
 
625
{
 
626
    images: [
 
627
        {name: 'Image one', url:'/GetImage.php?id=1', size:46.5, lastmod: new Date(2007, 10, 29)},
 
628
        {name: 'Image Two', url:'/GetImage.php?id=2', size:43.2, lastmod: new Date(2007, 10, 30)}
 
629
    ]
 
630
}
 
631
 * </code></pre>
 
632
 * An object literal of this form could also be used as the {@link #data} config option.</p>
 
633
 * <p><b>*Note:</b> Although not listed here, this class accepts all of the configuration options of
 
634
 * <b>{@link Ext.data.JsonReader JsonReader}</b>.</p>
 
635
 * @constructor
 
636
 * @param {Object} config
 
637
 * @xtype jsonstore
 
638
 */
 
639
Ext.data.JsonStore = Ext.extend(Ext.data.Store, {
 
640
    /**
 
641
     * @cfg {Ext.data.DataReader} reader @hide
 
642
     */
 
643
    constructor: function(config){
 
644
        Ext.data.JsonStore.superclass.constructor.call(this, Ext.apply(config, {
 
645
            reader: new Ext.data.JsonReader(config)
 
646
        }));
 
647
    }
 
648
});
 
649
Ext.reg('jsonstore', Ext.data.JsonStore);
 
 
b'\\ No newline at end of file'