+local function _cbi(self, ...)
+ local cbi = require "luci.cbi"
+ local tpl = require "luci.template"
+ local http = require "luci.http"
+
+ local config = self.config or {}
+ local maps = cbi.load(self.model, ...)
+
+ local state = nil
+
+ for i, res in ipairs(maps) do
+ res.flow = config
+ local cstate = res:parse()
+ if cstate and (not state or cstate < state) then
+ state = cstate
+ end
+ end
+
+ local function _resolve_path(path)
+ return type(path) == "table" and build_url(unpack(path)) or path
+ end
+
+ if config.on_valid_to and state and state > 0 and state < 2 then
+ http.redirect(_resolve_path(config.on_valid_to))
+ return
+ end
+
+ if config.on_changed_to and state and state > 1 then
+ http.redirect(_resolve_path(config.on_changed_to))
+ return
+ end
+
+ if config.on_success_to and state and state > 0 then
+ http.redirect(_resolve_path(config.on_success_to))
+ return
+ end