diff options
author | Ted Trask <ttrask01@yahoo.com> | 2008-05-15 20:15:32 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2008-05-15 20:15:32 +0000 |
commit | d8afa977ce3587ee2819c44d545753aa0cc38760 (patch) | |
tree | 82ea6d0e957959ba1a2777f090cffac9f941734c | |
parent | 7d9b0d93dd7c3dee3acd4da629b4f519eafe0f7b (diff) | |
download | acf-alpine-baselayout-d8afa977ce3587ee2819c44d545753aa0cc38760.tar.bz2 acf-alpine-baselayout-d8afa977ce3587ee2819c44d545753aa0cc38760.tar.xz |
For cfe.type='form', use cfe.option as the command to save the form data i.e. can be used as button name. Modified pages that use 'form' to also use 'option'.
git-svn-id: svn://svn.alpinelinux.org/acf/alpine-baselayout/trunk@1122 ab2d0c66-481e-0410-8bed-d214d4d58bed
-rw-r--r-- | syslog-config-html.lsp | 2 | ||||
-rw-r--r-- | syslog-controller.lua | 21 | ||||
-rw-r--r-- | syslog-expert-html.lsp | 2 | ||||
-rw-r--r-- | syslog-model.lua | 64 |
4 files changed, 52 insertions, 37 deletions
diff --git a/syslog-config-html.lsp b/syslog-config-html.lsp index ac5b77e..03a7b4a 100644 --- a/syslog-config-html.lsp +++ b/syslog-config-html.lsp @@ -42,7 +42,7 @@ end ?> ?> </DL> <H2>SAVE AND APPLY ABOVE SETTINGS</H2> -<DL><DT>Save/Apply above settings</DT><DD><input class="submit" type="submit" name="save" value="Save"></DD></DL> +<DL><DT>Save/Apply above settings</DT><DD><input class="submit" type="submit" name="<?= form.option ?>" value="Save"></DD></DL> </form> <? ---[[ ?> diff --git a/syslog-controller.lua b/syslog-controller.lua index 5c47415..48e7b56 100644 --- a/syslog-controller.lua +++ b/syslog-controller.lua @@ -8,28 +8,35 @@ end function config(self) local config - if self.clientdata.save then + if self.clientdata.Save then config = self.model.updateconfig(self.clientdata) else config = self.model.getconfig() end + config.type = "form" + config.label = "Edit config" + config.option = "Save" return config end function expert(self) -- Save changes + local config local modifications = self.clientdata.filecontent or "" - if self.clientdata.save then - self.model:update_filecontent(modifications) + if self.clientdata.Save then + config = self.model:update_filecontent(modifications) + if not config.errtxt then + config.descr = "Saved File" + end + else + config = self.model:get_filedetails() end - local config = self.model:get_filedetails() config.type = "form" - if self.clientdata.save then - config.descr = "Saved File" - end + config.label = "Edit config" + config.option = "Save" return config end diff --git a/syslog-expert-html.lsp b/syslog-expert-html.lsp index 37e1a4f..be57b96 100644 --- a/syslog-expert-html.lsp +++ b/syslog-expert-html.lsp @@ -34,7 +34,7 @@ displayitem(form.value.mtime) </textarea> <H2>SAVE AND APPLY ABOVE SETTINGS</H2> -<DL><DT>Save/Apply above settings</DT><DD><input class="submit" type="submit" name="save" value="Save"></DD></DL> +<DL><DT>Save/Apply above settings</DT><DD><input class="submit" type="submit" name="<?= form.option ?>" value="Save"></DD></DL> </form> <? ---[[ ?> diff --git a/syslog-model.lua b/syslog-model.lua index a77986b..c105dd4 100644 --- a/syslog-model.lua +++ b/syslog-model.lua @@ -55,6 +55,38 @@ local writeconfig = function (config) return cmdmessage, cmderror end +local validateconfig = function(config) + local success = true + -- Validate entries and create error strings + if not validator.is_valid_filename(config.value.logfile.value, "/var/log") then + config.value.logfile.errtxt = "Not a valid file name in /var/log" + success = false + end + if not validator.is_integer_in_range(config.value.loglevel.value, 1, 8) then + config.value.loglevel.errtxt = "Out of range!" + success = false + end + if config.value.maxsize.value ~= "" and not validator.is_integer(config.value.maxsize.value) then + config.value.maxsize.errtxt = "Must be an integer" + success = false + end + if config.value.numrotate.value ~= "" and not validator.is_integer_in_range(config.value.numrotate.value, 0, 99) then + config.value.numrotate.errtxt = "Out of range!" + success = false + end + if config.value.localandnetworklog.value == true and config.value.remotelogging.value == "" then + config.value.localandnetworklog.errtxt = "Logging to local and network is not possible unless you define a host for remote logging" + success = false + end + local hostport = format.string_to_table(config.value.remotelogging.value, ":") + if hostport[2] and not (validator.is_port(hostport[2])) then + config.value.remotelogging.errtxt = "Not a valid port" + success = false + end + + return success, config +end + -- ################################################################################ -- PUBLIC FUNCTIONS @@ -189,32 +221,7 @@ function updateconfig (clientdata) end end - -- Validate entries and create error strings - if not validator.is_valid_filename(config.value.logfile.value, "/var/log") then - config.value.logfile.errtxt = "Not a valid file name in /var/log" - success = false - end - if not validator.is_integer_in_range(config.value.loglevel.value, 1, 8) then - config.value.loglevel.errtxt = "Out of range!" - success = false - end - if config.value.maxsize.value ~= "" and not validator.is_integer(config.value.maxsize.value) then - config.value.maxsize.errtxt = "Must be an integer" - success = false - end - if config.value.numrotate.value ~= "" and not validator.is_integer_in_range(config.value.numrotate.value, 0, 99) then - config.value.numrotate.errtxt = "Out of range!" - success = false - end - if config.value.localandnetworklog.value == true and config.value.remotelogging.value == "" then - config.value.localandnetworklog.errtxt = "Logging to local and network is not possible unless you define a host for remote logging" - success = false - end - local hostport = format.string_to_table(config.value.remotelogging.value, ":") - if hostport[2] and not (validator.is_port(hostport[2])) then - config.value.remotelogging.errtxt = "Not a valid port" - success = false - end + success, config = validateconfig(config) if success == true then config.descr, config.errtxt = writeconfig(config) @@ -226,7 +233,8 @@ function updateconfig (clientdata) end function update_filecontent (self, modifications) - local path = configfile - fs.write_file(path, format.dostounix(modifications)) + -- FIXME add validation before writing + fs.write_file(configfile, format.dostounix(modifications)) + return get_filedetails() end |