0200-site-select.lua 932 B

1234567891011121314151617181920212223242526272829303132333435
  1. return function(form, uci)
  2. local default = require 'gluon.site_config'
  3. local tools = require 'gluon.site_generate'
  4. local sites = tools.get_config('/lib/gluon/site-select/sites.json')
  5. local s = form:section(Section, nil, translate('gluon-config-mode:site-select'))
  6. local o = s:option(ListValue, 'community', translate('Region'))
  7. o.optional = false
  8. if uci:get_bool('gluon-setup-mode', uci:get_first('gluon-setup-mode','setup_mode'), 'configured') then
  9. o:value(default.site_code, default.site_name)
  10. else
  11. o:value('')
  12. end
  13. for _, site in pairs(sites) do
  14. if (site.site_select or {}).hidden ~= 1 then
  15. o:value(site.site_code, site.site_name)
  16. end
  17. end
  18. function o:write(data)
  19. if data ~= uci:get('currentsite', 'current', 'name') then
  20. tools.set_site_code(data, false)
  21. end
  22. if data ~= default.site_code then
  23. os.execute('sh "/lib/gluon/site-select/site-upgrade"')
  24. end
  25. end
  26. return {'currentsite'}
  27. end