From fbaabd7d93e72506756e18988f98fca139e202e6 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Thu, 14 Oct 2010 23:21:25 +0000 Subject: libs/web: cbi: add new on_before_save and on_after_save hook, implement :reset_values() for options supporting :value() --- libs/web/luasrc/cbi.lua | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/libs/web/luasrc/cbi.lua b/libs/web/luasrc/cbi.lua index 0a63d6090a..5fa992dee8 100644 --- a/libs/web/luasrc/cbi.lua +++ b/libs/web/luasrc/cbi.lua @@ -304,9 +304,11 @@ function Map.parse(self, readinput, ...) Node.parse(self, ...) if self.save then + self:_run_hooks("on_save", "on_before_save") for i, config in ipairs(self.parsechain) do self.uci:save(config) end + self:_run_hooks("on_after_save") if self:submitstate() and ((not self.proceed and self.flow.autoapply) or luci.http.formvalue("cbi.apply")) then self:_run_hooks("on_before_commit") for i, config in ipairs(self.parsechain) do @@ -1402,6 +1404,11 @@ function Value.__init__(self, ...) self.vallist = {} end +function Value.reset_values(self) + self.keylist = {} + self.vallist = {} +end + function Value.value(self, key, val) val = val or key table.insert(self.keylist, tostring(key)) @@ -1487,6 +1494,11 @@ function ListValue.__init__(self, ...) self.widget = "select" end +function ListValue.reset_values(self) + self.keylist = {} + self.vallist = {} +end + function ListValue.value(self, key, val, ...) if luci.util.contains(self.keylist, key) then return @@ -1537,6 +1549,11 @@ function MultiValue.render(self, ...) AbstractValue.render(self, ...) end +function MultiValue.reset_values(self) + self.keylist = {} + self.vallist = {} +end + function MultiValue.value(self, key, val) if luci.util.contains(self.keylist, key) then return @@ -1613,6 +1630,11 @@ function DynamicList.__init__(self, ...) self.vallist = {} end +function DynamicList.reset_values(self) + self.keylist = {} + self.vallist = {} +end + function DynamicList.value(self, key, val) val = val or key table.insert(self.keylist, tostring(key)) -- cgit v1.2.3