[luci] Custom buttons and functions
Hanno Schupp
hanno.schupp at gmail.com
Sat Sep 26 12:26:08 CEST 2009
Very interesting. Thank you for the reply. I have two follow up questions:
You are suggesting the use of the CBI approach as oppose to the template/view approach by the previous respondent. Now the three approaches below seem to be tied to sections, which in turn have to be tied to a mapping to a schema. But would that not assumethe three kinds of buttons have to refer to the same /etc/config/file ? and if they do not (as is my case) does this mean these three button type cannot be on the same page?
And the action created in a function in the controller: Is that really creating a button on the screen? Or rather an action in response to an button still to be created on the page defined in the corresponding model/cbi file?
Is there a principle advantage in the CBI approach versus the view/template approach proposed by the previous respondent?
I may be very confused and therefore apologise for my ignorance in advance. I am not familiar with MVC kind of programming.
I look forward to your advice.
Thank again.
Hanno Schupp
-----Original Message-----
From: Jo-Philipp Wich [mailto:xm at subsignal.org]
Sent: Friday, 25 September 2009 11:12 p.m.
To: luci at lists.subsignal.org
Subject: Re: [luci] Custom buttons and functions
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi.
> I am trying to create a page that includes the following elements:
>
> a) A button that points to a URL outside the router, but with part of the
> URL parameters set by uci variables (set in a /etc/configfile
You can do that by wrapping the cbi action into a call action on the
controller side, like this:
local page = entry({"admin", "foo", "bar"}, call("myhandler"), ...)
function myhandler(self)
if luci.http.formvalue("some_value") then
luci.http.redirect("http://some.url/" ..
luci.http.formvalue("some_value"))
else
self.model = "some/cbi/model"
return _cbi(self)
end
end
> b) A button that allows to start a daemon or stop it. Button should toggle
> Start/Stop depending on the status of the programme
See the following url for an example:
http://luci.subsignal.org/trac/changeset/5257/luci/trunk/applications/luci-openvpn/luasrc
> c) A button that triggers a shell script programme when pressed. However,
> depending on a configuration option stored in one of the /etc/config files
> the button should either show, ready for action, or show a text in lieu of
> the button, indicating the function is not available.
This is best done in the cbi model like this:
local uci = require "luci.model.uci".cursor_state()
if uci:get("some_config", "some_section", "available") == "1" then
s:option(Button, ...)
else
s:option(DummyValue, ...)
end
Regards,
JoW
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAkq8pZkACgkQdputYINPTPOBmACfeoOEQNca10CDZwGeop7E5amZ
84IAoJewMSQgmLH6ExxhjtVyM7JGVWiE
=Kwhp
-----END PGP SIGNATURE-----
More information about the luci
mailing list