self.apply_on_parse = nil
self.readinput = true
self.proceed = false
+ self.flow = {}
self.uci = uci.cursor()
self.save = true
if type(node) == "table" and getmetatable(node) == nil then
node = Compound(unpack(node))
end
- assert(instanceof(node, Compound), "Invalid node")
+ assert(type(node) == "function" or instanceof(node, Compound), "Invalid")
assert(not self.nodes[name], "Duplicate entry")
self.nodes[name] = node
table.insert(self.chain, n, name)
end
+function Delegator.set_route(self, ...)
+ local n, chain, route = 0, self.chain, {...}
+ for i = 1, #chain do
+ if chain[i] == self.current then
+ n = i
+ break
+ end
+ end
+ for i = 1, #route do
+ n = n + 1
+ chain[n] = route[i]
+ end
+ for i = n + 1, #chain do
+ chain[i] = nil
+ end
+end
+
function Delegator.get(self, name)
return self.nodes[name]
end
function Delegator.parse(self, ...)
local newcurrent
- self.chain = self:get_chain()
- self.current = self:get_active()
- self.active = self:get(self.current)
+ self.chain = self.chain or self:get_chain()
+ self.current = self.current or self:get_active()
+ self.active = self.active or self:get(self.current)
assert(self.active, "Invalid state")
- self.active:populate_delegator(self)
- if self.active:parse() > FORM_PROCEED then
+ local stat = FORM_DONE
+ if type(self.active) ~= "function" then
+ self.active:populate_delegator(self)
+ stat = self.active:parse()
+ else
+ self:active()
+ end
+
+ if stat > FORM_PROCEED then
if Map.formvalue(self, "cbi.delg.back") then
newcurrent = self:get_prev(self.current)
else
else
self.current = newcurrent
self.active = self:get(self.current)
- self.active:parse(false)
- return FROM_PROCEED
+ if type(self.active) ~= "function" then
+ self.active:parse(false)
+ return FROM_PROCEED
+ else
+ return self:parse(...)
+ end
end
end
if v.optional and not v:cfgvalue(section) then
if field == v.option then
field = nil
- else
self.map.proceed = true
+ else
table.insert(self.optionals[section], v)
end
end