0200-site-select.lua 1.0 KB

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