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.

82 lines
3.5 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. This file is part of Ext JS 3.4
  3. Copyright (c) 2011-2013 Sencha Inc
  4. Contact: http://www.sencha.com/contact
  5. GNU General Public License Usage
  6. This file may be used under the terms of the GNU General Public License version 3.0 as
  7. published by the Free Software Foundation and appearing in the file LICENSE included in the
  8. packaging of this file.
  9. Please review the following information to ensure the GNU General Public License version 3.0
  10. requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  11. If you are unsure which license is appropriate for your use, please contact the sales department
  12. at http://www.sencha.com/contact.
  13. Build date: 2013-04-03 15:07:25
  14. */
  15. /**
  16. * @class Ext.data.MemoryProxy
  17. * @extends Ext.data.DataProxy
  18. * An implementation of Ext.data.DataProxy that simply passes the data specified in its constructor
  19. * to the Reader when its load method is called.
  20. * @constructor
  21. * @param {Object} data The data object which the Reader uses to construct a block of Ext.data.Records.
  22. */
  23. Ext.data.MemoryProxy = function(data){
  24. // Must define a dummy api with "read" action to satisfy DataProxy#doRequest and Ext.data.Api#prepare *before* calling super
  25. var api = {};
  26. api[Ext.data.Api.actions.read] = true;
  27. Ext.data.MemoryProxy.superclass.constructor.call(this, {
  28. api: api
  29. });
  30. this.data = data;
  31. };
  32. Ext.extend(Ext.data.MemoryProxy, Ext.data.DataProxy, {
  33. /**
  34. * @event loadexception
  35. * Fires if an exception occurs in the Proxy during data loading. Note that this event is also relayed
  36. * through {@link Ext.data.Store}, so you can listen for it directly on any Store instance.
  37. * @param {Object} this
  38. * @param {Object} arg The callback's arg object passed to the {@link #load} function
  39. * @param {Object} null This parameter does not apply and will always be null for MemoryProxy
  40. * @param {Error} e The JavaScript Error object caught if the configured Reader could not read the data
  41. */
  42. /**
  43. * MemoryProxy implementation of DataProxy#doRequest
  44. * @param {String} action
  45. * @param {Ext.data.Record/Ext.data.Record[]} rs If action is load, rs will be null
  46. * @param {Object} params An object containing properties which are to be used as HTTP parameters
  47. * for the request to the remote server.
  48. * @param {Ext.data.DataReader} reader The Reader object which converts the data
  49. * object into a block of Ext.data.Records.
  50. * @param {Function} callback The function into which to pass the block of Ext.data.Records.
  51. * The function must be passed <ul>
  52. * <li>The Record block object</li>
  53. * <li>The "arg" argument from the load function</li>
  54. * <li>A boolean success indicator</li>
  55. * </ul>
  56. * @param {Object} scope The scope (<code>this</code> reference) in which the callback function is executed. Defaults to the browser window.
  57. * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
  58. */
  59. doRequest : function(action, rs, params, reader, callback, scope, arg) {
  60. // No implementation for CRUD in MemoryProxy. Assumes all actions are 'load'
  61. params = params || {};
  62. var result;
  63. try {
  64. result = reader.readRecords(this.data);
  65. }catch(e){
  66. // @deprecated loadexception
  67. this.fireEvent("loadexception", this, null, arg, e);
  68. this.fireEvent('exception', this, 'response', action, arg, null, e);
  69. callback.call(scope, null, arg, false);
  70. return;
  71. }
  72. callback.call(scope, result, arg, true);
  73. }
  74. });