You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
3.6 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. This file is part of Ext JS 3.4
  3. Copyright (c) 2011-2013 Sencha Inc
  4. Contact: http://www.sencha.com/contact
  5. GNU General Public License Usage
  6. This file may be used under the terms of the GNU General Public License version 3.0 as
  7. published by the Free Software Foundation and appearing in the file LICENSE included in the
  8. packaging of this file.
  9. Please review the following information to ensure the GNU General Public License version 3.0
  10. requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  11. If you are unsure which license is appropriate for your use, please contact the sales department
  12. at http://www.sencha.com/contact.
  13. Build date: 2013-04-03 15:07:25
  14. */
  15. Ext.onReady(function(){
  16. //==== Progress bar 1 ====
  17. var pbar1 = new Ext.ProgressBar({
  18. text:'Initializing...'
  19. });
  20. var btn1 = Ext.get('btn1');
  21. btn1.on('click', function(){
  22. Ext.fly('p1text').update('Working');
  23. if (!pbar1.rendered){
  24. pbar1.render('p1');
  25. }else{
  26. pbar1.text = 'Initializing...';
  27. pbar1.show();
  28. }
  29. Runner.run(pbar1, Ext.get('btn1'), 10, function(){
  30. pbar1.reset(true);
  31. Ext.fly('p1text').update('Done.').show();
  32. });
  33. });
  34. //==== Progress bar 2 ====
  35. var pbar2 = new Ext.ProgressBar({
  36. text:'Ready',
  37. id:'pbar2',
  38. cls:'left-align',
  39. renderTo:'p2'
  40. });
  41. var btn2 = Ext.get('btn2');
  42. btn2.on('click', function(){
  43. Runner.run(pbar2, btn2, 12, function(){
  44. pbar2.reset();
  45. pbar2.updateText('Done.');
  46. });
  47. });
  48. //==== Progress bar 3 ====
  49. var pbar3 = new Ext.ProgressBar({
  50. id:'pbar3',
  51. width:300,
  52. renderTo:'p3'
  53. });
  54. pbar3.on('update', function(val){
  55. //You can handle this event at each progress interval if
  56. //needed to perform some other action
  57. Ext.fly('p3text').dom.innerHTML += '.';
  58. });
  59. var btn3 = Ext.get('btn3');
  60. btn3.on('click', function(){
  61. Ext.fly('p3text').update('Working');
  62. btn3.dom.disabled = true;
  63. pbar3.wait({
  64. interval:200,
  65. duration:5000,
  66. increment:15,
  67. fn:function(){
  68. btn3.dom.disabled = false;
  69. Ext.fly('p3text').update('Done');
  70. }
  71. });
  72. });
  73. //==== Progress bar 4 ====
  74. var pbar4 = new Ext.ProgressBar({
  75. text:'Waiting on you...',
  76. id:'pbar4',
  77. textEl:'p4text',
  78. cls:'custom',
  79. renderTo:'p4'
  80. });
  81. var btn4 = Ext.get('btn4');
  82. btn4.on('click', function(){
  83. Runner.run(pbar4, btn4, 19, function(){
  84. pbar4.updateText('All finished!');
  85. });
  86. });
  87. });
  88. //Please do not use the following code as a best practice! :)
  89. var Runner = function(){
  90. var f = function(v, pbar, btn, count, cb){
  91. return function(){
  92. if(v > count){
  93. btn.dom.disabled = false;
  94. cb();
  95. }else{
  96. if(pbar.id=='pbar4'){
  97. //give this one a different count style for fun
  98. var i = v/count;
  99. pbar.updateProgress(i, Math.round(100*i)+'% completed...');
  100. }else{
  101. pbar.updateProgress(v/count, 'Loading item ' + v + ' of '+count+'...');
  102. }
  103. }
  104. };
  105. };
  106. return {
  107. run : function(pbar, btn, count, cb){
  108. btn.dom.disabled = true;
  109. var ms = 5000/count;
  110. for(var i = 1; i < (count+2); i++){
  111. setTimeout(f(i, pbar, btn, count, cb), i*ms);
  112. }
  113. }
  114. }
  115. }();