+ if not config.nofooter then
+ tpl.render("cbi/footer", {flow = config, pageaction=pageaction, state = state, autoapply = config.autoapply})
+ end
+end
+
+--- Create a CBI model dispatching target.
+-- @param model CBI model to be rendered
+function cbi(model, config)
+ return {type = "cbi", config = config, model = model, target = _cbi}
+end
+
+
+local function _arcombine(self, ...)
+ local argv = {...}
+ local target = #argv > 0 and self.targets[2] or self.targets[1]
+ setfenv(target.target, self.env)
+ target:target(unpack(argv))
+end
+
+--- Create a combined dispatching target for non argv and argv requests.
+-- @param trg1 Overview Target
+-- @param trg2 Detail Target
+function arcombine(trg1, trg2)
+ return {type = "arcombine", env = getfenv(), target = _arcombine, targets = {trg1, trg2}}
+end
+
+
+local function _form(self, ...)
+ local cbi = require "luci.cbi"
+ local tpl = require "luci.template"
+ local http = require "luci.http"
+
+ local maps = luci.cbi.load(self.model, ...)
+ local state = nil
+
+ for i, res in ipairs(maps) do
+ local cstate = res:parse()
+ if cstate and (not state or cstate < state) then
+ state = cstate
+ end
+ end
+
+ http.header("X-CBI-State", state or 0)
+ tpl.render("header")
+ for i, res in ipairs(maps) do
+ res:render()
+ end
+ tpl.render("footer")
+end
+
+--- Create a CBI form model dispatching target.
+-- @param model CBI form model tpo be rendered
+function form(model)
+ return {type = "cbi", model = model, target = _form}