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.

389 lines
14 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.direct.RemotingProvider"></div>/**
  16. * @class Ext.direct.RemotingProvider
  17. * @extends Ext.direct.JsonProvider
  18. *
  19. * <p>The {@link Ext.direct.RemotingProvider RemotingProvider} exposes access to
  20. * server side methods on the client (a remote procedure call (RPC) type of
  21. * connection where the client can initiate a procedure on the server).</p>
  22. *
  23. * <p>This allows for code to be organized in a fashion that is maintainable,
  24. * while providing a clear path between client and server, something that is
  25. * not always apparent when using URLs.</p>
  26. *
  27. * <p>To accomplish this the server-side needs to describe what classes and methods
  28. * are available on the client-side. This configuration will typically be
  29. * outputted by the server-side Ext.Direct stack when the API description is built.</p>
  30. */
  31. Ext.direct.RemotingProvider = Ext.extend(Ext.direct.JsonProvider, {
  32. <div id="cfg-Ext.direct.RemotingProvider-actions"></div>/**
  33. * @cfg {Object} actions
  34. * Object literal defining the server side actions and methods. For example, if
  35. * the Provider is configured with:
  36. * <pre><code>
  37. "actions":{ // each property within the 'actions' object represents a server side Class
  38. "TestAction":[ // array of methods within each server side Class to be
  39. { // stubbed out on client
  40. "name":"doEcho",
  41. "len":1
  42. },{
  43. "name":"multiply",// name of method
  44. "len":2 // The number of parameters that will be used to create an
  45. // array of data to send to the server side function.
  46. // Ensure the server sends back a Number, not a String.
  47. },{
  48. "name":"doForm",
  49. "formHandler":true, // direct the client to use specialized form handling method
  50. "len":1
  51. }]
  52. }
  53. * </code></pre>
  54. * <p>Note that a Store is not required, a server method can be called at any time.
  55. * In the following example a <b>client side</b> handler is used to call the
  56. * server side method "multiply" in the server-side "TestAction" Class:</p>
  57. * <pre><code>
  58. TestAction.multiply(
  59. 2, 4, // pass two arguments to server, so specify len=2
  60. // callback function after the server is called
  61. // result: the result returned by the server
  62. // e: Ext.Direct.RemotingEvent object
  63. function(result, e){
  64. var t = e.getTransaction();
  65. var action = t.action; // server side Class called
  66. var method = t.method; // server side method called
  67. if(e.status){
  68. var answer = Ext.encode(result); // 8
  69. }else{
  70. var msg = e.message; // failure message
  71. }
  72. }
  73. );
  74. * </code></pre>
  75. * In the example above, the server side "multiply" function will be passed two
  76. * arguments (2 and 4). The "multiply" method should return the value 8 which will be
  77. * available as the <tt>result</tt> in the example above.
  78. */
  79. <div id="cfg-Ext.direct.RemotingProvider-namespace"></div>/**
  80. * @cfg {String/Object} namespace
  81. * Namespace for the Remoting Provider (defaults to the browser global scope of <i>window</i>).
  82. * Explicitly specify the namespace Object, or specify a String to have a
  83. * {@link Ext#namespace namespace created} implicitly.
  84. */
  85. <div id="cfg-Ext.direct.RemotingProvider-url"></div>/**
  86. * @cfg {String} url
  87. * <b>Required<b>. The url to connect to the {@link Ext.Direct} server-side router.
  88. */
  89. <div id="cfg-Ext.direct.RemotingProvider-enableUrlEncode"></div>/**
  90. * @cfg {String} enableUrlEncode
  91. * Specify which param will hold the arguments for the method.
  92. * Defaults to <tt>'data'</tt>.
  93. */
  94. <div id="cfg-Ext.direct.RemotingProvider-enableBuffer"></div>/**
  95. * @cfg {Number/Boolean} enableBuffer
  96. * <p><tt>true</tt> or <tt>false</tt> to enable or disable combining of method
  97. * calls. If a number is specified this is the amount of time in milliseconds
  98. * to wait before sending a batched request (defaults to <tt>10</tt>).</p>
  99. * <br><p>Calls which are received within the specified timeframe will be
  100. * concatenated together and sent in a single request, optimizing the
  101. * application by reducing the amount of round trips that have to be made
  102. * to the server.</p>
  103. */
  104. enableBuffer: 10,
  105. <div id="cfg-Ext.direct.RemotingProvider-maxRetries"></div>/**
  106. * @cfg {Number} maxRetries
  107. * Number of times to re-attempt delivery on failure of a call. Defaults to <tt>1</tt>.
  108. */
  109. maxRetries: 1,
  110. <div id="cfg-Ext.direct.RemotingProvider-timeout"></div>/**
  111. * @cfg {Number} timeout
  112. * The timeout to use for each request. Defaults to <tt>undefined</tt>.
  113. */
  114. timeout: undefined,
  115. constructor : function(config){
  116. Ext.direct.RemotingProvider.superclass.constructor.call(this, config);
  117. this.addEvents(
  118. <div id="event-Ext.direct.RemotingProvider-beforecall"></div>/**
  119. * @event beforecall
  120. * Fires immediately before the client-side sends off the RPC call.
  121. * By returning false from an event handler you can prevent the call from
  122. * executing.
  123. * @param {Ext.direct.RemotingProvider} provider
  124. * @param {Ext.Direct.Transaction} transaction
  125. * @param {Object} meta The meta data
  126. */
  127. 'beforecall',
  128. <div id="event-Ext.direct.RemotingProvider-call"></div>/**
  129. * @event call
  130. * Fires immediately after the request to the server-side is sent. This does
  131. * NOT fire after the response has come back from the call.
  132. * @param {Ext.direct.RemotingProvider} provider
  133. * @param {Ext.Direct.Transaction} transaction
  134. * @param {Object} meta The meta data
  135. */
  136. 'call'
  137. );
  138. this.namespace = (Ext.isString(this.namespace)) ? Ext.ns(this.namespace) : this.namespace || window;
  139. this.transactions = {};
  140. this.callBuffer = [];
  141. },
  142. // private
  143. initAPI : function(){
  144. var o = this.actions;
  145. for(var c in o){
  146. var cls = this.namespace[c] || (this.namespace[c] = {}),
  147. ms = o[c];
  148. for(var i = 0, len = ms.length; i < len; i++){
  149. var m = ms[i];
  150. cls[m.name] = this.createMethod(c, m);
  151. }
  152. }
  153. },
  154. // inherited
  155. isConnected: function(){
  156. return !!this.connected;
  157. },
  158. connect: function(){
  159. if(this.url){
  160. this.initAPI();
  161. this.connected = true;
  162. this.fireEvent('connect', this);
  163. }else if(!this.url){
  164. throw 'Error initializing RemotingProvider, no url configured.';
  165. }
  166. },
  167. disconnect: function(){
  168. if(this.connected){
  169. this.connected = false;
  170. this.fireEvent('disconnect', this);
  171. }
  172. },
  173. onData: function(opt, success, xhr){
  174. if(success){
  175. var events = this.getEvents(xhr);
  176. for(var i = 0, len = events.length; i < len; i++){
  177. var e = events[i],
  178. t = this.getTransaction(e);
  179. this.fireEvent('data', this, e);
  180. if(t){
  181. this.doCallback(t, e, true);
  182. Ext.Direct.removeTransaction(t);
  183. }
  184. }
  185. }else{
  186. var ts = [].concat(opt.ts);
  187. for(var i = 0, len = ts.length; i < len; i++){
  188. var t = this.getTransaction(ts[i]);
  189. if(t && t.retryCount < this.maxRetries){
  190. t.retry();
  191. }else{
  192. var e = new Ext.Direct.ExceptionEvent({
  193. data: e,
  194. transaction: t,
  195. code: Ext.Direct.exceptions.TRANSPORT,
  196. message: 'Unable to connect to the server.',
  197. xhr: xhr
  198. });
  199. this.fireEvent('data', this, e);
  200. if(t){
  201. this.doCallback(t, e, false);
  202. Ext.Direct.removeTransaction(t);
  203. }
  204. }
  205. }
  206. }
  207. },
  208. getCallData: function(t){
  209. return {
  210. action: t.action,
  211. method: t.method,
  212. data: t.data,
  213. type: 'rpc',
  214. tid: t.tid
  215. };
  216. },
  217. doSend : function(data){
  218. var o = {
  219. url: this.url,
  220. callback: this.onData,
  221. scope: this,
  222. ts: data,
  223. timeout: this.timeout
  224. }, callData;
  225. if(Ext.isArray(data)){
  226. callData = [];
  227. for(var i = 0, len = data.length; i < len; i++){
  228. callData.push(this.getCallData(data[i]));
  229. }
  230. }else{
  231. callData = this.getCallData(data);
  232. }
  233. if(this.enableUrlEncode){
  234. var params = {};
  235. params[Ext.isString(this.enableUrlEncode) ? this.enableUrlEncode : 'data'] = Ext.encode(callData);
  236. o.params = params;
  237. }else{
  238. o.jsonData = callData;
  239. }
  240. Ext.Ajax.request(o);
  241. },
  242. combineAndSend : function(){
  243. var len = this.callBuffer.length;
  244. if(len > 0){
  245. this.doSend(len == 1 ? this.callBuffer[0] : this.callBuffer);
  246. this.callBuffer = [];
  247. }
  248. },
  249. queueTransaction: function(t){
  250. if(t.form){
  251. this.processForm(t);
  252. return;
  253. }
  254. this.callBuffer.push(t);
  255. if(this.enableBuffer){
  256. if(!this.callTask){
  257. this.callTask = new Ext.util.DelayedTask(this.combineAndSend, this);
  258. }
  259. this.callTask.delay(Ext.isNumber(this.enableBuffer) ? this.enableBuffer : 10);
  260. }else{
  261. this.combineAndSend();
  262. }
  263. },
  264. doCall : function(c, m, args){
  265. var data = null, hs = args[m.len], scope = args[m.len+1];
  266. if(m.len !== 0){
  267. data = args.slice(0, m.len);
  268. }
  269. var t = new Ext.Direct.Transaction({
  270. provider: this,
  271. args: args,
  272. action: c,
  273. method: m.name,
  274. data: data,
  275. cb: scope && Ext.isFunction(hs) ? hs.createDelegate(scope) : hs
  276. });
  277. if(this.fireEvent('beforecall', this, t, m) !== false){
  278. Ext.Direct.addTransaction(t);
  279. this.queueTransaction(t);
  280. this.fireEvent('call', this, t, m);
  281. }
  282. },
  283. doForm : function(c, m, form, callback, scope){
  284. var t = new Ext.Direct.Transaction({
  285. provider: this,
  286. action: c,
  287. method: m.name,
  288. args:[form, callback, scope],
  289. cb: scope && Ext.isFunction(callback) ? callback.createDelegate(scope) : callback,
  290. isForm: true
  291. });
  292. if(this.fireEvent('beforecall', this, t, m) !== false){
  293. Ext.Direct.addTransaction(t);
  294. var isUpload = String(form.getAttribute("enctype")).toLowerCase() == 'multipart/form-data',
  295. params = {
  296. extTID: t.tid,
  297. extAction: c,
  298. extMethod: m.name,
  299. extType: 'rpc',
  300. extUpload: String(isUpload)
  301. };
  302. // change made from typeof callback check to callback.params
  303. // to support addl param passing in DirectSubmit EAC 6/2
  304. Ext.apply(t, {
  305. form: Ext.getDom(form),
  306. isUpload: isUpload,
  307. params: callback && Ext.isObject(callback.params) ? Ext.apply(params, callback.params) : params
  308. });
  309. this.fireEvent('call', this, t, m);
  310. this.processForm(t);
  311. }
  312. },
  313. processForm: function(t){
  314. Ext.Ajax.request({
  315. url: this.url,
  316. params: t.params,
  317. callback: this.onData,
  318. scope: this,
  319. form: t.form,
  320. isUpload: t.isUpload,
  321. ts: t
  322. });
  323. },
  324. createMethod : function(c, m){
  325. var f;
  326. if(!m.formHandler){
  327. f = function(){
  328. this.doCall(c, m, Array.prototype.slice.call(arguments, 0));
  329. }.createDelegate(this);
  330. }else{
  331. f = function(form, callback, scope){
  332. this.doForm(c, m, form, callback, scope);
  333. }.createDelegate(this);
  334. }
  335. f.directCfg = {
  336. action: c,
  337. method: m
  338. };
  339. return f;
  340. },
  341. getTransaction: function(opt){
  342. return opt && opt.tid ? Ext.Direct.getTransaction(opt.tid) : null;
  343. },
  344. doCallback: function(t, e){
  345. var fn = e.status ? 'success' : 'failure';
  346. if(t && t.cb){
  347. var hs = t.cb,
  348. result = Ext.isDefined(e.result) ? e.result : e.data;
  349. if(Ext.isFunction(hs)){
  350. hs(result, e);
  351. } else{
  352. Ext.callback(hs[fn], hs.scope, [result, e]);
  353. Ext.callback(hs.callback, hs.scope, [result, e]);
  354. }
  355. }
  356. }
  357. });
  358. Ext.Direct.PROVIDERS['remoting'] = Ext.direct.RemotingProvider;</pre>
  359. </body>
  360. </html>