Web Interface For Lite Argus Control modules
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.

183 lines
7.7 KiB

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