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.

244 lines
8.8 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.Direct"></div>/**
  16. * @class Ext.Direct
  17. * @extends Ext.util.Observable
  18. * <p><b><u>Overview</u></b></p>
  19. *
  20. * <p>Ext.Direct aims to streamline communication between the client and server
  21. * by providing a single interface that reduces the amount of common code
  22. * typically required to validate data and handle returned data packets
  23. * (reading data, error conditions, etc).</p>
  24. *
  25. * <p>The Ext.direct namespace includes several classes for a closer integration
  26. * with the server-side. The Ext.data namespace also includes classes for working
  27. * with Ext.data.Stores which are backed by data from an Ext.Direct method.</p>
  28. *
  29. * <p><b><u>Specification</u></b></p>
  30. *
  31. * <p>For additional information consult the
  32. * <a href="http://extjs.com/products/extjs/direct.php">Ext.Direct Specification</a>.</p>
  33. *
  34. * <p><b><u>Providers</u></b></p>
  35. *
  36. * <p>Ext.Direct uses a provider architecture, where one or more providers are
  37. * used to transport data to and from the server. There are several providers
  38. * that exist in the core at the moment:</p><div class="mdetail-params"><ul>
  39. *
  40. * <li>{@link Ext.direct.JsonProvider JsonProvider} for simple JSON operations</li>
  41. * <li>{@link Ext.direct.PollingProvider PollingProvider} for repeated requests</li>
  42. * <li>{@link Ext.direct.RemotingProvider RemotingProvider} exposes server side
  43. * on the client.</li>
  44. * </ul></div>
  45. *
  46. * <p>A provider does not need to be invoked directly, providers are added via
  47. * {@link Ext.Direct}.{@link Ext.Direct#add add}.</p>
  48. *
  49. * <p><b><u>Router</u></b></p>
  50. *
  51. * <p>Ext.Direct utilizes a "router" on the server to direct requests from the client
  52. * to the appropriate server-side method. Because the Ext.Direct API is completely
  53. * platform-agnostic, you could completely swap out a Java based server solution
  54. * and replace it with one that uses C# without changing the client side JavaScript
  55. * at all.</p>
  56. *
  57. * <p><b><u>Server side events</u></b></p>
  58. *
  59. * <p>Custom events from the server may be handled by the client by adding
  60. * listeners, for example:</p>
  61. * <pre><code>
  62. {"type":"event","name":"message","data":"Successfully polled at: 11:19:30 am"}
  63. // add a handler for a 'message' event sent by the server
  64. Ext.Direct.on('message', function(e){
  65. out.append(String.format('&lt;p>&lt;i>{0}&lt;/i>&lt;/p>', e.data));
  66. out.el.scrollTo('t', 100000, true);
  67. });
  68. * </code></pre>
  69. * @singleton
  70. */
  71. Ext.Direct = Ext.extend(Ext.util.Observable, {
  72. <div id="prop-Ext.Direct-eventTypes"></div>/**
  73. * Each event type implements a getData() method. The default event types are:
  74. * <div class="mdetail-params"><ul>
  75. * <li><b><tt>event</tt></b> : Ext.Direct.Event</li>
  76. * <li><b><tt>exception</tt></b> : Ext.Direct.ExceptionEvent</li>
  77. * <li><b><tt>rpc</tt></b> : Ext.Direct.RemotingEvent</li>
  78. * </ul></div>
  79. * @property eventTypes
  80. * @type Object
  81. */
  82. <div id="prop-Ext.Direct-exceptions"></div>/**
  83. * Four types of possible exceptions which can occur:
  84. * <div class="mdetail-params"><ul>
  85. * <li><b><tt>Ext.Direct.exceptions.TRANSPORT</tt></b> : 'xhr'</li>
  86. * <li><b><tt>Ext.Direct.exceptions.PARSE</tt></b> : 'parse'</li>
  87. * <li><b><tt>Ext.Direct.exceptions.LOGIN</tt></b> : 'login'</li>
  88. * <li><b><tt>Ext.Direct.exceptions.SERVER</tt></b> : 'exception'</li>
  89. * </ul></div>
  90. * @property exceptions
  91. * @type Object
  92. */
  93. exceptions: {
  94. TRANSPORT: 'xhr',
  95. PARSE: 'parse',
  96. LOGIN: 'login',
  97. SERVER: 'exception'
  98. },
  99. // private
  100. constructor: function(){
  101. this.addEvents(
  102. <div id="event-Ext.Direct-event"></div>/**
  103. * @event event
  104. * Fires after an event.
  105. * @param {event} e The {@link Ext.Direct#eventTypes Ext.Direct.Event type} that occurred.
  106. * @param {Ext.direct.Provider} provider The {@link Ext.direct.Provider Provider}.
  107. */
  108. 'event',
  109. <div id="event-Ext.Direct-exception"></div>/**
  110. * @event exception
  111. * Fires after an event exception.
  112. * @param {event} e The {@link Ext.Direct#eventTypes Ext.Direct.Event type} that occurred.
  113. */
  114. 'exception'
  115. );
  116. this.transactions = {};
  117. this.providers = {};
  118. },
  119. <div id="method-Ext.Direct-addProvider"></div>/**
  120. * Adds an Ext.Direct Provider and creates the proxy or stub methods to execute server-side methods.
  121. * If the provider is not already connected, it will auto-connect.
  122. * <pre><code>
  123. var pollProv = new Ext.direct.PollingProvider({
  124. url: 'php/poll2.php'
  125. });
  126. Ext.Direct.addProvider(
  127. {
  128. "type":"remoting", // create a {@link Ext.direct.RemotingProvider}
  129. "url":"php\/router.php", // url to connect to the Ext.Direct server-side router.
  130. "actions":{ // each property within the actions object represents a Class
  131. "TestAction":[ // array of methods within each server side Class
  132. {
  133. "name":"doEcho", // name of method
  134. "len":1
  135. },{
  136. "name":"multiply",
  137. "len":1
  138. },{
  139. "name":"doForm",
  140. "formHandler":true, // handle form on server with Ext.Direct.Transaction
  141. "len":1
  142. }]
  143. },
  144. "namespace":"myApplication",// namespace to create the Remoting Provider in
  145. },{
  146. type: 'polling', // create a {@link Ext.direct.PollingProvider}
  147. url: 'php/poll.php'
  148. },
  149. pollProv // reference to previously created instance
  150. );
  151. * </code></pre>
  152. * @param {Object/Array} provider Accepts either an Array of Provider descriptions (an instance
  153. * or config object for a Provider) or any number of Provider descriptions as arguments. Each
  154. * Provider description instructs Ext.Direct how to create client-side stub methods.
  155. */
  156. addProvider : function(provider){
  157. var a = arguments;
  158. if(a.length > 1){
  159. for(var i = 0, len = a.length; i < len; i++){
  160. this.addProvider(a[i]);
  161. }
  162. return;
  163. }
  164. // if provider has not already been instantiated
  165. if(!provider.events){
  166. provider = new Ext.Direct.PROVIDERS[provider.type](provider);
  167. }
  168. provider.id = provider.id || Ext.id();
  169. this.providers[provider.id] = provider;
  170. provider.on('data', this.onProviderData, this);
  171. provider.on('exception', this.onProviderException, this);
  172. if(!provider.isConnected()){
  173. provider.connect();
  174. }
  175. return provider;
  176. },
  177. <div id="method-Ext.Direct-getProvider"></div>/**
  178. * Retrieve a {@link Ext.direct.Provider provider} by the
  179. * <b><tt>{@link Ext.direct.Provider#id id}</tt></b> specified when the provider is
  180. * {@link #addProvider added}.
  181. * @param {String} id Unique identifier assigned to the provider when calling {@link #addProvider}
  182. */
  183. getProvider : function(id){
  184. return this.providers[id];
  185. },
  186. removeProvider : function(id){
  187. var provider = id.id ? id : this.providers[id];
  188. provider.un('data', this.onProviderData, this);
  189. provider.un('exception', this.onProviderException, this);
  190. delete this.providers[provider.id];
  191. return provider;
  192. },
  193. addTransaction: function(t){
  194. this.transactions[t.tid] = t;
  195. return t;
  196. },
  197. removeTransaction: function(t){
  198. delete this.transactions[t.tid || t];
  199. return t;
  200. },
  201. getTransaction: function(tid){
  202. return this.transactions[tid.tid || tid];
  203. },
  204. onProviderData : function(provider, e){
  205. if(Ext.isArray(e)){
  206. for(var i = 0, len = e.length; i < len; i++){
  207. this.onProviderData(provider, e[i]);
  208. }
  209. return;
  210. }
  211. if(e.name && e.name != 'event' && e.name != 'exception'){
  212. this.fireEvent(e.name, e);
  213. }else if(e.type == 'exception'){
  214. this.fireEvent('exception', e);
  215. }
  216. this.fireEvent('event', e, provider);
  217. },
  218. createEvent : function(response, extraProps){
  219. return new Ext.Direct.eventTypes[response.type](Ext.apply(response, extraProps));
  220. }
  221. });
  222. // overwrite impl. with static instance
  223. Ext.Direct = new Ext.Direct();
  224. Ext.Direct.TID = 1;
  225. Ext.Direct.PROVIDERS = {};</pre>
  226. </body>
  227. </html>