Merge pull request #1818 from dibdot/lxc_fix
[project/luci.git] / applications / luci-app-freifunk-widgets / luasrc / model / cbi / freifunk / widgets / widget.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 dsp = require "luci.dispatcher"
6 local utl = require "luci.util"
7 local widget = uci:get("freifunk-widgets", arg[1], "template")
8 local title = uci:get("freifunk-widgets", arg[1], "title") or ""
9
10 m = Map("freifunk-widgets", translate("Widget"))
11 m.redirect = luci.dispatcher.build_url("admin/freifunk/widgets")
12
13 if not arg[1] or m.uci:get("freifunk-widgets", arg[1]) ~= "widget" then
14         luci.http.redirect(m.redirect)
15         return
16 end
17
18 wdg = m:section(NamedSection, arg[1], "widget", translate("Widget") .. " " .. title)
19 wdg.anonymous = true
20 wdg.addremove = false
21
22 local en = wdg:option(Flag, "enabled", translate("Enable"))
23 en.rmempty = false
24
25 local title = wdg:option(Value, "title", translate("Title"))
26 title.rmempty = true
27
28 local form = loadfile(
29         utl.libpath() .. "/model/cbi/freifunk/widgets/%s.lua" % widget
30 )
31
32 if form then
33         setfenv(form, getfenv(1))(m, wdg)
34 end
35
36 return m
37