Browse Source

update ffho-config-mode-site-select

Karsten Böddeker 6 years ago
parent
commit
880755e7b2

+ 34 - 41
ffho/ffho-config-mode-site-select/luasrc/lib/gluon/config-mode/wizard/0200-site-select.lua

@@ -1,42 +1,35 @@
-local cbi = require "luci.cbi"
-local i18n = require "luci.i18n"
-local uci = require('luci.model.uci').cursor()
-local default = require 'gluon.site_config'
-local tools = require 'gluon.site_generate'
-
-local M = {}
-
-function M.section(form)
-  local sites = tools.get_config('/lib/gluon/site-select/sites.json')
-
-  local msg = i18n.translate('gluon-config-mode:site-select')
-  local s = form:section(cbi.SimpleSection, nil, msg)
-
-  local o = s:option(cbi.ListValue, "community", i18n.translate("Region"))
-  o.rmempty = false
-  o.optional = false
-
-  if uci:get_first("gluon-setup-mode", "setup_mode", "configured") == "0" then
-    o:value("")
-  else
-    o:value(default.site_code, default.site_name)
-  end
-
-  for _, site in pairs(sites) do
-    if site.site_select == nil or site.site_select.hidden ~= 1 then
-      o:value(site.site_code, site.site_name)
-    end
-  end
+return function(form, uci)
+	local default = require 'gluon.site_config'
+	local tools = require 'gluon.site_generate'
+
+	local sites = tools.get_config('/lib/gluon/site-select/sites.json')
+	
+	local s = form:section(Section, nil, translate('gluon-config-mode:site-select'))
+
+	local o = s:option(ListValue, 'community', translate('Region'))
+	o.optional = false
+
+	if uci:get_bool('gluon-setup-mode', uci:get_first('gluon-setup-mode','setup_mode'), 'configured')  then
+		o:value(default.site_code, default.site_name)
+	else
+		o:value('')
+	end
+
+	for _, site in pairs(sites) do
+		if (site.site_select or {}).hidden ~= 1 then
+			o:value(site.site_code, site.site_name)
+		end
+	end
+
+	function o:write(data)
+		if data.community ~= uci:get('currentsite', 'current', 'name') then
+			tools.set_site_code(data.community, false)
+		end
+
+		if data.community ~= default.site_code then
+			os.execute('sh "/lib/gluon/site-select/site-upgrade"')
+		end
+	end
+
+	return {'currentsite'}
 end
-
-function M.handle(data)
-  if data.community ~= uci:get('currentsite', 'current', 'name') then
-    tools.set_site_code(data.community)
-  end
-
-  if data.community ~= default.site_code then
-    os.execute('sh "/lib/gluon/site-select/site-upgrade"')
-  end
-end
-
-return M