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.

187 lines
8.1 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Ext-data-DirectProxy'>/**
  19. </span> * @class Ext.data.DirectProxy
  20. * @extends Ext.data.DataProxy
  21. */
  22. Ext.data.DirectProxy = function(config){
  23. Ext.apply(this, config);
  24. if(typeof this.paramOrder == 'string'){
  25. this.paramOrder = this.paramOrder.split(/[\s,|]/);
  26. }
  27. Ext.data.DirectProxy.superclass.constructor.call(this, config);
  28. };
  29. Ext.extend(Ext.data.DirectProxy, Ext.data.DataProxy, {
  30. <span id='Ext-data-DirectProxy-cfg-paramOrder'> /**
  31. </span> * @cfg {Array/String} paramOrder Defaults to &lt;tt&gt;undefined&lt;/tt&gt;. A list of params to be executed
  32. * server side. Specify the params in the order in which they must be executed on the server-side
  33. * as either (1) an Array of String values, or (2) a String of params delimited by either whitespace,
  34. * comma, or pipe. For example,
  35. * any of the following would be acceptable:&lt;pre&gt;&lt;code&gt;
  36. paramOrder: ['param1','param2','param3']
  37. paramOrder: 'param1 param2 param3'
  38. paramOrder: 'param1,param2,param3'
  39. paramOrder: 'param1|param2|param'
  40. &lt;/code&gt;&lt;/pre&gt;
  41. */
  42. paramOrder: undefined,
  43. <span id='Ext-data-DirectProxy-cfg-paramsAsHash'> /**
  44. </span> * @cfg {Boolean} paramsAsHash
  45. * Send parameters as a collection of named arguments (defaults to &lt;tt&gt;true&lt;/tt&gt;). Providing a
  46. * &lt;tt&gt;{@link #paramOrder}&lt;/tt&gt; nullifies this configuration.
  47. */
  48. paramsAsHash: true,
  49. <span id='Ext-data-DirectProxy-cfg-directFn'> /**
  50. </span> * @cfg {Function} directFn
  51. * Function to call when executing a request. directFn is a simple alternative to defining the api configuration-parameter
  52. * for Store's which will not implement a full CRUD api.
  53. */
  54. directFn : undefined,
  55. <span id='Ext-data-DirectProxy-method-doRequest'> /**
  56. </span> * DirectProxy implementation of {@link Ext.data.DataProxy#doRequest}
  57. * @param {String} action The crud action type (create, read, update, destroy)
  58. * @param {Ext.data.Record/Ext.data.Record[]} rs If action is load, rs will be null
  59. * @param {Object} params An object containing properties which are to be used as HTTP parameters
  60. * for the request to the remote server.
  61. * @param {Ext.data.DataReader} reader The Reader object which converts the data
  62. * object into a block of Ext.data.Records.
  63. * @param {Function} callback
  64. * &lt;div class=&quot;sub-desc&quot;&gt;&lt;p&gt;A function to be called after the request.
  65. * The &lt;tt&gt;callback&lt;/tt&gt; is passed the following arguments:&lt;ul&gt;
  66. * &lt;li&gt;&lt;tt&gt;r&lt;/tt&gt; : Ext.data.Record[] The block of Ext.data.Records.&lt;/li&gt;
  67. * &lt;li&gt;&lt;tt&gt;options&lt;/tt&gt;: Options object from the action request&lt;/li&gt;
  68. * &lt;li&gt;&lt;tt&gt;success&lt;/tt&gt;: Boolean success indicator&lt;/li&gt;&lt;/ul&gt;&lt;/p&gt;&lt;/div&gt;
  69. * @param {Object} scope The scope (&lt;code&gt;this&lt;/code&gt; reference) in which the callback function is executed. Defaults to the browser window.
  70. * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
  71. * @protected
  72. */
  73. doRequest : function(action, rs, params, reader, callback, scope, options) {
  74. var args = [],
  75. directFn = this.api[action] || this.directFn;
  76. switch (action) {
  77. case Ext.data.Api.actions.create:
  78. args.push(params.jsonData); // &lt;-- create(Hash)
  79. break;
  80. case Ext.data.Api.actions.read:
  81. // If the method has no parameters, ignore the paramOrder/paramsAsHash.
  82. if(directFn.directCfg.method.len &gt; 0){
  83. if(this.paramOrder){
  84. for(var i = 0, len = this.paramOrder.length; i &lt; len; i++){
  85. args.push(params[this.paramOrder[i]]);
  86. }
  87. }else if(this.paramsAsHash){
  88. args.push(params);
  89. }
  90. }
  91. break;
  92. case Ext.data.Api.actions.update:
  93. args.push(params.jsonData); // &lt;-- update(Hash/Hash[])
  94. break;
  95. case Ext.data.Api.actions.destroy:
  96. args.push(params.jsonData); // &lt;-- destroy(Int/Int[])
  97. break;
  98. }
  99. var trans = {
  100. params : params || {},
  101. request: {
  102. callback : callback,
  103. scope : scope,
  104. arg : options
  105. },
  106. reader: reader
  107. };
  108. args.push(this.createCallback(action, rs, trans), this);
  109. directFn.apply(window, args);
  110. },
  111. // private
  112. createCallback : function(action, rs, trans) {
  113. var me = this;
  114. return function(result, res) {
  115. if (!res.status) {
  116. // @deprecated fire loadexception
  117. if (action === Ext.data.Api.actions.read) {
  118. me.fireEvent(&quot;loadexception&quot;, me, trans, res, null);
  119. }
  120. me.fireEvent('exception', me, 'remote', action, trans, res, null);
  121. trans.request.callback.call(trans.request.scope, null, trans.request.arg, false);
  122. return;
  123. }
  124. if (action === Ext.data.Api.actions.read) {
  125. me.onRead(action, trans, result, res);
  126. } else {
  127. me.onWrite(action, trans, result, res, rs);
  128. }
  129. };
  130. },
  131. <span id='Ext-data-DirectProxy-method-onRead'> /**
  132. </span> * Callback for read actions
  133. * @param {String} action [Ext.data.Api.actions.create|read|update|destroy]
  134. * @param {Object} trans The request transaction object
  135. * @param {Object} result Data object picked out of the server-response.
  136. * @param {Object} res The server response
  137. * @protected
  138. */
  139. onRead : function(action, trans, result, res) {
  140. var records;
  141. try {
  142. records = trans.reader.readRecords(result);
  143. }
  144. catch (ex) {
  145. // @deprecated: Fire old loadexception for backwards-compat.
  146. this.fireEvent(&quot;loadexception&quot;, this, trans, res, ex);
  147. this.fireEvent('exception', this, 'response', action, trans, res, ex);
  148. trans.request.callback.call(trans.request.scope, null, trans.request.arg, false);
  149. return;
  150. }
  151. this.fireEvent(&quot;load&quot;, this, res, trans.request.arg);
  152. trans.request.callback.call(trans.request.scope, records, trans.request.arg, true);
  153. },
  154. <span id='Ext-data-DirectProxy-method-onWrite'> /**
  155. </span> * Callback for write actions
  156. * @param {String} action [{@link Ext.data.Api#actions create|read|update|destroy}]
  157. * @param {Object} trans The request transaction object
  158. * @param {Object} result Data object picked out of the server-response.
  159. * @param {Object} res The server response
  160. * @param {Ext.data.Record/Ext.data.Record[]} rs The Store resultset associated with the action.
  161. * @protected
  162. */
  163. onWrite : function(action, trans, result, res, rs) {
  164. var data = trans.reader.extractData(trans.reader.getRoot(result), false);
  165. var success = trans.reader.getSuccess(result);
  166. success = (success !== false);
  167. if (success){
  168. this.fireEvent(&quot;write&quot;, this, action, data, res, rs, trans.request.arg);
  169. }else{
  170. this.fireEvent('exception', this, 'remote', action, trans, result, rs);
  171. }
  172. trans.request.callback.call(trans.request.scope, data, res, success);
  173. }
  174. });
  175. </pre>
  176. </body>
  177. </html>