diff options
author | Ted Trask <ttrask01@yahoo.com> | 2008-07-08 13:27:06 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2008-07-08 13:27:06 +0000 |
commit | d6eaceb7368639a4d634b06b2e1f09498c81e1e4 (patch) | |
tree | a8b6c9286c95eeb331620b83842a9e186d90dd70 /tinydns-controller.lua | |
parent | 450023d50615816c7db2d4abfaface18132a1c47 (diff) | |
download | acf-tinydns-d6eaceb7368639a4d634b06b2e1f09498c81e1e4.tar.bz2 acf-tinydns-d6eaceb7368639a4d634b06b2e1f09498c81e1e4.tar.xz |
Modified tinydns to use controllerfunctions, modelfunctions, common lsp files, and new view without action functionality.
git-svn-id: svn://svn.alpinelinux.org/acf/tinydns/trunk@1290 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'tinydns-controller.lua')
-rw-r--r-- | tinydns-controller.lua | 117 |
1 files changed, 9 insertions, 108 deletions
diff --git a/tinydns-controller.lua b/tinydns-controller.lua index dd567c5..e0e7e2a 100644 --- a/tinydns-controller.lua +++ b/tinydns-controller.lua @@ -1,12 +1,7 @@ module(..., package.seeall) +require("controllerfunctions") require("validator") --- ################################################################################ --- LOCAL FUNCTIONS - --- ################################################################################ --- PUBLIC FUNCTIONS - default_action = "status" function status(self) @@ -18,71 +13,15 @@ function view(self) end function startstop(self) - local result - if self.clientdata.action then - result = self.model:startstop_service(self.clientdata.action) - self.sessiondata.tinydnsstartstopresult = result - self.redirect_to_referrer(self) - end - - local status = self.model.getstatus() - status = status.value.status - if self.sessiondata.tinydnsstartstopresult then - result = self.sessiondata.tinydnsstartstopresult - self.sessiondata.tinydnsstartstopresult = nil - end - - return cfe({ type="group", value={status=status, result=result} }) + return controllerfunctions.handle_startstop(self, self.model.startstop_service, self.model.getstatus, self.clientdata) end function config(self) - local config = self.model.getconfig() - - if self.clientdata.Save then - for name,value in pairs(self.clientdata) do - if config.value[name] then - config.value[name].errtxt = nil - config.value[name].value = value - end - end - - config = self.model.setconfig(config) - if not config.errtxt then - config.descr = "Configuration Set" - end - end - - config.type = "form" - config.option = "Save" - config.label = "Edit configuration" - - return config + return controllerfunctions.handle_form(self, self.model.getconfig, self.model.setconfig, self.clientdata, "Save", "Edit Configuration", "Configuration Saved") end function newfile(self) - local create = self.model.getnewconfigfile() - - -- In case we are trying to create a new configfile - if (self.clientdata.Create) then - for name,value in pairs(self.clientdata) do - if create.value[name] then - create.value[name].errtxt = nil - create.value[name].value = value - end - end - - create = self.model.createconfigfile(create) - if not create.errtxt then - create.descr = "Created new config file" - redirect(self, "listfiles") - end - end - - create.type = "form" - create.option = "Create" - create.label = "Create new config file" - - return create + return controllerfunctions.handle_form(self, self.model.getnewconfigfile, self.model.createconfigfile, self.clientdata, "Create", "Create New Config File", "Config File Created", "listfiles") end function listfiles(self) @@ -96,53 +35,15 @@ function listfiles(self) return cfe({ type="list", value=config, label="Config files" }) end -function edit(self) - local config = self.model.get_filedetails(self.clientdata.filename) - if self.clientdata.Save then - local result = self.model.updatefilecontent(self.clientdata.filename, self.clientdata.filecontent) - if not result.value then - config.value.filecontent.value = self.clientdata.filecontent - config.value.filecontent.errtxt = result.errtxt - config.errtxt = "Failed to save config!" - else - config = self.model.get_filedetails(self.clientdata.filename) - config.descr = "Saved file" - end - elseif self.clientdata.linenumber and validator.is_integer(self.clientdata.linenumber) then +function editfile(self) + config = controllerfunctions.handle_form(self, function() return self.model.get_filedetails(self.clientdata.filename) end, self.model.set_filedetails, self.clientdata, "Save", "Edit Config File", "Config File Saved") + + if self.clientdata.linenumber and validator.is_integer(self.clientdata.linenumber) then config.value.filecontent.linenumber = self.clientdata.linenumber end - - config.type = "form" - config.option = "Save" - config.label = "Edit config file" - - return config -end - -function expert(self) - local config = self.model.get_filedetails(self.clientdata.filename) - if self.clientdata.Save then - local result = self.model.updatefilecontent(self.clientdata.filename, self.clientdata.filecontent) - if not result.value then - config.value.filecontent.value = self.clientdata.filecontent - config.value.filecontent.errtxt = result.errtxt - config.errtxt = "Failed to save config!" - else - config = self.model.get_filedetails(self.clientdata.filename) - config.descr = "Saved file" - end - end - - config.type = "form" - config.option = "Save" - config.label = "Edit config file" - return config end function delete(self) - local cmdresult = self.model.remove_file(self.clientdata.filename) - --self.sessiondata.cmdresult = cmdresult - redirect_to_referrer(self) - return cmdresult + return self:redirect_to_referrer(self.model.remove_file(self.clientdata.filename)) end |