From 10d4d3ab01a7ab59b8c07c8acb75c1b3ffd9c754 Mon Sep 17 00:00:00 2001 From: Mika Havela Date: Wed, 9 Apr 2008 13:21:08 +0000 Subject: Created a 'edit' page to edit interfaces. Fixed so you can delete interfaces (I probably broke this earlier, not knowing it). Added a new tab to create new interface. git-svn-id: svn://svn.alpinelinux.org/acf/alpine-baselayout/trunk@965 ab2d0c66-481e-0410-8bed-d214d4d58bed --- interfaces-config-html.lsp | 84 +++++++++++++++++++++------------------------- interfaces-controller.lua | 40 +++++++++++++++++++--- interfaces-delete-html.lsp | 5 +++ interfaces-read-html.lsp | 28 ++-------------- interfaces-update-html.lsp | 43 +++++++++--------------- interfaces.menu | 5 +-- 6 files changed, 101 insertions(+), 104 deletions(-) diff --git a/interfaces-config-html.lsp b/interfaces-config-html.lsp index e3a13e9..f0cc8ef 100644 --- a/interfaces-config-html.lsp +++ b/interfaces-config-html.lsp @@ -1,45 +1,39 @@ - - -

Interfaces file

- -

New interface

-
-
Create new interface
-
[Create]
-
- -

Existing interface(s)

- - 0 then do - j = view.iface[i] - iface = j.name.value ?> -

-
-
Method
-
- -
Hostname
-
- -
Address
-
/
- - -
Comments
-
- - - - -
Modify this interface
-
[update] -[delete]
-
- - - - - - + +DEBUGGING

DEBUG INFO: CFE

") +io.write(html.cfe_unpack(form)) +io.write("
") +--]] +?> + +

INTERFACES

+

Edit interfaces

+
+ " .. (myform.name.value or '') .. "
") + io.write("") + local tags = { "edit", "method", "address", "netmask", "gateway", "provider", "hostname", "pre-up", "up", "down", "post-down", "comment", } + for k1,v1 in pairs(tags) do + if (myform[v1]['value'] ~= "") then + io.write("") + if (myform[v1]['type'] == "link") then + io.write("") + else + io.write("") + end + end + end + io.write("
" .. myform[v1]['label'] .. "[ " .. string.gsub(myform[v1]['value'], "\n", "
") .. "
]
" .. string.gsub(myform[v1]['value'], "\n", "
") .. "
") + end + +end +io.write("
") +?> +
diff --git a/interfaces-controller.lua b/interfaces-controller.lua index 1a33bc2..90f0fe7 100644 --- a/interfaces-controller.lua +++ b/interfaces-controller.lua @@ -6,7 +6,7 @@ module (..., package.seeall) -- We use the self.conf table because it already has prefix,controller,etc -- The redir code is defined in the application error handler (acf-controller) local list_redir = function (self) - self.conf.action = "read" + self.conf.action = "config" self.conf.type = "redir" error (self.conf) end @@ -51,6 +51,18 @@ read = function (self ) return ( { actions = actions, iface = iface, status=status } ) end +config = function (self ) + local config = read(self) + for k,v in pairs(config.iface) do + v['edit']=cfe( + {name="edit", + label="Edit this record", + value="Edit", + type="link", + }) + end + return ( config ) +end -- Accepts form info -- Returns a cfe object (the form) @@ -82,11 +94,24 @@ update = function(self) end end + -- If the "cmddelete" button was used, then attempt to delete the interface + if self.clientdata.cmddelete then + self.conf.action = "delete?iface=" .. tostring(self.clientdata.name) + self.conf.type = "redir" + error (self.conf) + end + + -- Hide the 'name' field + data.name.type="hidden" + -- If we reach this point in the function, then we are providing a form -- for the user to edit (either first time in, or validation failed) -- Add a command button - data.cmd = cfe({type="action", value="save", label="action"}) + data.cmd = cfe({type="action", value="Save", name="cmd", label="Save/Apply above settings"}) + + -- Add a delete button + data.cmddelete = cfe({type="action", value="Delete", name="cmddelete", label="Delete this record"}) return ( cfe ({type="form", option={ script=ENV["SCRIPT_NAME"], @@ -94,7 +119,9 @@ update = function(self) controller = self.conf.controller, action = "update", extra = "?iface=" .. data.name.value }, - value = data} ) ) + value = data, + clientdata=clientdata, + } ) ) end @@ -121,7 +148,7 @@ delete = function(self) -- Otherwise, return a form local me = {} - me.iface = cfe({value = self.clientdata.iface }) + me.iface = cfe({name="iface", type="hidden", value = (self.clientdata.iface or "") }) me.action1 = cfe({name="cmd", type="action", value="delete", label="action"}) me.action2 = cfe({name="cmd", type="action", value="cancel", label="action"}) @@ -131,7 +158,10 @@ delete = function(self) controller = self.conf.controller, action = "delete", extra = "?iface=" .. (self.clientdata.iface or "") }, - value = me} ) ) + value = me, + clientdata=clientdata, + iface=iface, + } ) ) end diff --git a/interfaces-delete-html.lsp b/interfaces-delete-html.lsp index cb11de4..86bc224 100644 --- a/interfaces-delete-html.lsp +++ b/interfaces-delete-html.lsp @@ -1,4 +1,5 @@ +

