1
0

widget.lua 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. -- Copyright 2012 Manuel Munz <freifunk at somakoma dot de>
  2. -- Licensed to the public under the Apache License 2.0.
  3. local uci = require "luci.model.uci".cursor()
  4. local dsp = require "luci.dispatcher"
  5. local utl = require "luci.util"
  6. local widget = uci:get("freifunk-widgets", arg[1], "template")
  7. local title = uci:get("freifunk-widgets", arg[1], "title") or ""
  8. m = Map("freifunk-widgets", translate("Widget"))
  9. m.redirect = luci.dispatcher.build_url("admin/freifunk/widgets")
  10. if not arg[1] or m.uci:get("freifunk-widgets", arg[1]) ~= "widget" then
  11. luci.http.redirect(m.redirect)
  12. return
  13. end
  14. wdg = m:section(NamedSection, arg[1], "widget", translate("Widget") .. " " .. title)
  15. wdg.anonymous = true
  16. wdg.addremove = false
  17. local en = wdg:option(Flag, "enabled", translate("Enable"))
  18. en.rmempty = false
  19. local title = wdg:option(Value, "title", translate("Title"))
  20. title.rmempty = true
  21. local form = loadfile(
  22. utl.libpath() .. "/model/cbi/freifunk/widgets/%s.lua" % widget
  23. )
  24. if form then
  25. setfenv(form, getfenv(1))(m, wdg)
  26. end
  27. return m