diff options
author | Mika Havela <mika.havela@gmail.com> | 2008-01-31 16:23:48 +0000 |
---|---|---|
committer | Mika Havela <mika.havela@gmail.com> | 2008-01-31 16:23:48 +0000 |
commit | 272e1f2444e68ed59533719f433b9435aa7f48a7 (patch) | |
tree | 17df8f736029f9c044e8beeb98c52b5c2b388e91 /syslog-controller.lua | |
parent | 6d30c3259050b88f42e92038e8eb8d325fc28540 (diff) | |
download | acf-alpine-baselayout-272e1f2444e68ed59533719f433b9435aa7f48a7.tar.bz2 acf-alpine-baselayout-272e1f2444e68ed59533719f433b9435aa7f48a7.tar.xz |
Changing things so we use cfe for sending/receiving things from model and controller.
The view-file is using loops instead to reduce code.
git-svn-id: svn://svn.alpinelinux.org/acf/alpine-baselayout/trunk@668 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'syslog-controller.lua')
-rw-r--r-- | syslog-controller.lua | 87 |
1 files changed, 77 insertions, 10 deletions
diff --git a/syslog-controller.lua b/syslog-controller.lua index b183a89..900856c 100644 --- a/syslog-controller.lua +++ b/syslog-controller.lua @@ -13,28 +13,88 @@ mvc.on_load = function(self, parent) end end +local function getstatus(self) + local status = self.model.getstatus() + if (#status.status.value > 0) then + status.status.value = "Enabled" + else + status.status.value = "Disabled" + end + return status +end + function status(self) - return { status=self.model.getstatus() } + return { status=getstatus(self) } end function config(self) - local cmdresult = {} + local cmd_save_result = {} local cmderrors = {} if ( self.clientdata.cmddaemon) then startstop = self.model:startstop_service( self.clientdata.cmddaemon ) end - if ( self.clientdata.cmdsave) then - local variables="-O -l -S -s -b -L -R" -- Advanced-config options - --local variables="-R" -- Guided-config options + if ( self.clientdata.cmd_save) then + local variables="logfile loglevel smallerlogs maxsize numrotate localandnetworklog remotelogging" -- Advanced-config options + --local variables="remotelogging" -- Guided-config options for var in string.gmatch(variables, "%S+") do - -- Send nil instead of "" causes the parameter to be removed/deleted/empty/unset + -- Send nil instead of "" causes the parameter to be removed/deleted/empty/unset the variable in the config-file if (self.clientdata[var] == "") then self.clientdata[var] = nil end - cmdresult[var],cmderrors[var] = self.model:setconfigs("SYSLOGD_OPTS",var,self.clientdata[var]) + cmd_save_result[var] = self.model:setconfigs("SYSLOGD_OPTS",var,self.clientdata[var]) end end - local status = self.model.getstatus() + local status = getstatus(self) +--[[ + if (#status.status.value > 0) then + status.status.value = "Enabled" + else + status.status.value = "Disabled" + end +--]] + local config, errors = self.model.getconfig() + -- Add a cmd button to the view + config.cmd_save = cfe({ name="cmd_save", + label="Save/Apply above settings", + value="Save", + type="submit", + }) + -- Add a management buttons + management = {} + management.start = cfe({ name="start", + label="Program control-panel", + value="Start", + type="submit", + }) + management.stop = cfe({ name="stop", + label="Program control-panel", + value="Stop", + type="submit", + }) + management.restart = cfe({ name="restart", + label="Program control-panel", + value="Restart", + type="submit", + }) + -- Disable management buttons based on if the process is running or not + if (string.lower(status.status.value) == "enabled" ) then + management.start.disabled = "yes" + management.stop.disabled = nil + else + management.start.disabled = nil + management.stop.disabled = "yes" + end + + -- Disable management buttons if there exist errors in the config + for k,v in pairs(config) do + if (config[k]["errtxt"] ~= "") then + management.start.disabled = "yes" + management.stop.disabled = "yes" + management.restart.disabled = "yes" + break + end + end + local url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller local cmderrors_str = "" @@ -50,11 +110,16 @@ function config(self) if (cmderrors_str == "") then cmderrors_str = nil end return { + option={ script=ENV["SCRIPT_NAME"], + prefix=self.conf.prefix, + controller = self.conf.controller, + action = "config", }, status = status, startstop = startstop, clientdata = self.clientdata, - cmdresult = cmdresult, + management = management, config = config, + cmd_save_result = cmd_save_result, errors = errors, cmderrors = cmderrors_str, url = url, } @@ -70,7 +135,9 @@ function expert(self) startstop = self.model:startstop_service( self.clientdata.cmddaemon ) end - local status = self.model.getstatus() +-- local status = self.model.getstatus() + local status = getstatus(self) + local url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller return { file = self.model:get_filedetails(), |