Forked mumble-django project from https://bitbucket.org/Svedrin/mumble-django
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

640 lines
24 KiB

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