Web UI for ARGUS server
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.

270 lines
12 KiB

6 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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.HttpProxy"></div>/**
  16. * @class Ext.data.HttpProxy
  17. * @extends Ext.data.DataProxy
  18. * <p>An implementation of {@link Ext.data.DataProxy} that processes data requests within the same
  19. * domain of the originating page.</p>
  20. * <p><b>Note</b>: this class cannot be used to retrieve data from a domain other
  21. * than the domain from which the running page was served. For cross-domain requests, use a
  22. * {@link Ext.data.ScriptTagProxy ScriptTagProxy}.</p>
  23. * <p>Be aware that to enable the browser to parse an XML document, the server must set
  24. * the Content-Type header in the HTTP response to "<tt>text/xml</tt>".</p>
  25. * @constructor
  26. * @param {Object} conn
  27. * An {@link Ext.data.Connection} object, or options parameter to {@link Ext.Ajax#request}.
  28. * <p>Note that if this HttpProxy is being used by a {@link Ext.data.Store Store}, then the
  29. * Store's call to {@link #load} will override any specified <tt>callback</tt> and <tt>params</tt>
  30. * options. In this case, use the Store's {@link Ext.data.Store#events events} to modify parameters,
  31. * or react to loading events. The Store's {@link Ext.data.Store#baseParams baseParams} may also be
  32. * used to pass parameters known at instantiation time.</p>
  33. * <p>If an options parameter is passed, the singleton {@link Ext.Ajax} object will be used to make
  34. * the request.</p>
  35. */
  36. Ext.data.HttpProxy = function(conn){
  37. Ext.data.HttpProxy.superclass.constructor.call(this, conn);
  38. <div id="prop-Ext.data.HttpProxy-conn"></div>/**
  39. * The Connection object (Or options parameter to {@link Ext.Ajax#request}) which this HttpProxy
  40. * uses to make requests to the server. Properties of this object may be changed dynamically to
  41. * change the way data is requested.
  42. * @property
  43. */
  44. this.conn = conn;
  45. // nullify the connection url. The url param has been copied to 'this' above. The connection
  46. // url will be set during each execution of doRequest when buildUrl is called. This makes it easier for users to override the
  47. // connection url during beforeaction events (ie: beforeload, beforewrite, etc).
  48. // Url is always re-defined during doRequest.
  49. this.conn.url = null;
  50. this.useAjax = !conn || !conn.events;
  51. // A hash containing active requests, keyed on action [Ext.data.Api.actions.create|read|update|destroy]
  52. var actions = Ext.data.Api.actions;
  53. this.activeRequest = {};
  54. for (var verb in actions) {
  55. this.activeRequest[actions[verb]] = undefined;
  56. }
  57. };
  58. Ext.extend(Ext.data.HttpProxy, Ext.data.DataProxy, {
  59. <div id="method-Ext.data.HttpProxy-getConnection"></div>/**
  60. * Return the {@link Ext.data.Connection} object being used by this Proxy.
  61. * @return {Connection} The Connection object. This object may be used to subscribe to events on
  62. * a finer-grained basis than the DataProxy events.
  63. */
  64. getConnection : function() {
  65. return this.useAjax ? Ext.Ajax : this.conn;
  66. },
  67. <div id="method-Ext.data.HttpProxy-setUrl"></div>/**
  68. * Used for overriding the url used for a single request. Designed to be called during a beforeaction event. Calling setUrl
  69. * will override any urls set via the api configuration parameter. Set the optional parameter makePermanent to set the url for
  70. * all subsequent requests. If not set to makePermanent, the next request will use the same url or api configuration defined
  71. * in the initial proxy configuration.
  72. * @param {String} url
  73. * @param {Boolean} makePermanent (Optional) [false]
  74. *
  75. * (e.g.: beforeload, beforesave, etc).
  76. */
  77. setUrl : function(url, makePermanent) {
  78. this.conn.url = url;
  79. if (makePermanent === true) {
  80. this.url = url;
  81. this.api = null;
  82. Ext.data.Api.prepare(this);
  83. }
  84. },
  85. <div id="method-Ext.data.HttpProxy-doRequest"></div>/**
  86. * HttpProxy implementation of DataProxy#doRequest
  87. * @param {String} action The crud action type (create, read, update, destroy)
  88. * @param {Ext.data.Record/Ext.data.Record[]} rs If action is load, rs will be null
  89. * @param {Object} params An object containing properties which are to be used as HTTP parameters
  90. * for the request to the remote server.
  91. * @param {Ext.data.DataReader} reader The Reader object which converts the data
  92. * object into a block of Ext.data.Records.
  93. * @param {Function} callback
  94. * <div class="sub-desc"><p>A function to be called after the request.
  95. * The <tt>callback</tt> is passed the following arguments:<ul>
  96. * <li><tt>r</tt> : Ext.data.Record[] The block of Ext.data.Records.</li>
  97. * <li><tt>options</tt>: Options object from the action request</li>
  98. * <li><tt>success</tt>: Boolean success indicator</li></ul></p></div>
  99. * @param {Object} scope The scope (<code>this</code> reference) in which the callback function is executed. Defaults to the browser window.
  100. * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
  101. * @protected
  102. */
  103. doRequest : function(action, rs, params, reader, cb, scope, arg) {
  104. var o = {
  105. method: (this.api[action]) ? this.api[action]['method'] : undefined,
  106. request: {
  107. callback : cb,
  108. scope : scope,
  109. arg : arg
  110. },
  111. reader: reader,
  112. callback : this.createCallback(action, rs),
  113. scope: this
  114. };
  115. // If possible, transmit data using jsonData || xmlData on Ext.Ajax.request (An installed DataWriter would have written it there.).
  116. // Use std HTTP params otherwise.
  117. if (params.jsonData) {
  118. o.jsonData = params.jsonData;
  119. } else if (params.xmlData) {
  120. o.xmlData = params.xmlData;
  121. } else {
  122. o.params = params || {};
  123. }
  124. // Set the connection url. If this.conn.url is not null here,
  125. // the user must have overridden the url during a beforewrite/beforeload event-handler.
  126. // this.conn.url is nullified after each request.
  127. this.conn.url = this.buildUrl(action, rs);
  128. if(this.useAjax){
  129. Ext.applyIf(o, this.conn);
  130. // If a currently running request is found for this action, abort it.
  131. if (this.activeRequest[action]) {
  132. ////
  133. // Disabled aborting activeRequest while implementing REST. activeRequest[action] will have to become an array
  134. // TODO ideas anyone?
  135. //
  136. //Ext.Ajax.abort(this.activeRequest[action]);
  137. }
  138. this.activeRequest[action] = Ext.Ajax.request(o);
  139. }else{
  140. this.conn.request(o);
  141. }
  142. // request is sent, nullify the connection url in preparation for the next request
  143. this.conn.url = null;
  144. },
  145. /**
  146. * Returns a callback function for a request. Note a special case is made for the
  147. * read action vs all the others.
  148. * @param {String} action [create|update|delete|load]
  149. * @param {Ext.data.Record[]} rs The Store-recordset being acted upon
  150. * @private
  151. */
  152. createCallback : function(action, rs) {
  153. return function(o, success, response) {
  154. this.activeRequest[action] = undefined;
  155. if (!success) {
  156. if (action === Ext.data.Api.actions.read) {
  157. // @deprecated: fire loadexception for backwards compat.
  158. // TODO remove
  159. this.fireEvent('loadexception', this, o, response);
  160. }
  161. this.fireEvent('exception', this, 'response', action, o, response);
  162. o.request.callback.call(o.request.scope, null, o.request.arg, false);
  163. return;
  164. }
  165. if (action === Ext.data.Api.actions.read) {
  166. this.onRead(action, o, response);
  167. } else {
  168. this.onWrite(action, o, response, rs);
  169. }
  170. };
  171. },
  172. <div id="method-Ext.data.HttpProxy-onRead"></div>/**
  173. * Callback for read action
  174. * @param {String} action Action name as per {@link Ext.data.Api.actions#read}.
  175. * @param {Object} o The request transaction object
  176. * @param {Object} res The server response
  177. * @fires loadexception (deprecated)
  178. * @fires exception
  179. * @fires load
  180. * @protected
  181. */
  182. onRead : function(action, o, response) {
  183. var result;
  184. try {
  185. result = o.reader.read(response);
  186. }catch(e){
  187. // @deprecated: fire old loadexception for backwards-compat.
  188. // TODO remove
  189. this.fireEvent('loadexception', this, o, response, e);
  190. this.fireEvent('exception', this, 'response', action, o, response, e);
  191. o.request.callback.call(o.request.scope, null, o.request.arg, false);
  192. return;
  193. }
  194. if (result.success === false) {
  195. // @deprecated: fire old loadexception for backwards-compat.
  196. // TODO remove
  197. this.fireEvent('loadexception', this, o, response);
  198. // Get DataReader read-back a response-object to pass along to exception event
  199. var res = o.reader.readResponse(action, response);
  200. this.fireEvent('exception', this, 'remote', action, o, res, null);
  201. }
  202. else {
  203. this.fireEvent('load', this, o, o.request.arg);
  204. }
  205. // TODO refactor onRead, onWrite to be more generalized now that we're dealing with Ext.data.Response instance
  206. // the calls to request.callback(...) in each will have to be made identical.
  207. // NOTE reader.readResponse does not currently return Ext.data.Response
  208. o.request.callback.call(o.request.scope, result, o.request.arg, result.success);
  209. },
  210. <div id="method-Ext.data.HttpProxy-onWrite"></div>/**
  211. * Callback for write actions
  212. * @param {String} action [Ext.data.Api.actions.create|read|update|destroy]
  213. * @param {Object} trans The request transaction object
  214. * @param {Object} res The server response
  215. * @fires exception
  216. * @fires write
  217. * @protected
  218. */
  219. onWrite : function(action, o, response, rs) {
  220. var reader = o.reader;
  221. var res;
  222. try {
  223. res = reader.readResponse(action, response);
  224. } catch (e) {
  225. this.fireEvent('exception', this, 'response', action, o, response, e);
  226. o.request.callback.call(o.request.scope, null, o.request.arg, false);
  227. return;
  228. }
  229. if (res.success === true) {
  230. this.fireEvent('write', this, action, res.data, res, rs, o.request.arg);
  231. } else {
  232. this.fireEvent('exception', this, 'remote', action, o, res, rs);
  233. }
  234. // TODO refactor onRead, onWrite to be more generalized now that we're dealing with Ext.data.Response instance
  235. // the calls to request.callback(...) in each will have to be made similar.
  236. // NOTE reader.readResponse does not currently return Ext.data.Response
  237. o.request.callback.call(o.request.scope, res.data, res, res.success);
  238. },
  239. // inherit docs
  240. destroy: function(){
  241. if(!this.useAjax){
  242. this.conn.abort();
  243. }else if(this.activeRequest){
  244. var actions = Ext.data.Api.actions;
  245. for (var verb in actions) {
  246. if(this.activeRequest[actions[verb]]){
  247. Ext.Ajax.abort(this.activeRequest[actions[verb]]);
  248. }
  249. }
  250. }
  251. Ext.data.HttpProxy.superclass.destroy.call(this);
  252. }
  253. });</pre>
  254. </body>
  255. </html>