4ff65d61a9004b798a31cadcbd6df0e09b8fc549.svn-base 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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.onReady(function() {
  7. // ==== Progress bar 1 ====
  8. var pbar1 = new Ext.ProgressBar({
  9. text : 'Initializing...'
  10. });
  11. var btn1 = Ext.get('btn1');
  12. btn1.on('click', function() {
  13. Ext.fly('p1text').update('Working');
  14. if (!pbar1.rendered) {
  15. pbar1.render('p1');
  16. } else {
  17. pbar1.text = 'Initializing...';
  18. pbar1.show();
  19. }
  20. Runner.run(pbar1, Ext.get('btn1'), 10, function() {
  21. pbar1.reset(true);
  22. Ext.fly('p1text').update('Done.').show();
  23. });
  24. });
  25. // ==== Progress bar 2 ====
  26. var pbar2 = new Ext.ProgressBar({
  27. text : 'Ready',
  28. id : 'pbar2',
  29. cls : 'left-align',
  30. renderTo : 'p2'
  31. });
  32. var btn2 = Ext.get('btn2');
  33. btn2.on('click', function() {
  34. Runner.run(pbar2, btn2, 12, function() {
  35. pbar2.reset();
  36. pbar2.updateText('Done.');
  37. });
  38. });
  39. // ==== Progress bar 3 ====
  40. var pbar3 = new Ext.ProgressBar({
  41. id : 'pbar3',
  42. width : 300,
  43. renderTo : 'p3'
  44. });
  45. pbar3.on('update', function(val) {
  46. // You can handle this event at each progress interval
  47. // if
  48. // needed to perform some other action
  49. Ext.fly('p3text').dom.innerHTML += '.';
  50. });
  51. var btn3 = Ext.get('btn3');
  52. btn3.on('click', function() {
  53. Ext.fly('p3text').update('Working');
  54. btn3.dom.disabled = true;
  55. pbar3.wait({
  56. interval : 200,
  57. duration : 5000,
  58. increment : 15,
  59. fn : function() {
  60. btn3.dom.disabled = false;
  61. Ext.fly('p3text').update('Done');
  62. }
  63. });
  64. });
  65. // ==== Progress bar 4 ====
  66. var pbar4 = new Ext.ProgressBar({
  67. text : 'Waiting on you...',
  68. id : 'pbar4',
  69. textEl : 'p4text',
  70. cls : 'custom',
  71. renderTo : 'p4'
  72. });
  73. var btn4 = Ext.get('btn4');
  74. btn4.on('click', function() {
  75. Runner.run(pbar4, btn4, 19, function() {
  76. pbar4.updateText('All finished!');
  77. });
  78. });
  79. });
  80. // Please do not use the following code as a best practice! :)
  81. var Runner = function() {
  82. var f = function(v, pbar, btn, count, cb) {
  83. return function() {
  84. if (v > count) {
  85. btn.dom.disabled = false;
  86. cb();
  87. } else {
  88. if (pbar.id == 'pbar4') {
  89. // give this one a different count style for fun
  90. var i = v / count;
  91. pbar.updateProgress(i, Math.round(100 * i)
  92. + '% completed...');
  93. } else {
  94. pbar.updateProgress(v / count, 'Loading item ' + v + ' of '
  95. + count + '...');
  96. }
  97. }
  98. };
  99. };
  100. return {
  101. run : function(pbar, btn, count, cb) {
  102. btn.dom.disabled = true;
  103. var ms = 5000 / count;
  104. for (var i = 1; i < (count + 2); i++) {
  105. setTimeout(f(i, pbar, btn, count, cb), i * ms);
  106. }
  107. }
  108. }
  109. }();