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.

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