0200-site-select.lua 1.1 KB

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