From bdb4bbde130ba4cfb86746dde2905fc12b94175f Mon Sep 17 00:00:00 2001 From: Steven Barth Date: Sat, 9 Aug 2008 14:14:04 +0000 Subject: libs/cbi: Major Improvements Added initial support for non-UCI-based forms (luci.cbi.SimpleForm) Minor API improvements Now correctly tagging "empty mandatory field" errors --- libs/web/luasrc/dispatcher.lua | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'libs/web') diff --git a/libs/web/luasrc/dispatcher.lua b/libs/web/luasrc/dispatcher.lua index 9ba74c49c..d9917c2a8 100644 --- a/libs/web/luasrc/dispatcher.lua +++ b/libs/web/luasrc/dispatcher.lua @@ -461,3 +461,32 @@ function cbi(model) luci.template.render("cbi/footer") end end + +--- Create a CBI form model dispatching target. +-- @param model CBI form model tpo be rendered +function form(model) + require("luci.cbi") + require("luci.template") + + return function(...) + local stat, maps = luci.util.copcall(luci.cbi.load, model, ...) + if not stat then + error500(maps) + return true + end + + for i, res in ipairs(maps) do + local stat, err = luci.util.copcall(res.parse, res) + if not stat then + error500(err) + return true + end + end + + luci.template.render("header") + for i, res in ipairs(maps) do + res:render() + end + luci.template.render("footer") + end +end -- cgit v1.2.3