diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/controllerfunctions.lua | 15 | ||||
-rw-r--r-- | lib/viewfunctions.lua | 35 |
2 files changed, 38 insertions, 12 deletions
diff --git a/lib/controllerfunctions.lua b/lib/controllerfunctions.lua index 5c3e559..90d31a4 100644 --- a/lib/controllerfunctions.lua +++ b/lib/controllerfunctions.lua @@ -43,7 +43,7 @@ function handle_clientdata(form, clientdata) end end -function handle_form(self, getFunction, setFunction, clientdata, option, label, descr, redirectOnSuccess) +function handle_form(self, getFunction, setFunction, clientdata, option, label, descr) local form = getFunction() if clientdata[option] then @@ -53,11 +53,20 @@ function handle_form(self, getFunction, setFunction, clientdata, option, label, if not form.errtxt and descr then form.descr = descr end + + if clientdata.redir then + form.value.redir = cfe({ type="hidden", value=clientdata.redir, label="" }) + end form = self:redirect_to_referrer(form) - if redirectOnSuccess and not form.errtxt then - self:redirect(redirectOnSuccess) + if clientdata.redir and not form.errtxt then + form.value = form.descr -- make it a command result + form.descr = nil + self:redirect(clientdata.redir, form) end else + if clientdata.redir then + form.value.redir = cfe({ type="hidden", value=clientdata.redir, label="" }) + end form = self:redirect_to_referrer() or form end diff --git a/lib/viewfunctions.lua b/lib/viewfunctions.lua index 19911a0..c3e4b6a 100644 --- a/lib/viewfunctions.lua +++ b/lib/viewfunctions.lua @@ -102,13 +102,15 @@ end function displayformitem(myitem, name, viewtype) if not myitem then return end if name then myitem.name = name end - io.write("<DT") - if myitem.errtxt then - myitem.class = "error" - io.write(' class="error"') + if myitem.type ~= "hidden" then + io.write("<DT") + if myitem.errtxt then + myitem.class = "error" + io.write(' class="error"') + end + io.write(">" .. myitem.label .. "</DT>\n") + io.write("<DD></DD>\n") end - io.write(">" .. myitem.label .. "</DT>\n") - io.write("<DD>") if (viewtype == "viewonly") then myitem.disabled = "true" end @@ -163,13 +165,21 @@ function displayformitem(myitem, name, viewtype) io.write("</DD>\n") end -function displayform(myform, order, finishingorder) +function displayformstart(myform) if not myform then return end if myform.descr then io.write('<P CLASS="descr">' .. string.gsub(myform.descr, "\n", "<BR>") .. "</P>\n") end if myform.errtxt then io.write('<P CLASS="error">' .. string.gsub(myform.errtxt, "\n", "<BR>") .. "</P>\n") end io.write('<form action="' .. (myform.action or "") .. '" method="POST">\n') + if myform.value.redir then + displayformitem(myform.value.redir, "redir") + end +end + +function displayform(myform, order, finishingorder) + if not myform then return end + displayformstart(myform) io.write('<DL>\n') - local reverseorder= {} + local reverseorder= {["redir"]=0} if order then for x,name in ipairs(order) do reverseorder[name] = x @@ -199,6 +209,13 @@ function displayform(myform, order, finishingorder) end end end + io.write('</DL>\n') + displayformend(myform) +end + +function displayformend(myform) + if not myform then return end + io.write('<DL>\n') io.write('<DT></DT><DD><input class="submit" type="submit" name="' .. myform.option .. '" value="' .. (myform.submit or myform.option) .. '"></DD>\n') io.write('</DL>\n') io.write('</FORM>') @@ -215,7 +232,7 @@ function displaycommandresults(commands, session) if #cmdresult > 0 then io.write("<H1>Command Result</H1>\n<DL>\n") for i,result in ipairs(cmdresult) do - if result.value ~= "" then io.write(result.value:gsub("\n", "<BR>") .. "\n") end + if type(result.value) == "string" and result.value ~= "" then io.write(result.value:gsub("\n", "<BR>") .. "\n") end if result.descr then io.write('<P CLASS="descr">' .. string.gsub(result.descr, "\n", "<BR>") .. "</P>\n") end if result.errtxt then io.write('<P CLASS="error">' .. string.gsub(result.errtxt, "\n", "<BR>") .. "</P>\n") end end |