luci-base: emit a warning if cbi() delegates a SimpleForm instance
[project/luci.git] / modules / luci-base / luasrc / dispatcher.lua
index 2468136..4866727 100644 (file)
@@ -658,6 +658,23 @@ function node(...)
        return c
 end
 
+function lookup(...)
+       local i, path = nil, {}
+       for i = 1, select('#', ...) do
+               local name, arg = nil, tostring(select(i, ...))
+               for name in arg:gmatch("[^/]+") do
+                       path[#path+1] = name
+               end
+       end
+
+       for i = #path, 1, -1 do
+               local node = context.treecache[table.concat(path, ".", 1, i)]
+               if node and (i == #path or node.leaf) then
+                       return node, build_url(unpack(path))
+               end
+       end
+end
+
 function _create_node(path)
        if #path == 0 then
                return context.tree
@@ -799,7 +816,16 @@ local function _cbi(self, ...)
 
        local state = nil
 
+       local i, res
        for i, res in ipairs(maps) do
+               if util.instanceof(res, cbi.SimpleForm) then
+                       io.stderr:write("Model %s returns SimpleForm but is dispatched via cbi(),\n"
+                               % self.model)
+
+                       io.stderr:write("please change %s to use the form() action instead.\n"
+                               % table.concat(context.request, "/"))
+               end
+
                res.flow = config
                local cstate = res:parse()
                if cstate and (not state or cstate < state) then
@@ -892,7 +918,7 @@ end
 function cbi(model, config)
        return {
                type = "cbi",
-               post = { ["cbi.submit"] = "1" },
+               post = { ["cbi.submit"] = true },
                config = config,
                model = model,
                target = _cbi
@@ -920,6 +946,7 @@ local function _form(self, ...)
        local maps = luci.cbi.load(self.model, ...)
        local state = nil
 
+       local i, res
        for i, res in ipairs(maps) do
                local cstate = res:parse()
                if cstate and (not state or cstate < state) then
@@ -938,7 +965,7 @@ end
 function form(model)
        return {
                type = "cbi",
-               post = { ["cbi.submit"] = "1" },
+               post = { ["cbi.submit"] = true },
                model = model,
                target = _form
        }