810a6433faa7c528f0c078eeaf039475edad0a9f.svn-base 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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.Updater = function(B, A) {
  7. B = Ext.get(B);
  8. if (!A && B.updateManager) {
  9. return B.updateManager
  10. }
  11. this.el = B;
  12. this.defaultUrl = null;
  13. this.addEvents("beforeupdate", "update", "failure");
  14. var C = Ext.Updater.defaults;
  15. this.sslBlankUrl = C.sslBlankUrl;
  16. this.disableCaching = C.disableCaching;
  17. this.indicatorText = C.indicatorText;
  18. this.showLoadIndicator = C.showLoadIndicator;
  19. this.timeout = C.timeout;
  20. this.loadScripts = C.loadScripts;
  21. this.transaction = null;
  22. this.autoRefreshProcId = null;
  23. this.refreshDelegate = this.refresh.createDelegate(this);
  24. this.updateDelegate = this.update.createDelegate(this);
  25. this.formUpdateDelegate = this.formUpdate.createDelegate(this);
  26. if (!this.renderer) {
  27. this.renderer = new Ext.Updater.BasicRenderer()
  28. }
  29. Ext.Updater.superclass.constructor.call(this)
  30. };
  31. Ext.extend(Ext.Updater, Ext.util.Observable, {
  32. getEl : function() {
  33. return this.el
  34. },
  35. update : function(B, F, H, D) {
  36. if (this.fireEvent("beforeupdate", this.el, B, F) !== false) {
  37. var G = this.method, A, C;
  38. if (typeof B == "object") {
  39. A = B;
  40. B = A.url;
  41. F = F || A.params;
  42. H = H || A.callback;
  43. D = D || A.discardUrl;
  44. C = A.scope;
  45. if (typeof A.method != "undefined") {
  46. G = A.method
  47. }
  48. if (typeof A.nocache != "undefined") {
  49. this.disableCaching = A.nocache
  50. }
  51. if (typeof A.text != "undefined") {
  52. this.indicatorText = "<div class=\"loading-indicator\">"
  53. + A.text + "</div>"
  54. }
  55. if (typeof A.scripts != "undefined") {
  56. this.loadScripts = A.scripts
  57. }
  58. if (typeof A.timeout != "undefined") {
  59. this.timeout = A.timeout
  60. }
  61. }
  62. this.showLoading();
  63. if (!D) {
  64. this.defaultUrl = B
  65. }
  66. if (typeof B == "function") {
  67. B = B.call(this)
  68. }
  69. G = G || (F ? "POST" : "GET");
  70. if (G == "GET") {
  71. B = this.prepareUrl(B)
  72. }
  73. var E = Ext.apply(A || {}, {
  74. url : B,
  75. params : (typeof F == "function" && C) ? F
  76. .createDelegate(C) : F,
  77. success : this.processSuccess,
  78. failure : this.processFailure,
  79. scope : this,
  80. callback : undefined,
  81. timeout : (this.timeout * 1000),
  82. argument : {
  83. "options" : A,
  84. "url" : B,
  85. "form" : null,
  86. "callback" : H,
  87. "scope" : C || window,
  88. "params" : F
  89. }
  90. });
  91. this.transaction = Ext.Ajax.request(E)
  92. }
  93. },
  94. formUpdate : function(C, A, B, D) {
  95. if (this.fireEvent("beforeupdate", this.el, C, A) !== false) {
  96. if (typeof A == "function") {
  97. A = A.call(this)
  98. }
  99. C = Ext.getDom(C);
  100. this.transaction = Ext.Ajax.request({
  101. form : C,
  102. url : A,
  103. success : this.processSuccess,
  104. failure : this.processFailure,
  105. scope : this,
  106. timeout : (this.timeout * 1000),
  107. argument : {
  108. "url" : A,
  109. "form" : C,
  110. "callback" : D,
  111. "reset" : B
  112. }
  113. });
  114. this.showLoading.defer(1, this)
  115. }
  116. },
  117. refresh : function(A) {
  118. if (this.defaultUrl == null) {
  119. return
  120. }
  121. this.update(this.defaultUrl, null, A, true)
  122. },
  123. startAutoRefresh : function(B, C, D, E, A) {
  124. if (A) {
  125. this.update(C || this.defaultUrl, D, E, true)
  126. }
  127. if (this.autoRefreshProcId) {
  128. clearInterval(this.autoRefreshProcId)
  129. }
  130. this.autoRefreshProcId = setInterval(this.update
  131. .createDelegate(this, [C || this.defaultUrl, D,
  132. E, true]), B * 1000)
  133. },
  134. stopAutoRefresh : function() {
  135. if (this.autoRefreshProcId) {
  136. clearInterval(this.autoRefreshProcId);
  137. delete this.autoRefreshProcId
  138. }
  139. },
  140. isAutoRefreshing : function() {
  141. return this.autoRefreshProcId ? true : false
  142. },
  143. showLoading : function() {
  144. if (this.showLoadIndicator) {
  145. this.el.update(this.indicatorText)
  146. }
  147. },
  148. prepareUrl : function(B) {
  149. if (this.disableCaching) {
  150. var A = "_dc=" + (allGetServerTime().getTime());
  151. if (B.indexOf("?") !== -1) {
  152. B += "&" + A
  153. } else {
  154. B += "?" + A
  155. }
  156. }
  157. return B
  158. },
  159. processSuccess : function(A) {
  160. this.transaction = null;
  161. if (A.argument.form && A.argument.reset) {
  162. try {
  163. A.argument.form.reset()
  164. } catch (B) {
  165. }
  166. }
  167. if (this.loadScripts) {
  168. this.renderer.render(this.el, A, this, this.updateComplete
  169. .createDelegate(this, [A]))
  170. } else {
  171. this.renderer.render(this.el, A, this);
  172. this.updateComplete(A)
  173. }
  174. },
  175. updateComplete : function(A) {
  176. this.fireEvent("update", this.el, A);
  177. if (typeof A.argument.callback == "function") {
  178. A.argument.callback.call(A.argument.scope, this.el, true,
  179. A, A.argument.options)
  180. }
  181. },
  182. processFailure : function(A) {
  183. this.transaction = null;
  184. this.fireEvent("failure", this.el, A);
  185. if (typeof A.argument.callback == "function") {
  186. A.argument.callback.call(A.argument.scope, this.el, false,
  187. A, A.argument.options)
  188. }
  189. },
  190. setRenderer : function(A) {
  191. this.renderer = A
  192. },
  193. getRenderer : function() {
  194. return this.renderer
  195. },
  196. setDefaultUrl : function(A) {
  197. this.defaultUrl = A
  198. },
  199. abort : function() {
  200. if (this.transaction) {
  201. Ext.Ajax.abort(this.transaction)
  202. }
  203. },
  204. isUpdating : function() {
  205. if (this.transaction) {
  206. return Ext.Ajax.isLoading(this.transaction)
  207. }
  208. return false
  209. }
  210. });
  211. Ext.Updater.defaults = {
  212. timeout : 30,
  213. loadScripts : false,
  214. sslBlankUrl : (Ext.SSL_SECURE_URL || "javascript:false"),
  215. disableCaching : false,
  216. showLoadIndicator : true,
  217. indicatorText : "<div class=\"loading-indicator\">Loading...</div>"
  218. };
  219. Ext.Updater.updateElement = function(D, C, E, B) {
  220. var A = Ext.get(D).getUpdater();
  221. Ext.apply(A, B);
  222. A.update(C, E, B ? B.callback : null)
  223. };
  224. Ext.Updater.update = Ext.Updater.updateElement;
  225. Ext.Updater.BasicRenderer = function() {
  226. };
  227. Ext.Updater.BasicRenderer.prototype = {
  228. render : function(C, A, B, D) {
  229. C.update(A.responseText, B.loadScripts, D)
  230. }
  231. };
  232. Ext.UpdateManager = Ext.Updater;