DHTML progress bar for glacial rate adding and editing, closes: Bug#1100
[freeside.git] / httemplate / elements / qlib / progress.js
diff --git a/httemplate/elements/qlib/progress.js b/httemplate/elements/qlib/progress.js
new file mode 100644 (file)
index 0000000..2de077e
--- /dev/null
@@ -0,0 +1,73 @@
+/**\r
+ * QLIB 1.0 Progress Control\r
+ * Copyright (C) 2002 2003, Quazzle.com Serge Dolgov\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ * http://qlib.quazzle.com\r
+ */\r
+\r
+function QProgress_update() {\r
+    with (this) {\r
+        var i = low;\r
+        for (var j=0; j<size; j++) {\r
+            images[j].src = i < value ? imgsrc1 : imgsrc0;\r
+            i += delta;\r
+        }\r
+    }\r
+}\r
+\r
+function QProgress_set(value) {\r
+    this.value = value - 0;\r
+    this.update();\r
+}\r
+\r
+function QProgress_setBounds(low, high) {\r
+    this.low = Math.min(low, high);\r
+    this.high = Math.max(low, high);\r
+    this.delta = (this.high - this.low) / this.size;\r
+    this.update();\r
+}\r
\r
+function QProgress(parent, name, res, size, style) {\r
+    this.init(parent, name);\r
+    if (res) {\r
+        this.res = res;\r
+        this.value = 0;\r
+        this.low = 0;\r
+        this.high = 100;\r
+        this.size = size || 10;\r
+        this.delta = 100 / this.size;\r
+        this.style = style || 0;\r
+        this.images = new Array(this.size);\r
+        this.imgsrc0 = res.list[0] && res.list[0].src;\r
+        this.imgsrc1 = res.list[1] && res.list[1].src;\r
+        this.set = QProgress_set;\r
+        this.update = QProgress_update;\r
+        this.setBounds = QProgress_setBounds;\r
+        with (this) {\r
+            var hor = this.style < 2;\r
+            var rev = this.style % 2;\r
+            document.write('<table class="qprogress" border="0"  cellspacing="0" cellpadding="0" unselectable="on" ' +\r
+                (hor ? 'width="' + (size * res.width) + '" height="' + res.height + '"><tr>' : 'width="' + res.width +\r
+                '" height="' + (size * res.height) + '">'));\r
+            for (var j=0; j<size; j++) {\r
+                document.write((hor ? '' : '<tr>') + '<td width="' + res.width + '" height="' + res.height +\r
+                    '" unselectable="on"><img name="' + id + (rev ? size - j - 1 : j) + '" src="' + res.list[0].src +\r
+                    '" border="0" width="' + res.width + '" height="' + res.height + '"></td>' + (hor ? '' : '</tr>'));\r
+            }\r
+            document.write((hor ? '</tr>' : '') + '</table>');\r
+            for (var j=0; j<size; j++) {\r
+                images[j] = document.images[id + j] || new Image(1, 1);\r
+            }\r
+        }\r
+    } else {\r
+        this.document.write("invalid resource");\r
+    }\r
+}\r
+QProgress.prototype = new QControl();\r
+QProgress.NORMAL    = 0;\r
+QProgress.REVERSE   = 1;\r
+QProgress.FALL      = 2;\r
+QProgress.RISE      = 3;\r