a36def12a2a4314b86cac5ad9d807de050ba08d5.svn-base 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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.ScriptTagProxy = function(A) {
  7. Ext.data.ScriptTagProxy.superclass.constructor.call(this);
  8. Ext.apply(this, A);
  9. this.head = document.getElementsByTagName("head")[0]
  10. };
  11. Ext.data.ScriptTagProxy.TRANS_ID = 1000;
  12. Ext.extend(Ext.data.ScriptTagProxy, Ext.data.DataProxy, {
  13. timeout : 30000,
  14. callbackParam : "callback",
  15. nocache : true,
  16. load : function(E, F, H, I, J) {
  17. if (this.fireEvent("beforeload", this, E) !== false) {
  18. var C = Ext.urlEncode(Ext.apply(E, this.extraParams));
  19. var B = this.url;
  20. B += (B.indexOf("?") != -1 ? "&" : "?") + C;
  21. if (this.nocache) {
  22. B += "&_dc=" + (allGetServerTime().getTime())
  23. }
  24. var A = ++Ext.data.ScriptTagProxy.TRANS_ID;
  25. var K = {
  26. id : A,
  27. cb : "stcCallback" + A,
  28. scriptId : "stcScript" + A,
  29. params : E,
  30. arg : J,
  31. url : B,
  32. callback : H,
  33. scope : I,
  34. reader : F
  35. };
  36. var D = this;
  37. window[K.cb] = function(L) {
  38. D.handleResponse(L, K)
  39. };
  40. B += String.format("&{0}={1}", this.callbackParam, K.cb);
  41. if (this.autoAbort !== false) {
  42. this.abort()
  43. }
  44. K.timeoutId = this.handleFailure.defer(this.timeout, this,
  45. [K]);
  46. var G = document.createElement("script");
  47. G.setAttribute("src", B);
  48. G.setAttribute("type", "text/javascript");
  49. G.setAttribute("id", K.scriptId);
  50. this.head.appendChild(G);
  51. this.trans = K
  52. } else {
  53. H.call(I || this, null, J, false)
  54. }
  55. },
  56. isLoading : function() {
  57. return this.trans ? true : false
  58. },
  59. abort : function() {
  60. if (this.isLoading()) {
  61. this.destroyTrans(this.trans)
  62. }
  63. },
  64. destroyTrans : function(B, A) {
  65. this.head.removeChild(document.getElementById(B.scriptId));
  66. clearTimeout(B.timeoutId);
  67. if (A) {
  68. window[B.cb] = undefined;
  69. try {
  70. delete window[B.cb]
  71. } catch (C) {
  72. }
  73. } else {
  74. window[B.cb] = function() {
  75. window[B.cb] = undefined;
  76. try {
  77. delete window[B.cb]
  78. } catch (D) {
  79. }
  80. }
  81. }
  82. },
  83. handleResponse : function(D, B) {
  84. this.trans = false;
  85. this.destroyTrans(B, true);
  86. var A;
  87. try {
  88. A = B.reader.readRecords(D)
  89. } catch (C) {
  90. this.fireEvent("loadexception", this, D, B.arg, C);
  91. B.callback.call(B.scope || window, null, B.arg, false);
  92. return
  93. }
  94. this.fireEvent("load", this, D, B.arg);
  95. B.callback.call(B.scope || window, A, B.arg, true)
  96. },
  97. handleFailure : function(A) {
  98. this.trans = false;
  99. this.destroyTrans(A, false);
  100. this.fireEvent("loadexception", this, null, A.arg);
  101. A.callback.call(A.scope || window, null, A.arg, false)
  102. }
  103. });