From 8997f1f6dc27262042a30c35266a95672e4406d4 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Wed, 22 Oct 2008 18:50:22 +0000 Subject: Modified viewfunctions to split displayform, creating displayformstart and displayformend, to provide flexibility while still using the library. Also added support for hidden fields - including a common redir field. Removed redirectOnSuccess from controllerfunctions handle_form, and replaced it with the redir field. Removed redirectOnSuccess from controllers that used it and added handlecommandresults and redir entries to links and forms throughout many views. This will cause a redirect to the originating view when a form is successfully completed. acf_www-controller now includes orig_action in page_info to report the original action launched by the user. git-svn-id: svn://svn.alpinelinux.org/acf/core/trunk@1560 ab2d0c66-481e-0410-8bed-d214d4d58bed --- app/acf-util/password-controller.lua | 2 +- app/acf-util/password-status-html.lsp | 11 ++++++----- app/acf-util/roles-controller.lua | 4 ++-- app/acf-util/roles-viewroles-html.lsp | 5 +++-- app/acf_www-controller.lua | 9 +++++++-- app/filedetails-html.lsp | 9 +++++---- app/status-html.lsp | 4 ++-- lib/controllerfunctions.lua | 15 ++++++++++++--- lib/viewfunctions.lua | 35 ++++++++++++++++++++++++++--------- 9 files changed, 64 insertions(+), 30 deletions(-) diff --git a/app/acf-util/password-controller.lua b/app/acf-util/password-controller.lua index bea4480..b2fab85 100755 --- a/app/acf-util/password-controller.lua +++ b/app/acf-util/password-controller.lua @@ -60,7 +60,7 @@ function newuser(self) return self.model.read_user(self) end, function(value) return self.model.create_user(self, value) - end, self.clientdata, "Save", "New User Settings", "Saved user", "status") + end, self.clientdata, "Save", "New User Settings", "Saved user") end function deleteuser(self) diff --git a/app/acf-util/password-status-html.lsp b/app/acf-util/password-status-html.lsp index 26416ce..d7db4e9 100755 --- a/app/acf-util/password-status-html.lsp +++ b/app/acf-util/password-status-html.lsp @@ -1,4 +1,4 @@ -<% local form, viewlibrary, pageinfo, session = ... %> +<% local form, viewlibrary, page_info, session = ... %> <% require("viewfunctions") %> <% --[[ DEBUG INFORMATION @@ -8,11 +8,12 @@ io.write("") --]] %> -<% displaycommandresults({"deleteuser"}, session) %> +<% displaycommandresults({"newuser", "edituser", "deleteuser"}, session) %>

User Accounts

Create new account

-
+ +

Existing account

@@ -32,9 +33,9 @@ io.write("") Option - [Edit this account] + [Edit this account] [Delete this account] - [View roles for this account] + [View roles for this account] diff --git a/app/acf-util/roles-controller.lua b/app/acf-util/roles-controller.lua index 91d4d9c..738f54f 100644 --- a/app/acf-util/roles-controller.lua +++ b/app/acf-util/roles-controller.lua @@ -47,14 +47,14 @@ newrole = function(self) return controllerfunctions.handle_form(self, function() return self.model.getpermissions(self) end, function(value) return self.model.setpermissions(self, value, true) end, - self.clientdata, "Save", "Create New Role", "New Role Created", "viewroles") + self.clientdata, "Save", "Create New Role", "New Role Created") end editrole = function(self) return controllerfunctions.handle_form(self, function() return self.model.getpermissions(self, self.clientdata.role) end, function(value) return self.model.setpermissions(self, value, false) end, - self.clientdata, "Save", "Edit Role", "Role Saved", "viewroles") + self.clientdata, "Save", "Edit Role", "Role Saved") end deleterole = function(self) diff --git a/app/acf-util/roles-viewroles-html.lsp b/app/acf-util/roles-viewroles-html.lsp index f5ca4d5..8b9a10f 100644 --- a/app/acf-util/roles-viewroles-html.lsp +++ b/app/acf-util/roles-viewroles-html.lsp @@ -5,11 +5,12 @@ io.write(html.cfe_unpack(view)) --]] %> -<% displaycommandresults({"deleterole"}, session) %> +<% displaycommandresults({"newrole", "editrole", "deleterole"}, session) %>

Roles

Create new role

