2 LuCI - Lua Configuration Interface
4 Copyright 2012 Manuel Munz <freifunk at somakoma dot de>
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
13 local uci = require "luci.model.uci".cursor()
14 local fs = require "luci.fs"
15 local utl = require "luci.util"
16 m = Map("freifunk-widgets", translate("Widgets"),
17 translate("Configure installed widgets."))
19 wdg = m:section(TypedSection, "widget", translate("Widgets"))
21 wdg.extedit = luci.dispatcher.build_url("admin/freifunk/widgets/widget/%s")
22 wdg.template = "cbi/tblsection"
26 function wdg.create(...)
27 local sid = TypedSection.create(...)
28 luci.http.redirect(wdg.extedit % sid)
32 local en = wdg:option(Flag, "enabled", translate("Enable"))
35 function en.cfgvalue(self, section)
36 return Flag.cfgvalue(self, section) or "0"
39 local tmpl = wdg:option(ListValue, "template", translate("Template"))
40 for k, v in ipairs(fs.dir('/usr/lib/lua/luci/view/freifunk/widgets/')) do
41 if v ~= "." and v ~= ".." then
46 local title = wdg:option(Value, "title", translate("Title"))
49 local width = wdg:option(Value, "width", translate("Width"))
52 local height = wdg:option(Value, "height", translate("Height"))
55 local pr = wdg:option(Value, "paddingright", translate("Padding right"))
58 function m.on_commit(self)
59 -- clean custom text files whose config has been deleted
60 local dir = "/usr/share/customtext/"
62 uci:foreach("freifunk-widgets", "widget", function(s)
63 if s["template"] == "html" then
64 table.insert(active, s[".name"])
67 for k, v in ipairs(fs.dir(dir)) do
68 filename = string.gsub(v, ".html", "")
69 if not utl.contains(active, filename) then