DHTML progress bar for glacial rate adding and editing, closes: Bug#1100
[freeside.git] / httemplate / elements / qlib / button.js
1 /**\r
2  * QLIB 1.0 Button 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 QButton_update() {\r
12     with (this) {\r
13         image.src = ((!enabled && res.imgD) || (value ? res.imgP : res.imgN)).src;\r
14     }\r
15 }\r
16 \r
17 function QButton_doEvent() {\r
18     with (this) {\r
19         if (enabled) {\r
20             if (res.style == 1) {\r
21                 this.value = value ? 0 : 1;\r
22                 update();\r
23             }\r
24             onClick(value, tag);\r
25         }\r
26     }\r
27     return false;\r
28 }\r
29 \r
30 function QButton_enable(state) {\r
31     this.enabled = state;\r
32     this.update();\r
33 }\r
34 \r
35 function QButton_set(value) {\r
36     if (this.enabled) {\r
37         this.value = value ? 1 : 0;\r
38         this.update();\r
39     }\r
40     return true;\r
41 }\r
42 \r
43 function QButton(parent, name, res, tooltip) {\r
44     this.init(parent, name);\r
45     if (res) {\r
46         this.res = res;\r
47         this.tip = tooltip || "";\r
48         this.enabled = true;\r
49         this.value = 0;\r
50         this.set = QButton_set;\r
51         this.enable = QButton_enable;\r
52         this.update = QButton_update;\r
53         this.doEvent = QButton_doEvent;\r
54         this.onClick = QControl.event;\r
55         with (this) {\r
56             document.write('<a href="#" hidefocus="true" unselectable="on"' +\r
57                 (tip ? ' title="' + tip + '"' : '') + ' onClick="return ' + name +\r
58                 '.doEvent()" onMouseOver="' + (res.style == 2 ? name + '.set(1);' : '') +\r
59                 'window.top.status=' + name + '.tip;return true" onMouseOut="' +\r
60                 (!res.style || (res.style == 2) ? name + '.set();' : '') + 'window.top.status=\'\'"' +\r
61                 (!res.style ? ' onMouseDown="return ' + name + '.set(1)" onMouseUp="return ' + name + '.set()"' : '') +\r
62                 '><img class="qbutton" name="' + id + '" src="' + res.imgN.src + '" border="0" width="' +\r
63                 res.width + '" height="' + res.height + '"></a>');\r
64             this.image = document.images[id] || new Image(1, 1);\r
65         }\r
66     } else {\r
67         this.document.write("invalid resource");\r
68     }\r
69 }\r
70 QButton.prototype = new QControl();\r
71 QButton.NORMAL    = 0;\r
72 QButton.CHECKBOX  = 1;\r
73 QButton.WEB       = 2;\r
74 QButton.SIGNAL    = 3;\r