0200-site-select.lua 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. return function(form, uci)
  2. local default = require 'gluon.site'
  3. local tools = require 'gluon.site_generate'
  4. local sites = tools.get_config('/lib/gluon/site-select/sites.json')
  5. local site_i18n = i18n 'gluon-site'
  6. local pkg_i18n = i18n 'ffho-config-mode-site-select'
  7. local help = site_i18n._translate('gluon-config-mode:site-select') or pkg_i18n.translate(
  8. 'Here you have the possibility of selecting the region in which '
  9. .. 'your node is placed. Please keep in mind that your router '
  10. .. 'connects only with the mesh of the selected region.'
  11. )
  12. local s = form:section(Section, nil, help)
  13. local o = s:option(ListValue, 'community', translate('Region'))
  14. o.optional = false
  15. if uci:get_bool('gluon-setup-mode', uci:get_first('gluon-setup-mode','setup_mode'), 'configured') then
  16. o.default = default.site_code()
  17. end
  18. for _, site in pairs(sites) do
  19. if (site.site_select or {}).hidden ~= 1 then
  20. o:value(site.site_code, site.site_name)
  21. end
  22. end
  23. function o:write(data)
  24. if data ~= uci:get('currentsite', 'current', 'name') then
  25. tools.set_site_code(data, false)
  26. end
  27. if data ~= default.site_code() then
  28. os.execute('sh "/lib/gluon/site-select/site-upgrade"')
  29. end
  30. end
  31. return {'currentsite'}
  32. end