libs/web: add "neg()" cbi datatype to negate arbritary types, e.g. "neg(hostname...
authorJo-Philipp Wich <jow@openwrt.org>
Sun, 4 Sep 2011 12:07:43 +0000 (12:07 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Sun, 4 Sep 2011 12:07:43 +0000 (12:07 +0000)
libs/web/htdocs/luci-static/resources/cbi.js
libs/web/luasrc/cbi/datatypes.lua

index 1cd49bc65d8b23776745d08f95473af3dd7cd3ca..1e751d47e64c0d140b26444928c0fef160af2423 100644 (file)
@@ -218,6 +218,14 @@ var cbi_validators = {
                if (!isNaN(max) && !isNaN(val))
                        return (val <= max);
 
+               return false;
+       },
+
+       'neg': function(v, args)
+       {
+               if (args[0] && typeof cbi_validators[args[0]] == "function")
+                       return cbi_validators[args[0]](v.replace(/^\s*!\s*/, ''));
+
                return false;
        }
 };
index 6640db639251769de94b9214ed0b17f3b1ea3afc..fc3048e37e40524d4c292411824e99479d219b7d 100644 (file)
@@ -267,3 +267,11 @@ function max(val, max)
 
        return false
 end
+
+function neg(val, what)
+       if what and type(_M[what]) == "function" then
+               return _M[what](val:gsub("^%s*!%s*", ""))
+       end
+
+       return false
+end