0400-geo-location.lua 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. local cbi = require "luci.cbi"
  2. local i18n = require "luci.i18n"
  3. local uci = luci.model.uci.cursor()
  4. local M = {}
  5. function M.section(form)
  6. local s = form:section(cbi.SimpleSection, nil, i18n.translate(
  7. 'If you want the location of your node to be displayed on the map, '
  8. .. 'you can enter its coordinates here.'))
  9. local o
  10. o = s:option(cbi.Flag, "_location", i18n.translate("Show node on the map"))
  11. o.default = uci:get_first("gluon-node-info", "location", "share_location", o.disabled)
  12. o.rmempty = false
  13. o = s:option(cbi.Value, "_latitude", i18n.translate("Latitude"))
  14. o.default = uci:get_first("gluon-node-info", "location", "latitude")
  15. o:depends("_location", "1")
  16. o.rmempty = false
  17. o.datatype = "float"
  18. o.description = i18n.translatef("e.g. %s", "53.873621")
  19. o = s:option(cbi.Value, "_longitude", i18n.translate("Longitude"))
  20. o.default = uci:get_first("gluon-node-info", "location", "longitude")
  21. o:depends("_location", "1")
  22. o.rmempty = false
  23. o.datatype = "float"
  24. o.description = i18n.translatef("e.g. %s", "10.689901")
  25. end
  26. function M.handle(data)
  27. local sname = uci:get_first("gluon-node-info", "location")
  28. uci:set("gluon-node-info", sname, "share_location", data._location)
  29. if data._location and data._latitude ~= nil and data._longitude ~= nil then
  30. uci:set("gluon-node-info", sname, "latitude", data._latitude:trim())
  31. uci:set("gluon-node-info", sname, "longitude", data._longitude:trim())
  32. end
  33. uci:save("gluon-node-info")
  34. uci:commit("gluon-node-info")
  35. end
  36. return M