OpenWrt Forum Archive

Topic: Luci naming convention for html/javascript

The content of this topic has been archived on 22 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

I need to add a button to a Luci page, similar to the toggle Wireless on/off button.

I need to add to the system.lua page however.

In wifi.lua is this:

if m:formvalue("cbid.wireless.%s.__toggle" % wdev:name()) then

The question I have is in system.lua, the result on the html page is:

cbid.system.cfg02e48a.__togglegps

My question is where does the "cfg02e48a" value come from so I can reference it correctly in system.lua when checking if the button was pressed?

I assume it has something to do with the fact that the UCI config file "system", and the config system section has no "name", but not sure where the "name" is being created and/or how to reference it.

Thanks!

(Last edited by JohnV on 13 Jan 2015, 21:24)

JohnV wrote:

I need to add a button to a Luci page, similar to the toggle Wireless on/off button.

I need to add to the system.lua page however.

In wifi.lua is this:

if m:formvalue("cbid.wireless.%s.__toggle" % wdev:name()) then

The question I have is in system.lua, the result on the html page is:

cbid.system.cfg02e48a.__togglegps

My question is where does the "cfg02e48a" value come from so I can reference it correctly in system.lua when checking if the button was pressed?

I assume it has something to do with the fact that the UCI config file "system", and the config system section has no "name", but not sure where the "name" is being created and/or how to reference it.

Thanks!

Let me try to help you.

First,  every config file has some sections , each of which has a section type and section id. Those who doesn't have a id is called annoymous. So the id will be assigned by the uci, like cfg123. Such as the wifi-iface in the wireless, it has no id but the type "wifi-iface". So  it will be assigned an id by the uci jus like cfg12345.

Second, you can find a function which you find helpfull in cbi.lua in ~/luci/, named cbid(). You can read it find more how to referrence it as well as uci.lua in ~/luci/model/ which will also do some help.

I hope it will help. If some mistakes, please tell me.

Wandy

Use the .write callback of the togglegps option object, that recives an argument which should contain the anonymous ID.

jow wrote:

Use the .write callback of the togglegps option object, that recives an argument which should contain the anonymous ID.

The object is a button however.  I did not think the write callback would be called since it is not a "value".

    en = s:taboption("gps", Button, "__togglegps")

I tried the .write callback, and it does not seem to be called.

The following works, but is pretty ugly:

function m.parse(map)
    local anonyname
    local name = s.map:formvaluetable("cbid.system")                                
    for k,v in pairs(name) do                       
        anonyname = k:match("%w+")
        break
    end 

The discussion might have continued from here.