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.

648 lines
26 KiB

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