summaryrefslogtreecommitdiffhomepage
path: root/modules/luci-base/htdocs/luci-static
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2016-01-18 17:05:36 +0100
committerJo-Philipp Wich <jow@openwrt.org>2016-01-18 17:05:36 +0100
commitb50471787feb9c04b365ff239aee8f39eadc236b (patch)
treecef8b5577dd9365c2d2de3106772c3f7dd705e93 /modules/luci-base/htdocs/luci-static
parentbe8dba57a9824179a6b942e27e7203d0ba921129 (diff)
luci-base: refactor cbi dependency handling code
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
Diffstat (limited to 'modules/luci-base/htdocs/luci-static')
-rw-r--r--modules/luci-base/htdocs/luci-static/resources/cbi.js66
1 files changed, 34 insertions, 32 deletions
diff --git a/modules/luci-base/htdocs/luci-static/resources/cbi.js b/modules/luci-base/htdocs/luci-static/resources/cbi.js
index dd8d7b8eea..81cc657784 100644
--- a/modules/luci-base/htdocs/luci-static/resources/cbi.js
+++ b/modules/luci-base/htdocs/luci-static/resources/cbi.js
@@ -344,7 +344,7 @@ var cbi_validators = {
{
return (this.match(/^[0-9\*#!\.]+$/) != null);
},
- 'timehhmmss': function()
+ 'timehhmmss': function()
{
return (this.match(/^[0-6][0-9]:[0-6][0-9]:[0-6][0-9]$/) != null);
},
@@ -388,12 +388,12 @@ var cbi_validators = {
};
-function cbi_d_add(field, dep, next) {
- var obj = document.getElementById(field);
+function cbi_d_add(field, dep, index) {
+ var obj = (typeof(field) === 'string') ? document.getElementById(field) : field;
if (obj) {
var entry
for (var i=0; i<cbi_d.length; i++) {
- if (cbi_d[i].id == field) {
+ if (cbi_d[i].id == obj.id) {
entry = cbi_d[i];
break;
}
@@ -401,10 +401,10 @@ function cbi_d_add(field, dep, next) {
if (!entry) {
entry = {
"node": obj,
- "id": field,
+ "id": obj.id,
"parent": obj.parentNode.id,
- "next": next,
- "deps": []
+ "deps": [],
+ "index": index
};
cbi_d.unshift(entry);
}
@@ -467,19 +467,27 @@ function cbi_d_update() {
var state = false;
for (var i=0; i<cbi_d.length; i++) {
var entry = cbi_d[i];
- var next = document.getElementById(entry.next)
- var node = document.getElementById(entry.id)
- var parent = document.getElementById(entry.parent)
+ var node = document.getElementById(entry.id);
+ var parent = document.getElementById(entry.parent);
if (node && node.parentNode && !cbi_d_check(entry.deps)) {
node.parentNode.removeChild(node);
state = true;
} else if ((!node || !node.parentNode) && cbi_d_check(entry.deps)) {
+ var next = undefined;
+
+ for (next = parent.firstChild; next; next = next.nextSibling) {
+ if (next.getAttribute && parseInt(next.getAttribute('data-index'), 10) > entry.index) {
+ break;
+ }
+ }
+
if (!next) {
parent.appendChild(entry.node);
} else {
- next.parentNode.insertBefore(entry.node, next);
+ parent.insertBefore(entry.node, next);
}
+
state = true;
}
}
@@ -494,6 +502,21 @@ function cbi_d_update() {
}
}
+function cbi_init() {
+ var nodes = document.querySelectorAll('[data-depends]');
+
+ for (var i = 0, node; (node = nodes[i]) !== undefined; i++) {
+ var deps = JSON.parse(node.getAttribute('data-depends'));
+ if (deps.length > 0) {
+ for (var alt = 0; alt < deps.length; alt++) {
+ cbi_d_add(node, deps[alt], i);
+ }
+ }
+ }
+
+ cbi_d_update();
+}
+
function cbi_bind(obj, type, callback, mode) {
if (!obj.addEventListener) {
obj.attachEvent('on' + type,
@@ -871,27 +894,6 @@ function cbi_dynlist_init(name, respath, datatype, optional, url, defpath, choic
cbi_dynlist_redraw(NaN, -1, -1);
}
-//Hijacks the CBI form to send via XHR (requires Prototype)
-function cbi_hijack_forms(layer, win, fail, load) {
- var forms = layer.getElementsByTagName('form');
- for (var i=0; i<forms.length; i++) {
- $(forms[i]).observe('submit', function(event) {
- // Prevent the form from also submitting the regular way
- event.stop();
-
- // Submit via XHR
- event.element().request({
- onSuccess: win,
- onFailure: fail
- });
-
- if (load) {
- load();
- }
- });
- }
-}
-
function cbi_t_add(section, tab) {
var t = document.getElementById('tab.' + section + '.' + tab);