noderole.lua 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. local f, s, o
  2. local site = require 'gluon.site_config'
  3. local i18n = require "luci.i18n"
  4. local uci = luci.model.uci.cursor()
  5. local config = 'gluon-node-info'
  6. -- where to read the configuration from
  7. local role = uci:get(config, uci:get_first(config, "system"), "role")
  8. f = SimpleForm("role", i18n.translate("Node role"))
  9. f.template = "admin/expertmode"
  10. s = f:section(SimpleSection, nil, i18n.translate(
  11. "If this node has a special role within the freifunk network you can specify this role here. "
  12. .. "Please find out about the available roles and their impact first. "
  13. .. "Only change the role if you know what you are doing."))
  14. o = s:option(ListValue, "role", i18n.translate("Role"))
  15. o.default = role
  16. o.rmempty = false
  17. for _, role in ipairs(site.roles.list) do
  18. o:value(role, i18n.translate('gluon-luci-node-role:role:' .. role))
  19. end
  20. function f.handle(self, state, data)
  21. if state == FORM_VALID then
  22. uci:set(config, uci:get_first(config, "system"), "role", data.role)
  23. uci:save(config)
  24. uci:commit(config)
  25. end
  26. end
  27. return f