summaryrefslogtreecommitdiffhomepage
path: root/libs/cbi
diff options
context:
space:
mode:
Diffstat (limited to 'libs/cbi')
-rw-r--r--libs/cbi/htdocs/luci-static/resources/cbi.js86
-rw-r--r--libs/cbi/luasrc/cbi.lua16
-rw-r--r--libs/cbi/luasrc/view/cbi/cell_valuefooter.htm10
-rw-r--r--libs/cbi/luasrc/view/cbi/footer.htm2
-rw-r--r--libs/cbi/luasrc/view/cbi/full_valuefooter.htm10
-rw-r--r--libs/cbi/luasrc/view/cbi/lvalue.htm2
-rw-r--r--libs/cbi/luasrc/view/cbi/ucisection.htm13
7 files changed, 93 insertions, 46 deletions
diff --git a/libs/cbi/htdocs/luci-static/resources/cbi.js b/libs/cbi/htdocs/luci-static/resources/cbi.js
index 78a9e90bf..d0e31e483 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();
}
}
diff --git a/libs/cbi/luasrc/cbi.lua b/libs/cbi/luasrc/cbi.lua
index fed53f6ee..6cc090882 100644
--- a/libs/cbi/luasrc/cbi.lua
+++ b/libs/cbi/luasrc/cbi.lua
@@ -710,7 +710,15 @@ end
-- Add a dependencie to another section field
function AbstractValue.depends(self, field, value)
- table.insert(self.deps, {field=field, value=value})
+ local deps
+ if type(field) == "string" then
+ deps = {}
+ deps[field] = value
+ else
+ deps = field
+ end
+
+ table.insert(self.deps, {deps=deps, add=""})
end
-- Generates the unique CBID
@@ -897,10 +905,14 @@ function ListValue.__init__(self, ...)
self.widget = "select"
end
-function ListValue.value(self, key, val)
+function ListValue.value(self, key, val, ...)
val = val or key
table.insert(self.keylist, tostring(key))
table.insert(self.vallist, tostring(val))
+
+ for i, deps in ipairs({...}) do
+ table.insert(self.deps, {add = "-"..key, deps=deps})
+ end
end
function ListValue.validate(self, val)
diff --git a/libs/cbi/luasrc/view/cbi/cell_valuefooter.htm b/libs/cbi/luasrc/view/cbi/cell_valuefooter.htm
index 941214246..7d1ac4ee6 100644
--- a/libs/cbi/luasrc/view/cbi/cell_valuefooter.htm
+++ b/libs/cbi/luasrc/view/cbi/cell_valuefooter.htm
@@ -25,7 +25,15 @@ $Id$
<% if #self.deps > 0 then -%>
<script type="text/javascript">
<% for j, d in ipairs(self.deps) do -%>
- cbi_d_add("cbi-<%=self.config.."-"..section.."-"..self.option%>", "cbid.<%=self.config.."."..section.."."..d.field%>", "<%=d.value%>");
+ cbi_d_add("cbi-<%=self.config.."-"..section.."-"..self.option..d.add%>", {
+ <%-
+ for k,v in pairs(d.deps) do
+ -%>
+ <%-=string.format('"cbid.%s.%s.%s"', self.config, section, k) .. ":" .. string.format("%q", v)-%>,
+ <%-
+ end
+ -%>
+ });
<%- end %>
</script>
<%- end %>
diff --git a/libs/cbi/luasrc/view/cbi/footer.htm b/libs/cbi/luasrc/view/cbi/footer.htm
index b71905820..a688fcddd 100644
--- a/libs/cbi/luasrc/view/cbi/footer.htm
+++ b/libs/cbi/luasrc/view/cbi/footer.htm
@@ -17,7 +17,7 @@ $Id$
<input class="cbi-button cbi-button-apply" type="submit" name="cbi.apply" value="<%:saveapply%>" />
<input class="cbi-button cbi-button-save" type="submit" value="<%:save%>" />
<input class="cbi-button cbi-button-reset" type="reset" value="<%:reset%>" />
- <script type="text/javascript">cbi_d_init();</script>
+ <script type="text/javascript">cbi_d_update();</script>
</div>
</form>
<%+footer%>
diff --git a/libs/cbi/luasrc/view/cbi/full_valuefooter.htm b/libs/cbi/luasrc/view/cbi/full_valuefooter.htm
index 5a52898d1..8084cfda9 100644
--- a/libs/cbi/luasrc/view/cbi/full_valuefooter.htm
+++ b/libs/cbi/luasrc/view/cbi/full_valuefooter.htm
@@ -34,7 +34,15 @@ $Id$
<% if #self.deps > 0 then -%>
<script type="text/javascript">
<% for j, d in ipairs(self.deps) do -%>
- cbi_d_add("cbi-<%=self.config.."-"..section.."-"..self.option%>", "cbid.<%=self.config.."."..section.."."..d.field%>", "<%=d.value%>");
+ cbi_d_add("cbi-<%=self.config.."-"..section.."-"..self.option..d.add%>", {
+ <%-
+ for k,v in pairs(d.deps) do
+ -%>
+ <%-=string.format('"cbid.%s.%s.%s"', self.config, section, k) .. ":" .. string.format("%q", v)-%>,
+ <%-
+ end
+ -%>
+ });
<%- end %>
</script>
<%- end %>
diff --git a/libs/cbi/luasrc/view/cbi/lvalue.htm b/libs/cbi/luasrc/view/cbi/lvalue.htm
index 5108e85c4..60dd68280 100644
--- a/libs/cbi/luasrc/view/cbi/lvalue.htm
+++ b/libs/cbi/luasrc/view/cbi/lvalue.htm
@@ -16,7 +16,7 @@ $Id$
<% if self.widget == "select" then %>
<select onchange="cbi_d_update(this.id)"<%= attr("id", cbid) .. attr("name", cbid) .. ifattr(self.size, "size") %>>
<% for i, key in pairs(self.keylist) do -%>
- <option<%= attr("value", key) .. ifattr(self:cfgvalue(section) == key, "selected", "selected") %>><%=luci.util.pcdata(self.vallist[i])%></option>
+ <option id="cbi-<%=self.config.."-"..section.."-"..self.option.."-"..key%>"<%= attr("value", key) .. ifattr(self:cfgvalue(section) == key, "selected", "selected") %>><%=luci.util.pcdata(self.vallist[i])%></option>
<%- end %>
</select>
<% elseif self.widget == "radio" then
diff --git a/libs/cbi/luasrc/view/cbi/ucisection.htm b/libs/cbi/luasrc/view/cbi/ucisection.htm
index 2ae856003..f8cf3d1bc 100644
--- a/libs/cbi/luasrc/view/cbi/ucisection.htm
+++ b/libs/cbi/luasrc/view/cbi/ucisection.htm
@@ -27,8 +27,17 @@ $Id$
<%- end %>
</select>
<script type="text/javascript"><% for key, val in pairs(self.optionals[section]) do %>
- <% if #val.deps > 0 then %><% for j, d in ipairs(val.deps) do %>cbi_d_add("cbi-<%=self.config.."-"..section.."-"..val.option%>", "cbid.<%=self.config.."."..section.."."..d.field%>", "<%=d.value%>");
- <% end %><% end %>
+ <% if #val.deps > 0 then %><% for j, d in ipairs(val.deps) do -%>
+ cbi_d_add("cbi-<%=self.config.."-"..section.."-"..val.option..d.add%>", {
+ <%-
+ for k,v in pairs(d.deps) do
+ -%>
+ <%-=string.format('"cbid.%s.%s.%s"', self.config, section, k) .. ":" .. string.format("%q", v)-%>,
+ <%-
+ end
+ -%>
+ });
+ <%- end %><% end %>
<% end %></script>
<% end %>
<input type="submit" class="cbi-button cbi-button-fieldadd" value="<%:add%>" />