0200-site-select.lua 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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:value(default.site_code(), default.site_name())
  17. else
  18. o:value('')
  19. end
  20. for _, site in pairs(sites) do
  21. if (site.site_select or {}).hidden ~= 1 then
  22. o:value(site.site_code, site.site_name)
  23. end
  24. end
  25. function o:write(data)
  26. if data ~= uci:get('currentsite', 'current', 'name') then
  27. tools.set_site_code(data, false)
  28. end
  29. if data ~= default.site_code() then
  30. os.execute('sh "/lib/gluon/site-select/site-upgrade"')
  31. end
  32. end
  33. return {'currentsite'}
  34. end