1ecbafe82c5850ecc2971a421faa1d3cebece0b8.svn-base 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*
  2. * Ext JS Library 2.0 Copyright(c) 2006-2007, Ext JS, LLC. licensing@extjs.com
  3. *
  4. * http://extjs.com/license
  5. */
  6. Ext.data.Connection = function(A) {
  7. Ext.apply(this, A);
  8. this.addEvents("beforerequest", "requestcomplete", "requestexception");
  9. Ext.data.Connection.superclass.constructor.call(this)
  10. };
  11. Ext.extend(Ext.data.Connection, Ext.util.Observable, {
  12. timeout : 30000,
  13. autoAbort : false,
  14. disableCaching : true,
  15. request : function(E) {
  16. if (this.fireEvent("beforerequest", this, E) !== false) {
  17. var C = E.params;
  18. if (typeof C == "function") {
  19. C = C.call(E.scope || window, E)
  20. }
  21. if (typeof C == "object") {
  22. C = Ext.urlEncode(C)
  23. }
  24. if (this.extraParams) {
  25. var G = Ext.urlEncode(this.extraParams);
  26. C = C ? (C + "&" + G) : G
  27. }
  28. var B = E.url || this.url;
  29. if (typeof B == "function") {
  30. B = B.call(E.scope || window, E)
  31. }
  32. if (E.form) {
  33. var D = Ext.getDom(E.form);
  34. B = B || D.action;
  35. var I = D.getAttribute("enctype");
  36. if (E.isUpload
  37. || (I && I.toLowerCase() == "multipart/form-data")) {
  38. return this.doFormUpload(E, C, B)
  39. }
  40. var H = Ext.lib.Ajax.serializeForm(D);
  41. C = C ? (C + "&" + H) : H
  42. }
  43. var J = E.headers;
  44. if (this.defaultHeaders) {
  45. J = Ext.apply(J || {}, this.defaultHeaders);
  46. if (!E.headers) {
  47. E.headers = J
  48. }
  49. }
  50. var F = {
  51. success : this.handleResponse,
  52. failure : this.handleFailure,
  53. scope : this,
  54. argument : {
  55. options : E
  56. },
  57. timeout : this.timeout
  58. };
  59. var A = E.method || this.method || (C ? "POST" : "GET");
  60. if (A == "GET"
  61. && (this.disableCaching && E.disableCaching !== false)
  62. || E.disableCaching === true) {
  63. B += (B.indexOf("?") != -1 ? "&" : "?") + "_dc="
  64. + (allGetServerTime().getTime())
  65. }
  66. if (typeof E.autoAbort == "boolean") {
  67. if (E.autoAbort) {
  68. this.abort()
  69. }
  70. } else {
  71. if (this.autoAbort !== false) {
  72. this.abort()
  73. }
  74. }
  75. if ((A == "GET" && C) || E.xmlData || E.jsonData) {
  76. B += (B.indexOf("?") != -1 ? "&" : "?") + C;
  77. C = ""
  78. }
  79. this.transId = Ext.lib.Ajax.request(A, B, F, C, E);
  80. return this.transId
  81. } else {
  82. Ext.callback(E.callback, E.scope, [E, null, null]);
  83. return null
  84. }
  85. },
  86. isLoading : function(A) {
  87. if (A) {
  88. return Ext.lib.Ajax.isCallInProgress(A)
  89. } else {
  90. return this.transId ? true : false
  91. }
  92. },
  93. abort : function(A) {
  94. if (A || this.isLoading()) {
  95. Ext.lib.Ajax.abort(A || this.transId)
  96. }
  97. },
  98. handleResponse : function(A) {
  99. this.transId = false;
  100. var B = A.argument.options;
  101. A.argument = B ? B.argument : null;
  102. this.fireEvent("requestcomplete", this, A, B);
  103. Ext.callback(B.success, B.scope, [A, B]);
  104. Ext.callback(B.callback, B.scope, [B, true, A])
  105. },
  106. handleFailure : function(A, C) {
  107. this.transId = false;
  108. var B = A.argument.options;
  109. A.argument = B ? B.argument : null;
  110. this.fireEvent("requestexception", this, A, B, C);
  111. Ext.callback(B.failure, B.scope, [A, B]);
  112. Ext.callback(B.callback, B.scope, [B, false, A])
  113. },
  114. doFormUpload : function(E, A, B) {
  115. var C = Ext.id();
  116. var F = document.createElement("iframe");
  117. F.id = C;
  118. F.name = C;
  119. F.className = "x-hidden";
  120. if (Ext.isIE) {
  121. F.src = Ext.SSL_SECURE_URL
  122. }
  123. document.body.appendChild(F);
  124. if (Ext.isIE) {
  125. document.frames[C].name = C
  126. }
  127. var D = Ext.getDom(E.form);
  128. D.target = C;
  129. D.method = "POST";
  130. D.enctype = D.encoding = "multipart/form-data";
  131. if (B) {
  132. D.action = B
  133. }
  134. var L, J;
  135. if (A) {
  136. L = [];
  137. A = Ext.urlDecode(A, false);
  138. for (var H in A) {
  139. if (A.hasOwnProperty(H)) {
  140. J = document.createElement("input");
  141. J.type = "hidden";
  142. J.name = H;
  143. J.value = A[H];
  144. D.appendChild(J);
  145. L.push(J)
  146. }
  147. }
  148. }
  149. function G() {
  150. var M = {
  151. responseText : "",
  152. responseXML : null
  153. };
  154. M.argument = E ? E.argument : null;
  155. try {
  156. var O;
  157. if (Ext.isIE) {
  158. O = F.contentWindow.document
  159. } else {
  160. O = (F.contentDocument || window.frames[C].document)
  161. }
  162. if (O && O.body) {
  163. M.responseText = O.body.innerHTML
  164. }
  165. if (O && O.XMLDocument) {
  166. M.responseXML = O.XMLDocument
  167. } else {
  168. M.responseXML = O
  169. }
  170. } catch (N) {
  171. }
  172. Ext.EventManager.removeListener(F, "load", G, this);
  173. this.fireEvent("requestcomplete", this, M, E);
  174. Ext.callback(E.success, E.scope, [M, E]);
  175. Ext.callback(E.callback, E.scope, [E, true, M]);
  176. setTimeout(function() {
  177. Ext.removeNode(F)
  178. }, 100)
  179. }
  180. Ext.EventManager.on(F, "load", G, this);
  181. D.submit();
  182. if (L) {
  183. for (var I = 0, K = L.length; I < K; I++) {
  184. Ext.removeNode(L[I])
  185. }
  186. }
  187. }
  188. });
  189. Ext.Ajax = new Ext.data.Connection({
  190. autoAbort : false,
  191. serializeForm : function(A) {
  192. return Ext.lib.Ajax.serializeForm(A)
  193. }
  194. });