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.

597 lines
31 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">(function(){
  19. var BEFOREREQUEST = &quot;beforerequest&quot;,
  20. REQUESTCOMPLETE = &quot;requestcomplete&quot;,
  21. REQUESTEXCEPTION = &quot;requestexception&quot;,
  22. UNDEFINED = undefined,
  23. LOAD = 'load',
  24. POST = 'POST',
  25. GET = 'GET',
  26. WINDOW = window;
  27. <span id='Ext-data-Connection-method-constructor'><span id='Ext-data-Connection'> /**
  28. </span></span> * @class Ext.data.Connection
  29. * @extends Ext.util.Observable
  30. * &lt;p&gt;The class encapsulates a connection to the page's originating domain, allowing requests to be made
  31. * either to a configured URL, or to a URL specified at request time.&lt;/p&gt;
  32. * &lt;p&gt;Requests made by this class are asynchronous, and will return immediately. No data from
  33. * the server will be available to the statement immediately following the {@link #request} call.
  34. * To process returned data, use a
  35. * &lt;a href=&quot;#request-option-success&quot; ext:member=&quot;request-option-success&quot; ext:cls=&quot;Ext.data.Connection&quot;&gt;success callback&lt;/a&gt;
  36. * in the request options object,
  37. * or an {@link #requestcomplete event listener}.&lt;/p&gt;
  38. * &lt;p&gt;&lt;h3&gt;File Uploads&lt;/h3&gt;&lt;a href=&quot;#request-option-isUpload&quot; ext:member=&quot;request-option-isUpload&quot; ext:cls=&quot;Ext.data.Connection&quot;&gt;File uploads&lt;/a&gt; are not performed using normal &quot;Ajax&quot; techniques, that
  39. * is they are &lt;b&gt;not&lt;/b&gt; performed using XMLHttpRequests. Instead the form is submitted in the standard
  40. * manner with the DOM &lt;tt&gt;&amp;lt;form&gt;&lt;/tt&gt; element temporarily modified to have its
  41. * &lt;a href=&quot;http://www.w3.org/TR/REC-html40/present/frames.html#adef-target&quot;&gt;target&lt;/a&gt; set to refer
  42. * to a dynamically generated, hidden &lt;tt&gt;&amp;lt;iframe&gt;&lt;/tt&gt; which is inserted into the document
  43. * but removed after the return data has been gathered.&lt;/p&gt;
  44. * &lt;p&gt;The server response is parsed by the browser to create the document for the IFRAME. If the
  45. * server is using JSON to send the return object, then the
  46. * &lt;a href=&quot;http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17&quot;&gt;Content-Type&lt;/a&gt; header
  47. * must be set to &quot;text/html&quot; in order to tell the browser to insert the text unchanged into the document body.&lt;/p&gt;
  48. * &lt;p&gt;Characters which are significant to an HTML parser must be sent as HTML entities, so encode
  49. * &quot;&amp;lt;&quot; as &quot;&amp;amp;lt;&quot;, &quot;&amp;amp;&quot; as &quot;&amp;amp;amp;&quot; etc.&lt;/p&gt;
  50. * &lt;p&gt;The response text is retrieved from the document, and a fake XMLHttpRequest object
  51. * is created containing a &lt;tt&gt;responseText&lt;/tt&gt; property in order to conform to the
  52. * requirements of event handlers and callbacks.&lt;/p&gt;
  53. * &lt;p&gt;Be aware that file upload packets are sent with the content type &lt;a href=&quot;http://www.faqs.org/rfcs/rfc2388.html&quot;&gt;multipart/form&lt;/a&gt;
  54. * and some server technologies (notably JEE) may require some custom processing in order to
  55. * retrieve parameter names and parameter values from the packet content.&lt;/p&gt;
  56. * &lt;p&gt;Also note that it's not possible to check the response code of the hidden iframe, so the success handler will ALWAYS fire.&lt;/p&gt;
  57. * @constructor
  58. * @param {Object} config a configuration object.
  59. */
  60. Ext.data.Connection = function(config){
  61. Ext.apply(this, config);
  62. this.addEvents(
  63. <span id='Ext-data-Connection-event-beforerequest'> /**
  64. </span> * @event beforerequest
  65. * Fires before a network request is made to retrieve a data object.
  66. * @param {Connection} conn This Connection object.
  67. * @param {Object} options The options config object passed to the {@link #request} method.
  68. */
  69. BEFOREREQUEST,
  70. <span id='Ext-data-Connection-event-requestcomplete'> /**
  71. </span> * @event requestcomplete
  72. * Fires if the request was successfully completed.
  73. * @param {Connection} conn This Connection object.
  74. * @param {Object} response The XHR object containing the response data.
  75. * See &lt;a href=&quot;http://www.w3.org/TR/XMLHttpRequest/&quot;&gt;The XMLHttpRequest Object&lt;/a&gt;
  76. * for details.
  77. * @param {Object} options The options config object passed to the {@link #request} method.
  78. */
  79. REQUESTCOMPLETE,
  80. <span id='Ext-data-Connection-event-requestexception'> /**
  81. </span> * @event requestexception
  82. * Fires if an error HTTP status was returned from the server.
  83. * See &lt;a href=&quot;http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html&quot;&gt;HTTP Status Code Definitions&lt;/a&gt;
  84. * for details of HTTP status codes.
  85. * @param {Connection} conn This Connection object.
  86. * @param {Object} response The XHR object containing the response data.
  87. * See &lt;a href=&quot;http://www.w3.org/TR/XMLHttpRequest/&quot;&gt;The XMLHttpRequest Object&lt;/a&gt;
  88. * for details.
  89. * @param {Object} options The options config object passed to the {@link #request} method.
  90. */
  91. REQUESTEXCEPTION
  92. );
  93. Ext.data.Connection.superclass.constructor.call(this);
  94. };
  95. Ext.extend(Ext.data.Connection, Ext.util.Observable, {
  96. <span id='Ext-data-Connection-cfg-url'> /**
  97. </span> * @cfg {String} url (Optional) &lt;p&gt;The default URL to be used for requests to the server. Defaults to undefined.&lt;/p&gt;
  98. * &lt;p&gt;The &lt;code&gt;url&lt;/code&gt; config may be a function which &lt;i&gt;returns&lt;/i&gt; the URL to use for the Ajax request. The scope
  99. * (&lt;code&gt;&lt;b&gt;this&lt;/b&gt;&lt;/code&gt; reference) of the function is the &lt;code&gt;scope&lt;/code&gt; option passed to the {@link #request} method.&lt;/p&gt;
  100. */
  101. <span id='Ext-data-Connection-cfg-extraParams'> /**
  102. </span> * @cfg {Object} extraParams (Optional) An object containing properties which are used as
  103. * extra parameters to each request made by this object. (defaults to undefined)
  104. */
  105. <span id='Ext-data-Connection-cfg-defaultHeaders'> /**
  106. </span> * @cfg {Object} defaultHeaders (Optional) An object containing request headers which are added
  107. * to each request made by this object. (defaults to undefined)
  108. */
  109. <span id='Ext-data-Connection-cfg-method'> /**
  110. </span> * @cfg {String} method (Optional) The default HTTP method to be used for requests.
  111. * (defaults to undefined; if not set, but {@link #request} params are present, POST will be used;
  112. * otherwise, GET will be used.)
  113. */
  114. <span id='Ext-data-Connection-cfg-timeout'> /**
  115. </span> * @cfg {Number} timeout (Optional) The timeout in milliseconds to be used for requests. (defaults to 30000)
  116. */
  117. timeout : 30000,
  118. <span id='Ext-data-Connection-property-autoAbort'> /**
  119. </span> * @cfg {Boolean} autoAbort (Optional) Whether this request should abort any pending requests. (defaults to false)
  120. * @type Boolean
  121. */
  122. autoAbort:false,
  123. <span id='Ext-data-Connection-property-disableCaching'> /**
  124. </span> * @cfg {Boolean} disableCaching (Optional) True to add a unique cache-buster param to GET requests. (defaults to true)
  125. * @type Boolean
  126. */
  127. disableCaching: true,
  128. <span id='Ext-data-Connection-property-disableCachingParam'> /**
  129. </span> * @cfg {String} disableCachingParam (Optional) Change the parameter which is sent went disabling caching
  130. * through a cache buster. Defaults to '_dc'
  131. * @type String
  132. */
  133. disableCachingParam: '_dc',
  134. <span id='Ext-data-Connection-method-request'> /**
  135. </span> * &lt;p&gt;Sends an HTTP request to a remote server.&lt;/p&gt;
  136. * &lt;p&gt;&lt;b&gt;Important:&lt;/b&gt; Ajax server requests are asynchronous, and this call will
  137. * return before the response has been received. Process any returned data
  138. * in a callback function.&lt;/p&gt;
  139. * &lt;pre&gt;&lt;code&gt;
  140. Ext.Ajax.request({
  141. url: 'ajax_demo/sample.json',
  142. success: function(response, opts) {
  143. var obj = Ext.decode(response.responseText);
  144. console.dir(obj);
  145. },
  146. failure: function(response, opts) {
  147. console.log('server-side failure with status code ' + response.status);
  148. }
  149. });
  150. * &lt;/code&gt;&lt;/pre&gt;
  151. * &lt;p&gt;To execute a callback function in the correct scope, use the &lt;tt&gt;scope&lt;/tt&gt; option.&lt;/p&gt;
  152. * @param {Object} options An object which may contain the following properties:&lt;ul&gt;
  153. * &lt;li&gt;&lt;b&gt;url&lt;/b&gt; : String/Function (Optional)&lt;div class=&quot;sub-desc&quot;&gt;The URL to
  154. * which to send the request, or a function to call which returns a URL string. The scope of the
  155. * function is specified by the &lt;tt&gt;scope&lt;/tt&gt; option. Defaults to the configured
  156. * &lt;tt&gt;{@link #url}&lt;/tt&gt;.&lt;/div&gt;&lt;/li&gt;
  157. * &lt;li&gt;&lt;b&gt;params&lt;/b&gt; : Object/String/Function (Optional)&lt;div class=&quot;sub-desc&quot;&gt;
  158. * An object containing properties which are used as parameters to the
  159. * request, a url encoded string or a function to call to get either. The scope of the function
  160. * is specified by the &lt;tt&gt;scope&lt;/tt&gt; option.&lt;/div&gt;&lt;/li&gt;
  161. * &lt;li&gt;&lt;b&gt;method&lt;/b&gt; : String (Optional)&lt;div class=&quot;sub-desc&quot;&gt;The HTTP method to use
  162. * for the request. Defaults to the configured method, or if no method was configured,
  163. * &quot;GET&quot; if no parameters are being sent, and &quot;POST&quot; if parameters are being sent. Note that
  164. * the method name is case-sensitive and should be all caps.&lt;/div&gt;&lt;/li&gt;
  165. * &lt;li&gt;&lt;b&gt;callback&lt;/b&gt; : Function (Optional)&lt;div class=&quot;sub-desc&quot;&gt;The
  166. * function to be called upon receipt of the HTTP response. The callback is
  167. * called regardless of success or failure and is passed the following
  168. * parameters:&lt;ul&gt;
  169. * &lt;li&gt;&lt;b&gt;options&lt;/b&gt; : Object&lt;div class=&quot;sub-desc&quot;&gt;The parameter to the request call.&lt;/div&gt;&lt;/li&gt;
  170. * &lt;li&gt;&lt;b&gt;success&lt;/b&gt; : Boolean&lt;div class=&quot;sub-desc&quot;&gt;True if the request succeeded.&lt;/div&gt;&lt;/li&gt;
  171. * &lt;li&gt;&lt;b&gt;response&lt;/b&gt; : Object&lt;div class=&quot;sub-desc&quot;&gt;The XMLHttpRequest object containing the response data.
  172. * See &lt;a href=&quot;http://www.w3.org/TR/XMLHttpRequest/&quot;&gt;http://www.w3.org/TR/XMLHttpRequest/&lt;/a&gt; for details about
  173. * accessing elements of the response.&lt;/div&gt;&lt;/li&gt;
  174. * &lt;/ul&gt;&lt;/div&gt;&lt;/li&gt;
  175. * &lt;li&gt;&lt;a id=&quot;request-option-success&quot;&gt;&lt;/a&gt;&lt;b&gt;success&lt;/b&gt; : Function (Optional)&lt;div class=&quot;sub-desc&quot;&gt;The function
  176. * to be called upon success of the request. The callback is passed the following
  177. * parameters:&lt;ul&gt;
  178. * &lt;li&gt;&lt;b&gt;response&lt;/b&gt; : Object&lt;div class=&quot;sub-desc&quot;&gt;The XMLHttpRequest object containing the response data.&lt;/div&gt;&lt;/li&gt;
  179. * &lt;li&gt;&lt;b&gt;options&lt;/b&gt; : Object&lt;div class=&quot;sub-desc&quot;&gt;The parameter to the request call.&lt;/div&gt;&lt;/li&gt;
  180. * &lt;/ul&gt;&lt;/div&gt;&lt;/li&gt;
  181. * &lt;li&gt;&lt;b&gt;failure&lt;/b&gt; : Function (Optional)&lt;div class=&quot;sub-desc&quot;&gt;The function
  182. * to be called upon failure of the request. The callback is passed the
  183. * following parameters:&lt;ul&gt;
  184. * &lt;li&gt;&lt;b&gt;response&lt;/b&gt; : Object&lt;div class=&quot;sub-desc&quot;&gt;The XMLHttpRequest object containing the response data.&lt;/div&gt;&lt;/li&gt;
  185. * &lt;li&gt;&lt;b&gt;options&lt;/b&gt; : Object&lt;div class=&quot;sub-desc&quot;&gt;The parameter to the request call.&lt;/div&gt;&lt;/li&gt;
  186. * &lt;/ul&gt;&lt;/div&gt;&lt;/li&gt;
  187. * &lt;li&gt;&lt;b&gt;scope&lt;/b&gt; : Object (Optional)&lt;div class=&quot;sub-desc&quot;&gt;The scope in
  188. * which to execute the callbacks: The &quot;this&quot; object for the callback function. If the &lt;tt&gt;url&lt;/tt&gt;, or &lt;tt&gt;params&lt;/tt&gt; options were
  189. * specified as functions from which to draw values, then this also serves as the scope for those function calls.
  190. * Defaults to the browser window.&lt;/div&gt;&lt;/li&gt;
  191. * &lt;li&gt;&lt;b&gt;timeout&lt;/b&gt; : Number (Optional)&lt;div class=&quot;sub-desc&quot;&gt;The timeout in milliseconds to be used for this request. Defaults to 30 seconds.&lt;/div&gt;&lt;/li&gt;
  192. * &lt;li&gt;&lt;b&gt;form&lt;/b&gt; : Element/HTMLElement/String (Optional)&lt;div class=&quot;sub-desc&quot;&gt;The &lt;tt&gt;&amp;lt;form&amp;gt;&lt;/tt&gt;
  193. * Element or the id of the &lt;tt&gt;&amp;lt;form&amp;gt;&lt;/tt&gt; to pull parameters from.&lt;/div&gt;&lt;/li&gt;
  194. * &lt;li&gt;&lt;a id=&quot;request-option-isUpload&quot;&gt;&lt;/a&gt;&lt;b&gt;isUpload&lt;/b&gt; : Boolean (Optional)&lt;div class=&quot;sub-desc&quot;&gt;&lt;b&gt;Only meaningful when used
  195. * with the &lt;tt&gt;form&lt;/tt&gt; option&lt;/b&gt;.
  196. * &lt;p&gt;True if the form object is a file upload (will be set automatically if the form was
  197. * configured with &lt;b&gt;&lt;tt&gt;enctype&lt;/tt&gt;&lt;/b&gt; &quot;multipart/form-data&quot;).&lt;/p&gt;
  198. * &lt;p&gt;File uploads are not performed using normal &quot;Ajax&quot; techniques, that is they are &lt;b&gt;not&lt;/b&gt;
  199. * performed using XMLHttpRequests. Instead the form is submitted in the standard manner with the
  200. * DOM &lt;tt&gt;&amp;lt;form&gt;&lt;/tt&gt; element temporarily modified to have its
  201. * &lt;a href=&quot;http://www.w3.org/TR/REC-html40/present/frames.html#adef-target&quot;&gt;target&lt;/a&gt; set to refer
  202. * to a dynamically generated, hidden &lt;tt&gt;&amp;lt;iframe&gt;&lt;/tt&gt; which is inserted into the document
  203. * but removed after the return data has been gathered.&lt;/p&gt;
  204. * &lt;p&gt;The server response is parsed by the browser to create the document for the IFRAME. If the
  205. * server is using JSON to send the return object, then the
  206. * &lt;a href=&quot;http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17&quot;&gt;Content-Type&lt;/a&gt; header
  207. * must be set to &quot;text/html&quot; in order to tell the browser to insert the text unchanged into the document body.&lt;/p&gt;
  208. * &lt;p&gt;The response text is retrieved from the document, and a fake XMLHttpRequest object
  209. * is created containing a &lt;tt&gt;responseText&lt;/tt&gt; property in order to conform to the
  210. * requirements of event handlers and callbacks.&lt;/p&gt;
  211. * &lt;p&gt;Be aware that file upload packets are sent with the content type &lt;a href=&quot;http://www.faqs.org/rfcs/rfc2388.html&quot;&gt;multipart/form&lt;/a&gt;
  212. * and some server technologies (notably JEE) may require some custom processing in order to
  213. * retrieve parameter names and parameter values from the packet content.&lt;/p&gt;
  214. * &lt;/div&gt;&lt;/li&gt;
  215. * &lt;li&gt;&lt;b&gt;headers&lt;/b&gt; : Object (Optional)&lt;div class=&quot;sub-desc&quot;&gt;Request
  216. * headers to set for the request.&lt;/div&gt;&lt;/li&gt;
  217. * &lt;li&gt;&lt;b&gt;xmlData&lt;/b&gt; : Object (Optional)&lt;div class=&quot;sub-desc&quot;&gt;XML document
  218. * to use for the post. Note: This will be used instead of params for the post
  219. * data. Any params will be appended to the URL.&lt;/div&gt;&lt;/li&gt;
  220. * &lt;li&gt;&lt;b&gt;jsonData&lt;/b&gt; : Object/String (Optional)&lt;div class=&quot;sub-desc&quot;&gt;JSON
  221. * data to use as the post. Note: This will be used instead of params for the post
  222. * data. Any params will be appended to the URL.&lt;/div&gt;&lt;/li&gt;
  223. * &lt;li&gt;&lt;b&gt;disableCaching&lt;/b&gt; : Boolean (Optional)&lt;div class=&quot;sub-desc&quot;&gt;True
  224. * to add a unique cache-buster param to GET requests.&lt;/div&gt;&lt;/li&gt;
  225. * &lt;/ul&gt;&lt;/p&gt;
  226. * &lt;p&gt;The options object may also contain any other property which might be needed to perform
  227. * postprocessing in a callback because it is passed to callback functions.&lt;/p&gt;
  228. * @return {Number} transactionId The id of the server transaction. This may be used
  229. * to cancel the request.
  230. */
  231. request : function(o){
  232. var me = this;
  233. if(me.fireEvent(BEFOREREQUEST, me, o)){
  234. if (o.el) {
  235. if(!Ext.isEmpty(o.indicatorText)){
  236. me.indicatorText = '&lt;div class=&quot;loading-indicator&quot;&gt;'+o.indicatorText+&quot;&lt;/div&gt;&quot;;
  237. }
  238. if(me.indicatorText) {
  239. Ext.getDom(o.el).innerHTML = me.indicatorText;
  240. }
  241. o.success = (Ext.isFunction(o.success) ? o.success : function(){}).createInterceptor(function(response) {
  242. Ext.getDom(o.el).innerHTML = response.responseText;
  243. });
  244. }
  245. var p = o.params,
  246. url = o.url || me.url,
  247. method,
  248. cb = {success: me.handleResponse,
  249. failure: me.handleFailure,
  250. scope: me,
  251. argument: {options: o},
  252. timeout : Ext.num(o.timeout, me.timeout)
  253. },
  254. form,
  255. serForm;
  256. if (Ext.isFunction(p)) {
  257. p = p.call(o.scope||WINDOW, o);
  258. }
  259. p = Ext.urlEncode(me.extraParams, Ext.isObject(p) ? Ext.urlEncode(p) : p);
  260. if (Ext.isFunction(url)) {
  261. url = url.call(o.scope || WINDOW, o);
  262. }
  263. if((form = Ext.getDom(o.form))){
  264. url = url || form.action;
  265. if(o.isUpload || (/multipart\/form-data/i.test(form.getAttribute(&quot;enctype&quot;)))) {
  266. return me.doFormUpload.call(me, o, p, url);
  267. }
  268. serForm = Ext.lib.Ajax.serializeForm(form);
  269. p = p ? (p + '&amp;' + serForm) : serForm;
  270. }
  271. method = o.method || me.method || ((p || o.xmlData || o.jsonData) ? POST : GET);
  272. if(method === GET &amp;&amp; (me.disableCaching &amp;&amp; o.disableCaching !== false) || o.disableCaching === true){
  273. var dcp = o.disableCachingParam || me.disableCachingParam;
  274. url = Ext.urlAppend(url, dcp + '=' + (new Date().getTime()));
  275. }
  276. o.headers = Ext.applyIf(o.headers || {}, me.defaultHeaders || {});
  277. if(o.autoAbort === true || me.autoAbort) {
  278. me.abort();
  279. }
  280. if((method == GET || o.xmlData || o.jsonData) &amp;&amp; p){
  281. url = Ext.urlAppend(url, p);
  282. p = '';
  283. }
  284. return (me.transId = Ext.lib.Ajax.request(method, url, cb, p, o));
  285. }else{
  286. return o.callback ? o.callback.apply(o.scope, [o,UNDEFINED,UNDEFINED]) : null;
  287. }
  288. },
  289. <span id='Ext-data-Connection-method-isLoading'> /**
  290. </span> * Determine whether this object has a request outstanding.
  291. * @param {Number} transactionId (Optional) defaults to the last transaction
  292. * @return {Boolean} True if there is an outstanding request.
  293. */
  294. isLoading : function(transId){
  295. return transId ? Ext.lib.Ajax.isCallInProgress(transId) : !! this.transId;
  296. },
  297. <span id='Ext-data-Connection-method-abort'> /**
  298. </span> * Aborts any outstanding request.
  299. * @param {Number} transactionId (Optional) defaults to the last transaction
  300. */
  301. abort : function(transId){
  302. if(transId || this.isLoading()){
  303. Ext.lib.Ajax.abort(transId || this.transId);
  304. }
  305. },
  306. // private
  307. handleResponse : function(response){
  308. this.transId = false;
  309. var options = response.argument.options;
  310. response.argument = options ? options.argument : null;
  311. this.fireEvent(REQUESTCOMPLETE, this, response, options);
  312. if(options.success){
  313. options.success.call(options.scope, response, options);
  314. }
  315. if(options.callback){
  316. options.callback.call(options.scope, options, true, response);
  317. }
  318. },
  319. // private
  320. handleFailure : function(response, e){
  321. this.transId = false;
  322. var options = response.argument.options;
  323. response.argument = options ? options.argument : null;
  324. this.fireEvent(REQUESTEXCEPTION, this, response, options, e);
  325. if(options.failure){
  326. options.failure.call(options.scope, response, options);
  327. }
  328. if(options.callback){
  329. options.callback.call(options.scope, options, false, response);
  330. }
  331. },
  332. // private
  333. doFormUpload : function(o, ps, url){
  334. var id = Ext.id(),
  335. doc = document,
  336. frame = doc.createElement('iframe'),
  337. form = Ext.getDom(o.form),
  338. hiddens = [],
  339. hd,
  340. encoding = 'multipart/form-data',
  341. buf = {
  342. target: form.target,
  343. method: form.method,
  344. encoding: form.encoding,
  345. enctype: form.enctype,
  346. action: form.action
  347. };
  348. /*
  349. * Originally this behaviour was modified for Opera 10 to apply the secure URL after
  350. * the frame had been added to the document. It seems this has since been corrected in
  351. * Opera so the behaviour has been reverted, the URL will be set before being added.
  352. */
  353. Ext.fly(frame).set({
  354. id: id,
  355. name: id,
  356. cls: 'x-hidden',
  357. src: Ext.SSL_SECURE_URL
  358. });
  359. doc.body.appendChild(frame);
  360. // This is required so that IE doesn't pop the response up in a new window.
  361. if(Ext.isIE){
  362. document.frames[id].name = id;
  363. }
  364. Ext.fly(form).set({
  365. target: id,
  366. method: POST,
  367. enctype: encoding,
  368. encoding: encoding,
  369. action: url || buf.action
  370. });
  371. // add dynamic params
  372. Ext.iterate(Ext.urlDecode(ps, false), function(k, v){
  373. hd = doc.createElement('input');
  374. Ext.fly(hd).set({
  375. type: 'hidden',
  376. value: v,
  377. name: k
  378. });
  379. form.appendChild(hd);
  380. hiddens.push(hd);
  381. });
  382. function cb(){
  383. var me = this,
  384. // bogus response object
  385. r = {responseText : '',
  386. responseXML : null,
  387. argument : o.argument},
  388. doc,
  389. firstChild;
  390. try{
  391. doc = frame.contentWindow.document || frame.contentDocument || WINDOW.frames[id].document;
  392. if(doc){
  393. if(doc.body){
  394. if(/textarea/i.test((firstChild = doc.body.firstChild || {}).tagName)){ // json response wrapped in textarea
  395. r.responseText = firstChild.value;
  396. }else{
  397. r.responseText = doc.body.innerHTML;
  398. }
  399. }
  400. //in IE the document may still have a body even if returns XML.
  401. r.responseXML = doc.XMLDocument || doc;
  402. }
  403. }
  404. catch(e) {}
  405. Ext.EventManager.removeListener(frame, LOAD, cb, me);
  406. me.fireEvent(REQUESTCOMPLETE, me, r, o);
  407. function runCallback(fn, scope, args){
  408. if(Ext.isFunction(fn)){
  409. fn.apply(scope, args);
  410. }
  411. }
  412. runCallback(o.success, o.scope, [r, o]);
  413. runCallback(o.callback, o.scope, [o, true, r]);
  414. if(!me.debugUploads){
  415. setTimeout(function(){Ext.removeNode(frame);}, 100);
  416. }
  417. }
  418. Ext.EventManager.on(frame, LOAD, cb, this);
  419. form.submit();
  420. Ext.fly(form).set(buf);
  421. Ext.each(hiddens, function(h) {
  422. Ext.removeNode(h);
  423. });
  424. }
  425. });
  426. })();
  427. <span id='Ext-Ajax'>/**
  428. </span> * @class Ext.Ajax
  429. * @extends Ext.data.Connection
  430. * &lt;p&gt;The global Ajax request class that provides a simple way to make Ajax requests
  431. * with maximum flexibility.&lt;/p&gt;
  432. * &lt;p&gt;Since Ext.Ajax is a singleton, you can set common properties/events for it once
  433. * and override them at the request function level only if necessary.&lt;/p&gt;
  434. * &lt;p&gt;Common &lt;b&gt;Properties&lt;/b&gt; you may want to set are:&lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
  435. * &lt;li&gt;&lt;b&gt;&lt;tt&gt;{@link #method}&lt;/tt&gt;&lt;/b&gt;&lt;p class=&quot;sub-desc&quot;&gt;&lt;/p&gt;&lt;/li&gt;
  436. * &lt;li&gt;&lt;b&gt;&lt;tt&gt;{@link #extraParams}&lt;/tt&gt;&lt;/b&gt;&lt;p class=&quot;sub-desc&quot;&gt;&lt;/p&gt;&lt;/li&gt;
  437. * &lt;li&gt;&lt;b&gt;&lt;tt&gt;{@link #url}&lt;/tt&gt;&lt;/b&gt;&lt;p class=&quot;sub-desc&quot;&gt;&lt;/p&gt;&lt;/li&gt;
  438. * &lt;/ul&gt;&lt;/div&gt;
  439. * &lt;pre&gt;&lt;code&gt;
  440. // Default headers to pass in every request
  441. Ext.Ajax.defaultHeaders = {
  442. 'Powered-By': 'Ext'
  443. };
  444. * &lt;/code&gt;&lt;/pre&gt;
  445. * &lt;/p&gt;
  446. * &lt;p&gt;Common &lt;b&gt;Events&lt;/b&gt; you may want to set are:&lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
  447. * &lt;li&gt;&lt;b&gt;&lt;tt&gt;{@link Ext.data.Connection#beforerequest beforerequest}&lt;/tt&gt;&lt;/b&gt;&lt;p class=&quot;sub-desc&quot;&gt;&lt;/p&gt;&lt;/li&gt;
  448. * &lt;li&gt;&lt;b&gt;&lt;tt&gt;{@link Ext.data.Connection#requestcomplete requestcomplete}&lt;/tt&gt;&lt;/b&gt;&lt;p class=&quot;sub-desc&quot;&gt;&lt;/p&gt;&lt;/li&gt;
  449. * &lt;li&gt;&lt;b&gt;&lt;tt&gt;{@link Ext.data.Connection#requestexception requestexception}&lt;/tt&gt;&lt;/b&gt;&lt;p class=&quot;sub-desc&quot;&gt;&lt;/p&gt;&lt;/li&gt;
  450. * &lt;/ul&gt;&lt;/div&gt;
  451. * &lt;pre&gt;&lt;code&gt;
  452. // Example: show a spinner during all Ajax requests
  453. Ext.Ajax.on('beforerequest', this.showSpinner, this);
  454. Ext.Ajax.on('requestcomplete', this.hideSpinner, this);
  455. Ext.Ajax.on('requestexception', this.hideSpinner, this);
  456. * &lt;/code&gt;&lt;/pre&gt;
  457. * &lt;/p&gt;
  458. * &lt;p&gt;An example request:&lt;/p&gt;
  459. * &lt;pre&gt;&lt;code&gt;
  460. // Basic request
  461. Ext.Ajax.{@link Ext.data.Connection#request request}({
  462. url: 'foo.php',
  463. success: someFn,
  464. failure: otherFn,
  465. headers: {
  466. 'my-header': 'foo'
  467. },
  468. params: { foo: 'bar' }
  469. });
  470. // Simple ajax form submission
  471. Ext.Ajax.{@link Ext.data.Connection#request request}({
  472. form: 'some-form',
  473. params: 'foo=bar'
  474. });
  475. * &lt;/code&gt;&lt;/pre&gt;
  476. * &lt;/p&gt;
  477. * @singleton
  478. */
  479. Ext.Ajax = new Ext.data.Connection({
  480. <span id='Ext-Ajax-cfg-url'> /**
  481. </span> * @cfg {String} url @hide
  482. */
  483. <span id='Ext-Ajax-cfg-extraParams'> /**
  484. </span> * @cfg {Object} extraParams @hide
  485. */
  486. <span id='Ext-Ajax-cfg-defaultHeaders'> /**
  487. </span> * @cfg {Object} defaultHeaders @hide
  488. */
  489. <span id='Ext-Ajax-cfg-method'> /**
  490. </span> * @cfg {String} method (Optional) @hide
  491. */
  492. <span id='Ext-Ajax-cfg-timeout'> /**
  493. </span> * @cfg {Number} timeout (Optional) @hide
  494. */
  495. <span id='Ext-Ajax-cfg-autoAbort'> /**
  496. </span> * @cfg {Boolean} autoAbort (Optional) @hide
  497. */
  498. <span id='Ext-Ajax-cfg-disableCaching'> /**
  499. </span> * @cfg {Boolean} disableCaching (Optional) @hide
  500. */
  501. <span id='Ext-Ajax-property-disableCaching'> /**
  502. </span> * @property disableCaching
  503. * True to add a unique cache-buster param to GET requests. (defaults to true)
  504. * @type Boolean
  505. */
  506. <span id='Ext-Ajax-property-url'> /**
  507. </span> * @property url
  508. * The default URL to be used for requests to the server. (defaults to undefined)
  509. * If the server receives all requests through one URL, setting this once is easier than
  510. * entering it on every request.
  511. * @type String
  512. */
  513. <span id='Ext-Ajax-property-extraParams'> /**
  514. </span> * @property extraParams
  515. * An object containing properties which are used as extra parameters to each request made
  516. * by this object (defaults to undefined). Session information and other data that you need
  517. * to pass with each request are commonly put here.
  518. * @type Object
  519. */
  520. <span id='Ext-Ajax-property-defaultHeaders'> /**
  521. </span> * @property defaultHeaders
  522. * An object containing request headers which are added to each request made by this object
  523. * (defaults to undefined).
  524. * @type Object
  525. */
  526. <span id='Ext-Ajax-property-method'> /**
  527. </span> * @property method
  528. * The default HTTP method to be used for requests. Note that this is case-sensitive and
  529. * should be all caps (defaults to undefined; if not set but params are present will use
  530. * &lt;tt&gt;&quot;POST&quot;&lt;/tt&gt;, otherwise will use &lt;tt&gt;&quot;GET&quot;&lt;/tt&gt;.)
  531. * @type String
  532. */
  533. <span id='Ext-Ajax-property-timeout'> /**
  534. </span> * @property timeout
  535. * The timeout in milliseconds to be used for requests. (defaults to 30000)
  536. * @type Number
  537. */
  538. <span id='Ext-Ajax-property-autoAbort'> /**
  539. </span> * @property autoAbort
  540. * Whether a new request should abort any pending requests. (defaults to false)
  541. * @type Boolean
  542. */
  543. autoAbort : false,
  544. <span id='Ext-Ajax-method-serializeForm'> /**
  545. </span> * Serialize the passed form into a url encoded string
  546. * @param {String/HTMLElement} form
  547. * @return {String}
  548. */
  549. serializeForm : function(form){
  550. return Ext.lib.Ajax.serializeForm(form);
  551. }
  552. });
  553. </pre>
  554. </body>
  555. </html>