]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/javascript/widgets/ProgressBar.js
*** empty log message ***
[Evergreen.git] / Open-ILS / src / javascript / widgets / ProgressBar.js
1 function ProgressBar(size,interval) {
2
3         if(interval == null) interval = 100;
4         if(size == null) size = 10;
5         this.is_running = false;
6
7         this.size = size;
8         this.interval = interval;
9
10         this.div = createAppElement("div");
11         this.div.className = "progress_bar";
12         this.current    = 0;
13         this.timeoutId;
14
15         this.percentDiv = createAppElement("div");
16         add_css_class(this.percentDiv, "progress_percent");
17
18         var divWidth = 100 / parseInt(size);
19         for( i = 0; i!= size; i++ ) {
20                 var div = createAppElement("div");
21                 div.className = "progress_bar_chunk";
22                 div.style.width = "" + divWidth + "%";
23                 this.div.appendChild(div);
24         }
25 }
26
27 ProgressBar.prototype.running = function() {
28         return this.is_running;
29 }
30
31 ProgressBar.prototype.getNode = function() {
32         return this.div;
33 }
34
35 ProgressBar.prototype.next = function() {
36         this.manualNext();
37         var obj = this;
38         this.timeoutId = setTimeout( function(){ obj.next(); }, this.interval );
39 }
40
41 ProgressBar.prototype.start = function() {
42         this.is_running = true;
43         this.next();
44 }
45
46 ProgressBar.prototype.stop = function() {
47         this.is_running = false;
48         this.current = this.size;
49         clearTimeout(this.timeoutId);
50         for(var i in this.div.childNodes) {
51                 this.div.childNodes[i].className = "progress_bar_chunk_active";
52         }
53         add_css_class(this.percentDiv, "hide_me");
54         this.percentDiv.innerHTML = "";
55 }
56
57
58         
59 ProgressBar.prototype.manualNext = function() {
60         if( this.current == this.size ) {
61                 for( var i in this.div.childNodes ) {
62                         if(!this.div.childNodes[i])
63                         this.div.childNodes[i].className = "progress_bar_chunk";
64                 }
65                 this.current = 0;
66         } else {
67                 var node = this.div.childNodes[this.current];
68                 node.className = "progress_bar_chunk_active";
69                 this.current = parseInt(this.current) + 1;
70         }
71
72         this.percentDiv.innerHTML = (parseInt(this.current) / parseInt(this.size) * 100) + "%";
73 }