Delete Interface

Are you you sure you want to delete

+
diff --git a/interfaces-read-html.lsp b/interfaces-read-html.lsp index 2ddd5c5..1884e3d 100644 --- a/interfaces-read-html.lsp +++ b/interfaces-read-html.lsp @@ -1,4 +1,6 @@ - + DEBUGGING

DEBUG INFO: CFE

") @@ -7,30 +9,6 @@ io.write("
") --]] ?> - 0) then - val.class = "error" - io.write(" class='error'") - end - io.write(">" .. val.label .. "\n") - if (viewonly) then - io.write("\t\t
" .. val.value .. "\n") - else - io.write("\t\t
" .. html.form[val.type](val) .. "\n") - end - if (val.descr) and (#val.descr > 0) then io.write("\t\t

" .. string.gsub(val.descr, "\n", "
") .. "

\n") end - if (#val.errtxt > 0) then io.write("\t\t

" .. string.gsub(val.errtxt, "\n", "
") .. "

\n") end - io.write("\t\t
\n") - end - end -end -?> -

SYSTEM INFO

+ DEBUGGING

DEBUG INFO: CFE

") @@ -7,38 +9,13 @@ io.write("
") --]] ?> -") - for k,v in pairs(tags) do - if (myform[v]) and (myform[v]["value"]) then - local val = myform[v] - io.write("\t 0) then - val.class = "error" - io.write(" class='error'") - end - io.write(">" .. val.label .. "\n") - if (viewonly) then - io.write("\t\t
" .. val.value .. "\n") - else - io.write("\t\t
" .. html.form[val.type](val) .. "\n") - end - if (val.descr) and (#val.descr > 0) then io.write("\t\t

" .. string.gsub(val.descr, "\n", "
") .. "

\n") end - if (#val.errtxt > 0) then io.write("\t\t

" .. string.gsub(val.errtxt, "\n", "
") .. "

\n") end - io.write("\t\t
\n") - end - end - io.write("
") -end -?> -

Update Interface

" method="POST"> +
+
+

Other actions

+
+ +
+
diff --git a/interfaces.menu b/interfaces.menu index 9562ce2..8ef863f 100644 --- a/interfaces.menu +++ b/interfaces.menu @@ -1,4 +1,5 @@ # Prefix and controller are already known at this point # Cat Group Tab Action -System Interfaces Define read -System Interfaces Update update +System Interfaces Status read +System Interfaces Edit_interfaces config +System Interfaces Create_New_interface create -- cgit v1.2.3