This commit was generated by cvs2svn to compensate for changes in r4407,
[freeside.git] / httemplate / elements / qlib / progress.js
1 /**\r
2  * QLIB 1.0 Progress Control\r
3  * Copyright (C) 2002 2003, Quazzle.com Serge Dolgov\r
4  * This program is free software; you can redistribute it and/or\r
5  * modify it under the terms of the GNU General Public License\r
6  * as published by the Free Software Foundation; either version 2\r
7  * of the License, or (at your option) any later version.\r
8  * http://qlib.quazzle.com\r
9  */\r
10 \r
11 function QProgress_update() {\r
12     with (this) {\r
13         var i = low;\r
14         for (var j=0; j<size; j++) {\r
15             images[j].src = i < value ? imgsrc1 : imgsrc0;\r
16             i += delta;\r
17         }\r
18     }\r
19 }\r
20 \r
21 function QProgress_set(value) {\r
22     this.value = value - 0;\r
23     this.update();\r
24 }\r
25 \r
26 function QProgress_setBounds(low, high) {\r
27     this.low = Math.min(low, high);\r
28     this.high = Math.max(low, high);\r
29     this.delta = (this.high - this.low) / this.size;\r
30     this.update();\r
31 }\r
32  \r
33 function QProgress(parent, name, res, size, style) {\r
34     this.init(parent, name);\r
35     if (res) {\r
36         this.res = res;\r
37         this.value = 0;\r
38         this.low = 0;\r
39         this.high = 100;\r
40         this.size = size || 10;\r
41         this.delta = 100 / this.size;\r
42         this.style = style || 0;\r
43         this.images = new Array(this.size);\r
44         this.imgsrc0 = res.list[0] && res.list[0].src;\r
45         this.imgsrc1 = res.list[1] && res.list[1].src;\r
46         this.set = QProgress_set;\r
47         this.update = QProgress_update;\r
48         this.setBounds = QProgress_setBounds;\r
49         with (this) {\r
50             var hor = this.style < 2;\r
51             var rev = this.style % 2;\r
52             document.write('<table class="qprogress" border="0"  cellspacing="0" cellpadding="0" unselectable="on" ' +\r
53                 (hor ? 'width="' + (size * res.width) + '" height="' + res.height + '"><tr>' : 'width="' + res.width +\r
54                 '" height="' + (size * res.height) + '">'));\r
55             for (var j=0; j<size; j++) {\r
56                 document.write((hor ? '' : '<tr>') + '<td width="' + res.width + '" height="' + res.height +\r
57                     '" unselectable="on"><img name="' + id + (rev ? size - j - 1 : j) + '" src="' + res.list[0].src +\r
58                     '" border="0" width="' + res.width + '" height="' + res.height + '"></td>' + (hor ? '' : '</tr>'));\r
59             }\r
60             document.write((hor ? '</tr>' : '') + '</table>');\r
61             for (var j=0; j<size; j++) {\r
62                 images[j] = document.images[id + j] || new Image(1, 1);\r
63             }\r
64         }\r
65     } else {\r
66         this.document.write("invalid resource");\r
67     }\r
68 }\r
69 QProgress.prototype = new QControl();\r
70 QProgress.NORMAL    = 0;\r
71 QProgress.REVERSE   = 1;\r
72 QProgress.FALL      = 2;\r
73 QProgress.RISE      = 3;\r