f72acddd9c34f75facce3d31e1afae1dea3e3488.svn-base 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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.ProgressBar = Ext.extend(Ext.BoxComponent, {
  7. baseCls : "x-progress",
  8. waitTimer : null,
  9. initComponent : function() {
  10. Ext.ProgressBar.superclass.initComponent.call(this);
  11. this.addEvents("update")
  12. },
  13. onRender : function(D, A) {
  14. Ext.ProgressBar.superclass.onRender.call(this, D, A);
  15. var C = new Ext.Template("<div class=\"{cls}-wrap\">",
  16. "<div class=\"{cls}-inner\">", "<div class=\"{cls}-bar\">",
  17. "<div class=\"{cls}-text\">", "<div>&#160;</div>", "</div>",
  18. "</div>", "<div class=\"{cls}-text {cls}-text-back\">",
  19. "<div>&#160;</div>", "</div>", "</div>", "</div>");
  20. if (A) {
  21. this.el = C.insertBefore(A, {
  22. cls : this.baseCls
  23. }, true)
  24. } else {
  25. this.el = C.append(D, {
  26. cls : this.baseCls
  27. }, true)
  28. }
  29. if (this.id) {
  30. this.el.dom.id = this.id
  31. }
  32. var B = this.el.dom.firstChild;
  33. this.progressBar = Ext.get(B.firstChild);
  34. if (this.textEl) {
  35. this.textEl = Ext.get(this.textEl);
  36. delete this.textTopEl
  37. } else {
  38. this.textTopEl = Ext.get(this.progressBar.dom.firstChild);
  39. var E = Ext.get(B.childNodes[1]);
  40. this.textTopEl.setStyle("z-index", 99).addClass("x-hidden");
  41. this.textEl = new Ext.CompositeElement([
  42. this.textTopEl.dom.firstChild, E.dom.firstChild]);
  43. this.textEl.setWidth(B.offsetWidth)
  44. }
  45. if (this.value) {
  46. this.updateProgress(this.value, this.text)
  47. } else {
  48. this.updateText(this.text)
  49. }
  50. this.setSize(this.width || "auto", "auto");
  51. this.progressBar.setHeight(B.offsetHeight)
  52. },
  53. updateProgress : function(B, C) {
  54. this.value = B || 0;
  55. if (C) {
  56. this.updateText(C)
  57. }
  58. var A = Math.floor(B * this.el.dom.firstChild.offsetWidth);
  59. this.progressBar.setWidth(A);
  60. if (this.textTopEl) {
  61. this.textTopEl.removeClass("x-hidden").setWidth(A)
  62. }
  63. this.fireEvent("update", this, B, C);
  64. return this
  65. },
  66. wait : function(B) {
  67. if (!this.waitTimer) {
  68. var A = this;
  69. B = B || {};
  70. this.waitTimer = Ext.TaskMgr.start({
  71. run : function(C) {
  72. var D = B.increment || 10;
  73. this
  74. .updateProgress(((((C + D) % D) + 1) * (100 / D))
  75. * 0.01)
  76. },
  77. interval : B.interval || 1000,
  78. duration : B.duration,
  79. onStop : function() {
  80. if (B.fn) {
  81. B.fn.apply(B.scope || this)
  82. }
  83. this.reset()
  84. },
  85. scope : A
  86. })
  87. }
  88. return this
  89. },
  90. isWaiting : function() {
  91. return this.waitTimer != null
  92. },
  93. updateText : function(A) {
  94. this.text = A || "&#160;";
  95. this.textEl.update(this.text);
  96. return this
  97. },
  98. setSize : function(A, C) {
  99. Ext.ProgressBar.superclass.setSize.call(this, A, C);
  100. if (this.textTopEl) {
  101. var B = this.el.dom.firstChild;
  102. this.textEl.setSize(B.offsetWidth, B.offsetHeight)
  103. }
  104. return this
  105. },
  106. reset : function(A) {
  107. this.updateProgress(0);
  108. if (this.textTopEl) {
  109. this.textTopEl.addClass("x-hidden")
  110. }
  111. if (this.waitTimer) {
  112. this.waitTimer.onStop = null;
  113. Ext.TaskMgr.stop(this.waitTimer);
  114. this.waitTimer = null
  115. }
  116. if (A === true) {
  117. this.hide()
  118. }
  119. return this
  120. }
  121. });
  122. Ext.reg("progress", Ext.ProgressBar);