source: trunk/web/addons/job_monarch/lib/extjs/examples/simple-widgets/progress-bar.js @ 619

Last change on this file since 619 was 619, checked in by ramonb, 15 years ago

lib/:

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