[luci] refreshing site after pressing a button

Martin Röcker roecker at empty-v.de
Fri Nov 28 10:54:14 CET 2014


Hi,

I need to put a toggle button on the interface overview page to
enable/disable bridging of eth0 and eth1. The buttons label should show
"disable" when the interfaces are bridged, otherwise "enable".

My problem is that after pressing the button the action is performed but
the buttons text/value is not updated. From this it follows that
pressing the button again has no effekt. I need to manually reload the
page to get the button working again.


The code I use looks similar to this:
-- 8< --
    local uci = require "luci.model.uci".cursor_state()

    local m2 = Map("network", translate("LAN interface mode"))
    local s = m2:section(NamedSection, "lan", translate("Bridge") )

    if uci:get("network", "lan", "type") == "bridge" then
        v = s:option(Button, "type", ... )
        v.inputtitle = "disable"
    else
        v = s:option(Button, ... ")
        v.inputtitle = "enable"
    end
    v.title = "Bridge mode:"
    v.inputstyle = "apply"

    function v.write(self, section, value)
        if value == "disable" then
            -- uci commands to switch to unbridged mode
        else
            -- uci commands to switch to bridged mode
        end
        m.uci:commit("network")
    end
-- >8 --

I know this is a strange example but I ran into the same problem with a
button I used to execute a shell script. The script created a
ssh-connection to a remote host and I wanted existing connections to be
listed on the page. When I was pressing the button the connection has
been established, but I needed to reload the page before getting the
list of connections shown.

Maybe this is some kind of timing or caching problem. But I don't know
how to fix this.

Can anyone give me a hint how to get this done?

Thanks!
Martin


More information about the luci mailing list