applications/freifunk-widgets: Add missing Makefile
[project/luci.git] / applications / luci-freifunk-widgets / luasrc / model / cbi / freifunk / widgets / widget.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2012 Manuel Munz <freifunk at somakoma dot de>
5
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
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 ]]--
13
14
15 local uci = require "luci.model.uci".cursor()
16 local dsp = require "luci.dispatcher"
17 local utl = require "luci.util"
18 local widget = uci:get("freifunk-widgets", arg[1], "template")
19 local title = uci:get("freifunk-widgets", arg[1], "title") or ""
20
21 m = Map("freifunk-widgets", translate("Widget"))
22 m.redirect = luci.dispatcher.build_url("admin/freifunk/widgets")
23
24 if not arg[1] or m.uci:get("freifunk-widgets", arg[1]) ~= "widget" then
25 luci.http.redirect(m.redirect)
26 return
27 end
28
29 wdg = m:section(NamedSection, arg[1], "widget", translate("Widget") .. " " .. title)
30 wdg.anonymous = true
31 wdg.addremove = false
32
33 local en = wdg:option(Flag, "enabled", translate("Enable"))
34 en.rmempty = false
35
36 local title = wdg:option(Value, "title", translate("Title"))
37 title.rmempty = true
38
39 local order = wdg:option(Value, "order", translate("Order"))
40 order.default = "100"
41 order.placeholder = "100"
42 order.datatype = "integer"
43
44
45 local form = loadfile(
46 utl.libpath() .. "/model/cbi/freifunk/widgets/%s.lua" % widget
47 )
48
49 if form then
50 setfenv(form, getfenv(1))(m, wdg)
51 end
52 return m
53