2014-07-27 19:31:45 +02:00
|
|
|
local cbi = require "luci.cbi"
|
2015-03-19 01:08:38 +01:00
|
|
|
local i18n = require "luci.i18n"
|
2014-07-27 19:31:45 +02:00
|
|
|
local uci = luci.model.uci.cursor()
|
|
|
|
|
|
|
|
local M = {}
|
|
|
|
|
|
|
|
function M.section(form)
|
|
|
|
local s = form:section(cbi.SimpleSection, nil,
|
2015-03-19 01:08:38 +01:00
|
|
|
i18n.translate("If you want your node to be displayed on the map, you can enter its coodinates here."))
|
2014-07-27 19:31:45 +02:00
|
|
|
|
|
|
|
local o
|
|
|
|
|
2015-03-19 01:08:38 +01:00
|
|
|
o = s:option(cbi.Flag, "_location", i18n.translate("Show node on the map"))
|
2014-07-27 19:31:45 +02:00
|
|
|
o.default = uci:get_first("gluon-node-info", "location", "share_location", o.disabled)
|
|
|
|
o.rmempty = false
|
|
|
|
|
2015-03-19 01:08:38 +01:00
|
|
|
o = s:option(cbi.Value, "_latitude", i18n.translate("Latitude"))
|
2014-07-27 19:31:45 +02:00
|
|
|
o.default = uci:get_first("gluon-node-info", "location", "latitude")
|
|
|
|
o:depends("_location", "1")
|
|
|
|
o.rmempty = false
|
|
|
|
o.datatype = "float"
|
2015-03-19 01:08:38 +01:00
|
|
|
o.description = i18n.translatef("e.g. %s", "53.873621")
|
2014-07-27 19:31:45 +02:00
|
|
|
|
2015-03-19 01:08:38 +01:00
|
|
|
o = s:option(cbi.Value, "_longitude", i18n.translate("Longitude"))
|
2014-07-27 19:31:45 +02:00
|
|
|
o.default = uci:get_first("gluon-node-info", "location", "longitude")
|
|
|
|
o:depends("_location", "1")
|
|
|
|
o.rmempty = false
|
|
|
|
o.datatype = "float"
|
2015-03-19 01:08:38 +01:00
|
|
|
o.description = i18n.translatef("e.g. %s", "10.689901")
|
2014-07-27 19:31:45 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function M.handle(data)
|
|
|
|
local sname = uci:get_first("gluon-node-info", "location")
|
|
|
|
|
|
|
|
uci:set("gluon-node-info", sname, "share_location", data._location)
|
|
|
|
if data._location and data._latitude ~= nil and data._longitude ~= nil then
|
|
|
|
uci:set("gluon-node-info", sname, "latitude", data._latitude)
|
|
|
|
uci:set("gluon-node-info", sname, "longitude", data._longitude)
|
|
|
|
end
|
|
|
|
uci:save("gluon-node-info")
|
|
|
|
uci:commit("gluon-node-info")
|
|
|
|
end
|
|
|
|
|
|
|
|
return M
|