From 997b4dcd33463841aa8f1ca6d59dea7bc9d38ae9 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Wed, 2 Jul 2008 15:56:04 +0000 Subject: Modified core to create model and controller function libraries and some common html views. Moved cfe to a library. Modified redirect_to_referrer function - may break some pages. git-svn-id: svn://svn.alpinelinux.org/acf/core/trunk@1267 ab2d0c66-481e-0410-8bed-d214d4d58bed --- lib/controllerfunctions.lua | 51 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 lib/controllerfunctions.lua (limited to 'lib/controllerfunctions.lua') diff --git a/lib/controllerfunctions.lua b/lib/controllerfunctions.lua new file mode 100644 index 0000000..23e57d4 --- /dev/null +++ b/lib/controllerfunctions.lua @@ -0,0 +1,51 @@ +module(..., package.seeall) + +function handle_form(self, getFunction, setFunction, clientdata, option, label, descr) + local form = getFunction() + + if clientdata[option] then + form.errtxt = nil + for name,value in pairs(form.value) do + value.errtxt = nil + if value.type == "boolean" then + value.value = (clientdata[name] ~= nil) + elseif value.type == "list" then + value.value = {} + if clientdata[name] and clientdata[name] ~= "" then + for ip in string.gmatch(clientdata[name].."\n", "%s*(%S[^\n]*%S)%s*\n") do + table.insert(value.value, ip) + end + end + else + value.value = clientdata[name] or value.value + end + end + form = setFunction(form) + if not form.errtxt then + form.descr = descr + end + form = self:redirect_to_referrer(form) + else + form = self:redirect_to_referrer() or form + end + + form.type = "form" + form.option = option + form.label = label + + return form +end + +function handle_startstop(self, startstopfunction, getstatusfunction, clientdata) + local result + if clientdata.action then + result = startstopfunction(clientdata.action) + end + result = self:redirect_to_referrer(result) + + local status = getstatusfunction() + status = status.value.status + + return cfe({ type="group", value={status=status, result=result} }) +end + -- cgit v1.2.3