+ if config.state_handler then
+ if not config.state_handler(state, maps) then
+ return
+ end
+ end
+
+ local pageaction = true
+ http.header("X-CBI-State", state or 0)
+ luci.template.render("cbi/header", {state = state})
+ for i, res in ipairs(maps) do
+ res:render()
+ if res.pageaction == false then
+ pageaction = false
+ end
+ end
+ luci.template.render("cbi/footer", {pageaction=pageaction, state = state, autoapply = config.autoapply})
+ end
+end
+
+--- Create a CBI form model dispatching target.
+-- @param model CBI form model tpo be rendered
+function form(model)
+ return function(...)
+ require("luci.cbi")
+ require("luci.template")
+ local http = require "luci.http"
+
+ maps = luci.cbi.load(model, ...)
+
+ local state = nil
+
+ for i, res in ipairs(maps) do
+ local cstate = res:parse()
+ if not state or cstate < state then
+ state = cstate
+ end
+ end
+
+ http.header("X-CBI-State", state or 0)
+ luci.template.render("header")
+ for i, res in ipairs(maps) do
+ res:render()
+ end
+ luci.template.render("footer")