Globally reduce copyright headers
[project/luci.git] / applications / luci-app-freifunk-widgets / luasrc / model / cbi / freifunk / widgets / widgets_overview.lua
1 -- Copyright 2012 Manuel Munz <freifunk at somakoma dot de>
2 -- Licensed to the public under the Apache License 2.0.
3
4 local uci = require "luci.model.uci".cursor()
5 local fs = require "nixio.fs"
6 local utl = require "luci.util"
7 m = Map("freifunk-widgets", translate("Widgets"),
8         translate("Configure installed widgets."))
9
10 wdg = m:section(TypedSection, "widget", translate("Widgets"))
11 wdg.addremove = true
12 wdg.extedit   = luci.dispatcher.build_url("admin/freifunk/widgets/widget/%s")
13 wdg.template  = "cbi/tblsection"
14 wdg.sortable  = true
15
16 --[[
17 function wdg.create(...)
18         local sid = TypedSection.create(...)
19         luci.http.redirect(wdg.extedit % sid)
20 end
21 ]]--
22
23 local en = wdg:option(Flag, "enabled", translate("Enable"))
24 en.rmempty = false
25 --en.default = "0"
26 function en.cfgvalue(self, section)
27         return Flag.cfgvalue(self, section) or "0"
28 end
29
30 local tmpl = wdg:option(ListValue, "template", translate("Template"))
31 local file
32 for file in fs.dir("/usr/lib/lua/luci/view/freifunk/widgets/") do
33         if file ~= "." and file ~= ".." then
34                 tmpl:value(file)
35         end
36 end
37
38 local title = wdg:option(Value, "title", translate("Title"))
39 title.rmempty = true
40
41 local width = wdg:option(Value, "width", translate("Width"))
42 width.rmempty = true
43
44 local height = wdg:option(Value, "height", translate("Height"))
45 height.rmempty = true
46
47 local pr = wdg:option(Value, "paddingright", translate("Padding right"))
48 pr.rmempty = true
49
50 function m.on_commit(self)
51         -- clean custom text files whose config has been deleted
52         local dir = "/usr/share/customtext/"
53         local active = {}
54         uci:foreach("freifunk-widgets", "widget", function(s)
55                 if s["template"] == "html" then
56                         table.insert(active, s[".name"])
57                 end
58         end )
59         local file
60         for file in fs.dir(dir) do
61                 local filename = string.gsub(file, ".html", "")
62                 if not utl.contains(active, filename) then
63                         fs.unlink(dir .. file)
64                 end
65         end
66 end
67
68 return m