summaryrefslogtreecommitdiffhomepage
path: root/libs/cbi/htdocs/luci-static
diff options
context:
space:
mode:
authorSteven Barth <steven@midlink.org>2008-08-17 18:32:53 +0000
committerSteven Barth <steven@midlink.org>2008-08-17 18:32:53 +0000
commit97ce1ad8adf935e2aa0d1b13f07b16d2d950053f (patch)
treed5eafec4b6996a6dc64046fd1d46a8f299cd4246 /libs/cbi/htdocs/luci-static
parent1d08361bea91c11ba2f82f3ab3004c067ebabc85 (diff)
Preparing rewrite of WiFi configuration
Diffstat (limited to 'libs/cbi/htdocs/luci-static')
-rw-r--r--libs/cbi/htdocs/luci-static/resources/cbi.js86
1 files changed, 48 insertions, 38 deletions
diff --git a/libs/cbi/htdocs/luci-static/resources/cbi.js b/libs/cbi/htdocs/luci-static/resources/cbi.js
index 78a9e90bf6..d0e31e483a 100644
--- a/libs/cbi/htdocs/luci-static/resources/cbi.js
+++ b/libs/cbi/htdocs/luci-static/resources/cbi.js
@@ -1,38 +1,30 @@
-var cbi_d = {};
+var cbi_d = [];
-function cbi_d_add(field, target, value) {
- if (!cbi_d[target]) {
- cbi_d[target] = {};
- }
- if (!cbi_d[target][value]) {
- cbi_d[target][value] = [];
- }
-
+function cbi_d_add(field, dep) {
var obj = document.getElementById(field);
if (obj) {
- var entry = {
- "node": obj,
- "parent": obj.parentNode,
- "next": obj.nextSibling
- }
- cbi_d[target][value].unshift(entry);
- }
-}
-
-function cbi_d_update(target) {
- if (!cbi_d[target]) {
- return;
- }
-
- for (var x in cbi_d[target]) {
- for (var i=0; i<cbi_d[target][x].length; i++) {
- var entry = cbi_d[target][x][i];
- if (entry.node.parentNode) {
- entry.parent.removeChild(entry.node)
+ var entry
+ for (var i=0; i<cbi_d.length; i++) {
+ if (cbi_d[i].id == field) {
+ entry = cbi_d[i];
+ break;
}
}
+ if (!entry) {
+ entry = {
+ "id": field,
+ "node": obj,
+ "parent": obj.parentNode,
+ "next": obj.nextSibling,
+ "deps": []
+ };
+ cbi_d.unshift(entry);
+ }
+ entry.deps.push(dep)
}
-
+}
+
+function cbi_d_value(target) {
var t = document.getElementById(target);
var value
@@ -46,21 +38,39 @@ function cbi_d_update(target) {
}
}
- if (cbi_d[target][value]) {
- for (var i=0; i<cbi_d[target][value].length; i++) {
- var entry = cbi_d[target][value][i];
+ return value
+}
+
+function cbi_d_check(deps) {
+ for (var i=0; i<deps.length; i++) {
+ var istat = true
+ for (var j in deps[i]) {
+ istat = (istat && cbi_d_value(j) == deps[i][j])
+ }
+ if (istat) {
+ return true
+ }
+ }
+}
+
+function cbi_d_update() {
+ var state = false;
+ for (var i=0; i<cbi_d.length; i++) {
+ var entry = cbi_d[i];
+ if (entry.node.parentNode && !cbi_d_check(entry.deps)) {
+ entry.parent.removeChild(entry.node);
+ state = (state || !entry.node.parentNode)
+ } else if (!entry.node.parentNode && cbi_d_check(entry.deps)) {
if (!entry.next) {
entry.parent.appendChild(entry.node);
} else {
entry.parent.insertBefore(entry.node, entry.next);
- }
+ }
+ state = (state || entry.node.parentNode)
}
}
-}
-
-function cbi_d_init() {
- for (var x in cbi_d) {
- cbi_d_update(x);
+ if (state) {
+ cbi_d_update();
}
}