summaryrefslogtreecommitdiffstats
path: root/opennhrp-controller.lua
diff options
context:
space:
mode:
authorMika Havela <mika.havela@gmail.com>2008-04-08 15:12:44 +0000
committerMika Havela <mika.havela@gmail.com>2008-04-08 15:12:44 +0000
commit910f45e7c9889172631a6554fbf90c70e850984c (patch)
tree4032e8840233c301746a42cdcc3d914ca32eb2ab /opennhrp-controller.lua
parentbb074fac16b8227a0bbb35208261635fed1b0891 (diff)
downloadacf-opennhrp-910f45e7c9889172631a6554fbf90c70e850984c.tar.bz2
acf-opennhrp-910f45e7c9889172631a6554fbf90c70e850984c.tar.xz
Cleaning up code.
git-svn-id: svn://svn.alpinelinux.org/acf/opennhrp/trunk@958 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'opennhrp-controller.lua')
-rw-r--r--opennhrp-controller.lua65
1 files changed, 37 insertions, 28 deletions
diff --git a/opennhrp-controller.lua b/opennhrp-controller.lua
index ac216e7..e90c030 100644
--- a/opennhrp-controller.lua
+++ b/opennhrp-controller.lua
@@ -1,25 +1,21 @@
module(..., package.seeall)
--- This is the object/text used when we want to add a new record
-
+-- Load libraries
require("format")
+-- Set variables
local newrecordtxt = "[New]"
+-- ################################################################################
+-- LOCAL FUNCTIONS
+
local list_redir = function (self)
self.conf.action = "status"
self.conf.type = "redir"
error (self.conf)
end
-mvc = {}
-mvc.on_load = function(self, parent)
- if (self.worker[self.conf.action] == nil ) or ( self.conf.action == "init" ) then
- self.worker[self.conf.action] = list_redir(self)
- end
-end
-
-local function displaycmdmanagement(disablestart,disablestop,disablerestart)
+local function displaycmdmanagement(pidofstatus)
-- Add a management buttons
local management = {}
management.start = cfe({ name="cmdmanagement",
@@ -37,22 +33,38 @@ local function displaycmdmanagement(disablestart,disablestop,disablerestart)
value="Restart",
type="submit",
})
+ -- next CFE can be used to present the result of the previous action
+ management.actionresult = cfe({ name="actionresult",
+ label="Previous action result",
+ descr="", --Content of this variable is displayed as <PRE> ... </PRE> in BLACK text
+ errtxt="", --Content of this variable is displayed as <PRE> ... </PRE> in RED text
+ })
-- Disable management buttons based on if the process is running or not
- if (disablestart) then management.start.disabled = "yes" end
- if (disablestop) then management.stop.disabled = "yes" end
- if (disablerestart) then management.restart.disabled = "yes" end
+ if (pidofstatus) then
+ management.start.disabled = "yes"
+ else
+ management.stop.disabled = "yes"
+ management.restart.disabled = "yes"
+ end
return management
end
-
-- ################################################################################
-- PUBLIC FUNCTIONS
+
+mvc = {}
+function mvc.on_load (self, parent)
+ if (self.worker[self.conf.action] == nil ) or ( self.conf.action == "init" ) then
+ self.worker[self.conf.action] = list_redir(self)
+ end
+end
+
function status(self)
return { status=self.model.getstatus() }
end
-expert = function (self)
+function expert (self)
local modifications = self.clientdata.filecontent or ""
if ( self.clientdata.cmdsave ) then
modifications = self.model:update_filecontent(modifications)
@@ -60,7 +72,7 @@ expert = function (self)
local url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller
-- Start/Stop/Restart process
- local cmdmanagement
+ local cmdmanagement, actionresult
if ( self.clientdata.cmdmanagement) then
cmdmanagement = cfe({
name="cmdmanagement",
@@ -70,7 +82,7 @@ expert = function (self)
value=string.lower(self.clientdata.cmdmanagement), -- This row contains start/stop/restart (one of these commands)
}),
})
- local actionresult, cmdmanagement = self.model:startstop_service( cmdmanagement.action )
+ actionresult, cmdmanagement = self.model:startstop_service( cmdmanagement.action )
end
local status=self.model.getstatus()
@@ -88,26 +100,23 @@ expert = function (self)
end
- -- Management buttons
- local disablestart,disablestop,disablerestart
- -- Disable management buttons based on if the process is running or not
- if (string.lower(status.status.value) == "enabled" ) then
- disablestart = "yes"
- else
- disablestop = "yes"
+ -- Management buttons (Hide/show buttons
+ local pidofstatus
+ if (string.lower(status.status.value) == "enabled" ) then pidofstatus = true end
+ management = displaycmdmanagement(pidofstatus)
+ if (actionresult) then
+ management.actionresult.descr=cmdmanagement.descr
+ management.actionresult.errtxt=cmdmanagement.errtxt
end
- -- Display management buttons
- management = displaycmdmanagement(disablestart,disablestop,disablerestart)
return ( {
status = status,
file = file,
modifications = modifications,
management = management,
- cmdmanagement = cmdmanagement,
url = url, } )
end
-logfile = function (self)
+function logfile(self)
local status=self.model.getstatus()
local logfile = self.model:get_logfile()