libs/web: add list(...) datatype for space separated lists of arbritary datatypes
authorJo-Philipp Wich <jow@openwrt.org>
Fri, 16 Dec 2011 05:52:24 +0000 (05:52 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Fri, 16 Dec 2011 05:52:24 +0000 (05:52 +0000)
libs/web/htdocs/luci-static/resources/cbi.js
libs/web/luasrc/cbi/datatypes.lua

index d1e34d1786035b24489d96a0c3f12e1408bc923b..8d32b669d18fc2ae36272737e80e96b2715f93e7 100644 (file)
@@ -233,6 +233,24 @@ var cbi_validators = {
                if (args[0] && typeof cbi_validators[args[0]] == "function")
                        return cbi_validators[args[0]](v.replace(/^\s*!\s*/, ''));
 
+               return false;
+       },
+
+       'list': function(v, args)
+       {
+               var cb = cbi_validators[args[0] || 'string'];
+               if (typeof cb == "function")
+               {
+                       var cbargs = args.slice(1);
+                       var values = v.match(/[^\s]+/g);
+
+                       for (var i = 0; i < values.length; i++)
+                               if (!cb(values[i], cbargs))
+                                       return false;
+
+                       return true;
+               }
+
                return false;
        }
 };
index 93b29cba81d2c54afaae2479417f74551a2a8704..9a3b735008a289de333a35a0d88898f76c657eaa 100644 (file)
@@ -282,3 +282,17 @@ function neg(val, what)
 
        return false
 end
+
+function list(val, what, ...)
+       if type(val) == "string" and what and type(_M[what]) == "function" then
+               for val in val:gmatch("%S+") do
+                       if not _M[what](val, ...) then
+                               return false
+                       end
+               end
+
+               return true
+       end
+
+       return false
+end