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"))
47 --title.rmempty = true
50 local order = wdg:option(Value, "order", translate("Order"))
52 order.placeholder = "100"
53 order.datatype = "integer"
55 local width = wdg:option(Value, "width", translate("Width"))
56 --width.rmempty = true
58 local height = wdg:option(Value, "height", translate("Height"))
59 --height.rmempty = true
61 local pr = wdg:option(Value, "paddingright", translate("Padding right"))
64 function m.on_commit(self)
65 -- clean custom text files for elements which may have been deleted
66 local dir = "/usr/share/customtext/"
68 uci:foreach("freifunk-widgets", "widget", function(s)
69 if s["template"] == "html" then
70 table.insert(active, s[".name"])
73 for k, v in ipairs(fs.dir(dir)) do
74 filename = string.gsub(v, ".html", "")
75 if not utl.contains(active, filename) then