widgets_overview.lua 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 fs = require "nixio.fs"
  5. local utl = require "luci.util"
  6. m = Map("freifunk-widgets", translate("Widgets"),
  7. translate("Configure installed widgets."))
  8. wdg = m:section(TypedSection, "widget", translate("Widgets"))
  9. wdg.addremove = true
  10. wdg.extedit = luci.dispatcher.build_url("admin/freifunk/widgets/widget/%s")
  11. wdg.template = "cbi/tblsection"
  12. wdg.sortable = true
  13. --[[
  14. function wdg.create(...)
  15. local sid = TypedSection.create(...)
  16. luci.http.redirect(wdg.extedit % sid)
  17. end
  18. ]]--
  19. local en = wdg:option(Flag, "enabled", translate("Enable"))
  20. en.rmempty = false
  21. --en.default = "0"
  22. function en.cfgvalue(self, section)
  23. return Flag.cfgvalue(self, section) or "0"
  24. end
  25. local tmpl = wdg:option(ListValue, "template", translate("Template"))
  26. local file
  27. for file in fs.dir("/usr/lib/lua/luci/view/freifunk/widgets/") do
  28. if file ~= "." and file ~= ".." then
  29. tmpl:value(file)
  30. end
  31. end
  32. local title = wdg:option(Value, "title", translate("Title"))
  33. title.rmempty = true
  34. local width = wdg:option(Value, "width", translate("Width"))
  35. width.rmempty = true
  36. local height = wdg:option(Value, "height", translate("Height"))
  37. height.rmempty = true
  38. local pr = wdg:option(Value, "paddingright", translate("Padding right"))
  39. pr.rmempty = true
  40. function m.on_commit(self)
  41. -- clean custom text files whose config has been deleted
  42. local dir = "/usr/share/customtext/"
  43. local active = {}
  44. uci:foreach("freifunk-widgets", "widget", function(s)
  45. if s["template"] == "html" then
  46. table.insert(active, s[".name"])
  47. end
  48. end )
  49. local file
  50. for file in fs.dir(dir) do
  51. local filename = string.gsub(file, ".html", "")
  52. if not utl.contains(active, filename) then
  53. fs.unlink(dir .. file)
  54. end
  55. end
  56. end
  57. return m