Web Interface For Lite Argus Control modules
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.

110 lines
3.0 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*!
  2. * Ext JS Library 3.3.1
  3. * Copyright(c) 2006-2010 Sencha Inc.
  4. * licensing@sencha.com
  5. * http://www.sencha.com/license
  6. */
  7. Ext.onReady(function(){
  8. //==== Progress bar 1 ====
  9. var pbar1 = new Ext.ProgressBar({
  10. text:'Initializing...'
  11. });
  12. var btn1 = Ext.get('btn1');
  13. btn1.on('click', function(){
  14. Ext.fly('p1text').update('Working');
  15. if (!pbar1.rendered){
  16. pbar1.render('p1');
  17. }else{
  18. pbar1.text = 'Initializing...';
  19. pbar1.show();
  20. }
  21. Runner.run(pbar1, Ext.get('btn1'), 10, function(){
  22. pbar1.reset(true);
  23. Ext.fly('p1text').update('Done.').show();
  24. });
  25. });
  26. //==== Progress bar 2 ====
  27. var pbar2 = new Ext.ProgressBar({
  28. text:'Ready',
  29. id:'pbar2',
  30. cls:'left-align',
  31. renderTo:'p2'
  32. });
  33. var btn2 = Ext.get('btn2');
  34. btn2.on('click', function(){
  35. Runner.run(pbar2, btn2, 12, function(){
  36. pbar2.reset();
  37. pbar2.updateText('Done.');
  38. });
  39. });
  40. //==== Progress bar 3 ====
  41. var pbar3 = new Ext.ProgressBar({
  42. id:'pbar3',
  43. width:300,
  44. renderTo:'p3'
  45. });
  46. pbar3.on('update', function(val){
  47. //You can handle this event at each progress interval 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)+'% completed...');
  92. }else{
  93. pbar.updateProgress(v/count, 'Loading item ' + v + ' of '+count+'...');
  94. }
  95. }
  96. };
  97. };
  98. return {
  99. run : function(pbar, btn, count, cb){
  100. btn.dom.disabled = true;
  101. var ms = 5000/count;
  102. for(var i = 1; i < (count+2); i++){
  103. setTimeout(f(i, pbar, btn, count, cb), i*ms);
  104. }
  105. }
  106. }
  107. }();