noderole.lua 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. local f, s, o
  2. local site = require 'gluon.site_config'
  3. local i18n = require "luci.i18n"
  4. local uci = require("simple-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. s = f:section(SimpleSection, nil, i18n.translate(
  10. "If this node has a special role within the freifunk network you can specify this role here. "
  11. .. "Please find out about the available roles and their impact first. "
  12. .. "Only change the role if you know what you are doing."))
  13. o = s:option(ListValue, "role", i18n.translate("Role"))
  14. o.default = role
  15. o.rmempty = false
  16. for _, role in ipairs(site.roles.list) do
  17. o:value(role, i18n.translate('gluon-luci-node-role:role:' .. role))
  18. end
  19. function f.handle(self, state, data)
  20. if state == FORM_VALID then
  21. uci:set(config, uci:get_first(config, "system"), "role", data.role)
  22. uci:save(config)
  23. uci:commit(config)
  24. end
  25. end
  26. return f