[luci] Editing several configs at one page

Tomasz Mrugalski spam at klub.com.pl
Sun Jan 24 15:28:51 CET 2010


Hi,
I'd like to edit 3 config files on one page. I've found a way to do this.
Here's an example. I'm trying to configure a tunnel. There are 2 config 
files. One defines behavior when tunnel is automatic and the second one
is manual. There is also third one that defines tunnel configuration mode
(automatic or manual). Here's simplified code of my page:

tunnelMode = Map("mode","TunnelMode")
m = Section(NamedSection, "general","general")
mode = m:option(ListValue, "tunnelmode","Tunnel mode")

auto = Map("tunnel_auto", "tunnel in DHCPv6 mode")
-- automatic tunnel parameters go here

manual = Map("tunnel_manual", "Static tunnel configuration")
-- static tunnel parameters go here

return tunnelMode, auto, manual

However, there's one thing that bothers me. How do I make auto and manual 
Maps appear only if mode is set to 0 or 1? Map class does not have 
depends method.

I've tried to do something like
local returnForms = {}
tunnelMode = Map("mode","TunnelMode")
table.insert(returnForms, tunnelMode)

if mode == 0 then
   auto = Map("tunnel_auto", "tunnel in DHCPv6 mode")
   table.insert(returnForms, auto)
else
   manual = Map("tunnel_manual", "Static tunnel configuration")
   table.insert(returnForms, manual)
end

return unpack(returnForms)

This *almost* works. Depending on the mode chosen, I page contains manual 
or automatic parameters. There are only 2 drawback:
- I need to click SAVE after I change tunnelmode (it would be better if
   specific form was "hiddable")
- When I change from static to auto (or vice versa), form
   appears empty, i.e. all fields are visible, but does not
   contain values. If I go to my page via menu, then fields
   content reappears.

How to proceed with this?

Is it possible to make a field "auto-submitable", i.e. when value is 
changed, sumbit form immediately?

By the way: I think I have enough experience that I could contribute to 
the documentation. I'd like to work on extending "HowTo: Write 
Modules". Basically add number of examples how to achieve various 
things. Is it possible to get an account in trac system?

Thanks,
Tomek Mrugalski









More information about the luci mailing list