0500-contact-info.lua 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  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. 'You can provide your contact information here to '
  8. .. 'allow others to contact you. Please note that '
  9. .. 'this information will be visible <em>publicly</em> '
  10. .. 'on the internet together with your node\'s coordinates.'
  11. )
  12. )
  13. local o = s:option(cbi.Value, "_contact", i18n.translate("Contact info"))
  14. o.default = uci:get_first("gluon-node-info", "owner", "contact", "")
  15. o.rmempty = true
  16. o.datatype = "string"
  17. o.description = i18n.translate("e.g. E-mail or phone number")
  18. o.maxlen = 140
  19. end
  20. function M.handle(data)
  21. if data._contact ~= nil then
  22. uci:set("gluon-node-info", uci:get_first("gluon-node-info", "owner"), "contact", data._contact)
  23. else
  24. uci:delete("gluon-node-info", uci:get_first("gluon-node-info", "owner"), "contact")
  25. end
  26. uci:save("gluon-node-info")
  27. uci:commit("gluon-node-info")
  28. end
  29. return M