0500-contact-info.lua 1.1 KB

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