X-Git-Url: http://git.archive.openwrt.org/?a=blobdiff_plain;f=modules%2Fluci-base%2Fhtdocs%2Fluci-static%2Fresources%2Fcbi.js;h=81cc65778464b6d9956eb711adc31b11a61d9c92;hb=b50471787feb9c04b365ff239aee8f39eadc236b;hp=4b7227f1a4e959c225dfa0fecac9e78a64d58c19;hpb=6318f67fd46450b501879d9cf36c023fab7824d3;p=project%2Fluci.git diff --git a/modules/luci-base/htdocs/luci-static/resources/cbi.js b/modules/luci-base/htdocs/luci-static/resources/cbi.js index 4b7227f1a..81cc65778 100644 --- a/modules/luci-base/htdocs/luci-static/resources/cbi.js +++ b/modules/luci-base/htdocs/luci-static/resources/cbi.js @@ -13,7 +13,6 @@ var cbi_d = []; var cbi_t = []; -var cbi_c = []; var cbi_validators = { @@ -139,10 +138,11 @@ var cbi_validators = { return (this.match(/^([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}$/) != null); }, - 'host': function() + 'host': function(ipv4only) { return cbi_validators.hostname.apply(this) || - cbi_validators.ipaddr.apply(this); + ((ipv4only != 1) && cbi_validators.ipaddr.apply(this)) || + ((ipv4only == 1) && cb_validators.ip4addr.apply(this)); }, 'hostname': function() @@ -161,28 +161,49 @@ var cbi_validators = { cbi_validators.host.apply(this); }, - 'hostport': function() + 'hostport': function(ipv4only) { var hp = this.split(/:/); if (hp.length == 2) - return (cbi_validators.host.apply(hp[0]) && + return (cbi_validators.host.apply(hp[0], ipv4only) && cbi_validators.port.apply(hp[1])); return false; }, - 'ipaddrport': function() + 'ip4addrport': function() { var hp = this.split(/:/); if (hp.length == 2) return (cbi_validators.ipaddr.apply(hp[0]) && cbi_validators.port.apply(hp[1])); - return false; }, + 'ipaddrport': function(bracket) + { + if (this.match(/^([^\[\]:]+):([^:]+)$/)) { + var addr = RegExp.$1 + var port = RegExp.$2 + return (cbi_validators.ip4addr.apply(addr) && + cbi_validators.port.apply(port)); + } else if ((bracket == 1) && (this.match(/^\[(.+)\]:([^:]+)$/))) { + var addr = RegExp.$1 + var port = RegExp.$2 + return (cbi_validators.ip6addr.apply(addr) && + cbi_validators.port.apply(port)); + } else if ((bracket != 1) && (this.match(/^([^\[\]]+):([^:]+)$/))) { + var addr = RegExp.$1 + var port = RegExp.$2 + return (cbi_validators.ip6addr.apply(addr) && + cbi_validators.port.apply(port)); + } else { + return false; + } + }, + 'wpakey': function() { var v = this; @@ -323,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); }, @@ -367,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 entry.index) { + break; + } + } + if (!next) { parent.appendChild(entry.node); } else { - next.parentNode.insertBefore(entry.node, next); + parent.insertBefore(entry.node, next); } + state = true; - if( entry.parent ) - cbi_c[entry.parent]++; } } @@ -477,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, @@ -854,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 0 ) + if (hl_tabs.length > 0) window.setTimeout(function() { for( var i = 0; i < hl_tabs.length; i++ ) hl_tabs[i].className = hl_tabs[i].className.replace(/ cbi-tab-highlighted/g, '');