summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2012-02-22 20:45:51 +0000
committerTed Trask <ttrask01@yahoo.com>2012-02-22 20:45:51 +0000
commit7a094cf04dd3fe002bf568e5bdbc29ddd833fb29 (patch)
treeb1d0ef289fc3b6e562356884103b0b0009814dcf
parent5dd6e6c5e5c6f5dc14315bae74e26421f1a9d197 (diff)
downloadacf-core-7a094cf04dd3fe002bf568e5bdbc29ddd833fb29.tar.bz2
acf-core-7a094cf04dd3fe002bf568e5bdbc29ddd833fb29.tar.xz
Changed startstop to be a standard form by creating two model functions and deleting the special controller function
-rw-r--r--app/startstop-html.lsp26
-rw-r--r--lib/controllerfunctions.lua7
-rw-r--r--lib/modelfunctions.lua33
3 files changed, 27 insertions, 39 deletions
diff --git a/app/startstop-html.lsp b/app/startstop-html.lsp
index c98208b..0783483 100644
--- a/app/startstop-html.lsp
+++ b/app/startstop-html.lsp
@@ -1,22 +1,10 @@
<% local data, viewlibrary, page_info = ... %>
+<% require("htmlviewfunctions") %>
<H1>Management</H1>
-
-<% if data.value.result then %>
-<H2>Previous action result</H2>
-<% if data.value.result.value ~= "" then %>
-<P CLASS='descr'><%= string.gsub(html.html_escape(data.value.result.value), "\n", "<BR>") %></P>
-<% end if data.value.result.errtxt then %>
-<P CLASS='error'><%= string.gsub(html.html_escape(data.value.result.errtxt), "\n", "<BR>") %></P>
-<% end end %>
-
-<DL>
-<form action="<%= html.html_escape(page_info.script .. page_info.prefix .. page_info.controller .. "/" .. page_info.action) %>" method="POST">
-<DT>Program control-panel</DT>
-<DD>
-<% for i,act in ipairs(data.value.actions.value) do %>
- <input class="submit" type="submit" name="action" value="<%= act %>">
-<% end %>
-</DD>
-</form>
-</DL>
+<%
+for i,v in ipairs(data.option) do
+ data.option[i] = v:gsub("^%l", string.upper)
+end
+htmlviewfunctions.displayform(data, nil, nil, page_info)
+%>
diff --git a/lib/controllerfunctions.lua b/lib/controllerfunctions.lua
index ee10a14..b0879ae 100644
--- a/lib/controllerfunctions.lua
+++ b/lib/controllerfunctions.lua
@@ -97,10 +97,3 @@ function handle_form(self, getFunction, setFunction, clientdata, option, label,
return form
end
-
-function handle_startstop(self, startstopfunction, clientdata)
- local result = startstopfunction(clientdata.action)
- result.value.result = self:redirect_to_referrer(result.value.result)
- return result
-end
-
diff --git a/lib/modelfunctions.lua b/lib/modelfunctions.lua
index 004a326..efc3693 100644
--- a/lib/modelfunctions.lua
+++ b/lib/modelfunctions.lua
@@ -18,24 +18,31 @@ function getenabled(processname)
return result
end
-function startstop_service(servicename, action, actions)
- local result = {}
- actions = actions or {"Start", "Stop", "Restart"}
- result.actions = cfe({ type="list", value=actions, label="Start/Stop actions" })
-
- if action then
+function get_startstop(servicename)
+ local service = cfe({ type="hidden", value=servicename, label="Service Name" })
+ local actions, descr = processinfo.daemon_actions(servicename)
+ local errtxt
+ if not actions then
+ errtxt = descr
+ end
+ return cfe({ type="group", label="Management", value={servicename=service}, option=actions, errtxt=errtxt })
+end
+
+function startstop_service(startstop, action)
+ if not action then
+ startstop.errtxt = "Invalid Action"
+ else
local reverseactions = {}
- for i,act in ipairs(actions) do reverseactions[string.lower(act)] = i end
- result.result = cfe({ label="Start/Stop result" })
+ for i,act in ipairs(startstop.option) do reverseactions[string.lower(act)] = i end
if reverseactions[string.lower(action)] then
- local cmdresult, errtxt = processinfo.daemoncontrol(servicename, action)
- result.result.value = cmdresult
- result.result.errtxt = errtxt
+ local cmdresult, errtxt = processinfo.daemoncontrol(startstop.value.servicename.value, string.lower(action))
+ startstop.descr = cmdresult
+ startstop.errtxt = errtxt
else
- result.result.errtxt = "Unknown command!"
+ startstop.errtxt = "Unknown command!"
end
end
- return cfe({ type="group", value=result, label="Start/Stop result" })
+ return startstop
end
function getstatus(processname, packagename, label, servicename)