+
@@ -31,7 +32,7 @@
<%= role %>
[View this role] - [Edit this role] + [Edit this role] [Delete this role]
<% end %> diff --git a/app/acf_www-controller.lua b/app/acf_www-controller.lua index 5f5abcd..3587578 100644 --- a/app/acf_www-controller.lua +++ b/app/acf_www-controller.lua @@ -134,6 +134,7 @@ local dispatch_component = function(str, clientdata, suppress_view) end self.conf.component = true self.conf.suppress_view = suppress_view + self.conf.orig_action = self.conf.orig_action or self.conf.prefix .. self.conf.controller .. "/" .. self.conf.action local tempclientdata = self.clientdata self.clientdata = clientdata or {} self.clientdata.sessionid = tempclientdata.sessionid @@ -200,7 +201,8 @@ local view_resolver = function(self) script = self.conf.script, appname = self.conf.appname, skindir = self.conf.skindir or "", - skin = self.conf.skin or "" + skin = self.conf.skin or "", + orig_action = self.conf.orig_action or self.conf.prefix .. self.conf.controller .. "/" .. self.conf.action } return func, viewlibrary, pageinfo, self.sessiondata @@ -453,7 +455,10 @@ end -- Cause a redirect to specified (or default) action -- We use the self.conf table because it already has prefix,controller,etc -- The actual redirection is defined in exception_handler above -redirect = function (self, str) +redirect = function (self, str, result) + if result then + self.sessiondata[self.conf.action.."result"] = result + end local prefix, controller, action = self.parse_path_info("/" .. (str or "")) if prefix ~= "/" then self.conf.prefix = prefix end if controller ~= "" then self.conf.controller = controller end diff --git a/app/filedetails-html.lsp b/app/filedetails-html.lsp index 4c1f116..ccf7a0c 100644 --- a/app/filedetails-html.lsp +++ b/app/filedetails-html.lsp @@ -17,10 +17,11 @@ displayitem(form.value.mtime)

File Content

-<% if form.descr then %>

<%= string.gsub(form.descr, "\n", "
") %>

<% end %> -<% if form.errtxt then %>

<%= string.gsub(form.errtxt, "\n", "
") %>

<% end %> -
" method="POST"> +<% if form.type == "form" then %> +<% form.action = page_info.script .. page_info.prefix .. page_info.controller .. "/" .. page_info.action %> +<% displayformstart(form) %> +<% end %> @@ -29,6 +30,6 @@ displayitem(form.value.mtime) <% if form.type == "form" then %>

Save

-
Submit and save above changes
+<% displayformend(form) %> <% end %>
diff --git a/app/status-html.lsp b/app/status-html.lsp index d5bdad0..f1e4c5c 100644 --- a/app/status-html.lsp +++ b/app/status-html.lsp @@ -2,7 +2,7 @@ require("viewfunctions") %> -<% displaycommandresults({"install"}, session) %> +<% displaycommandresults({"install","edit"}, session) %>

System Info

@@ -19,6 +19,6 @@ end displayitem(data.value.autostart) if not (data.value.version and data.value.version.errtxt) and data.value.autostart and data.value.autostart.errtxt and session.permissions.rc and session.permissions.rc.edit then %> - Schedule autostart + Schedule autostart <% end %>
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("" .. myitem.label .. "\n") + io.write("
\n") end - io.write(">" .. myitem.label .. "\n") - io.write("
") if (viewtype == "viewonly") then myitem.disabled = "true" end @@ -163,13 +165,21 @@ function displayformitem(myitem, name, viewtype) io.write("
\n") end -function displayform(myform, order, finishingorder) +function displayformstart(myform) if not myform then return end if myform.descr then io.write('

' .. string.gsub(myform.descr, "\n", "
") .. "

\n") end if myform.errtxt then io.write('

' .. string.gsub(myform.errtxt, "\n", "
") .. "

\n") end io.write('
\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('
\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('
\n') + displayformend(myform) +end + +function displayformend(myform) + if not myform then return end + io.write('
\n') io.write('
\n') io.write('
\n') io.write('
') @@ -215,7 +232,7 @@ function displaycommandresults(commands, session) if #cmdresult > 0 then io.write("

Command Result

\n
\n") for i,result in ipairs(cmdresult) do - if result.value ~= "" then io.write(result.value:gsub("\n", "
") .. "\n") end + if type(result.value) == "string" and result.value ~= "" then io.write(result.value:gsub("\n", "
") .. "\n") end if result.descr then io.write('

' .. string.gsub(result.descr, "\n", "
") .. "

\n") end if result.errtxt then io.write('

' .. string.gsub(result.errtxt, "\n", "
") .. "

\n") end end -- cgit v1.2.3