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 1cd49bc..1e751d4 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 6640db6..fc3048e 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