luci-mod-freifunk: switch to nixio.fs
[project/luci.git] / modules / luci-mod-freifunk / luasrc / model / cbi / freifunk / basics.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2008 Steven Barth <steven@midlink.org>
5 Copyright 2011 Manuel Munz <freifunk at somakoma de>
6
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
10
11         http://www.apache.org/licenses/LICENSE-2.0
12 ]]
13
14 local fs = require "nixio.fs"
15 local util = require "luci.util"
16 local uci = require "luci.model.uci".cursor()
17 local profiles = "/etc/config/profile_"
18
19 m = Map("freifunk", translate ("Community"))
20 c = m:section(NamedSection, "community", "public", nil, translate("These are the basic settings for your local wireless community. These settings define the default values for the wizard and DO NOT affect the actual configuration of the router."))
21
22 community = c:option(ListValue, "name", translate ("Community"))
23 community.rmempty = false
24
25 local profile
26 for profile in fs.dir(profiles) do
27         local name = uci:get_first(profile, "community", "name") or "?"
28         community:value(profile, name)
29 end
30
31
32 n = Map("system", translate("Basic system settings"))
33 function n.on_after_commit(self)
34         luci.http.redirect(luci.dispatcher.build_url("admin", "freifunk", "basics"))
35 end
36
37 b = n:section(TypedSection, "system")
38 b.anonymous = true
39
40 hn = b:option(Value, "hostname", translate("Hostname"))
41 hn.rmempty = false
42 hn.datatype = "hostname"
43
44 loc = b:option(Value, "location", translate("Location"))
45 loc.rmempty = false
46 loc.datatype = "minlength(1)"
47
48 lat = b:option(Value, "latitude", translate("Latitude"), translate("e.g.") .. " 48.12345")
49 lat.datatype = "float"
50 lat.rmempty = false
51
52 lon = b:option(Value, "longitude", translate("Longitude"), translate("e.g.") .. " 10.12345")
53 lon.datatype = "float"
54 lon.rmempty = false
55
56 --[[
57 Opens an OpenStreetMap iframe or popup
58 Makes use of resources/OSMLatLon.htm and htdocs/resources/osm.js
59 ]]--
60
61 local class = util.class
62 local ff = uci:get("freifunk", "community", "name") or ""
63 local co = "profile_" .. ff
64
65 local deflat = uci:get_first("system", "system", "latitude") or uci:get_first(co, "community", "latitude") or 52
66 local deflon = uci:get_first("system", "system", "longitude") or uci:get_first(co, "community", "longitude") or 10
67 local zoom = 12
68 if ( deflat == 52 and deflon == 10 ) then
69         zoom = 4
70 end
71
72 OpenStreetMapLonLat = luci.util.class(AbstractValue)
73     
74 function OpenStreetMapLonLat.__init__(self, ...)
75         AbstractValue.__init__(self, ...)
76         self.template = "cbi/osmll_value"
77         self.latfield = nil
78         self.lonfield = nil
79         self.centerlat = ""
80         self.centerlon = ""
81         self.zoom = "0"
82         self.width = "100%" --popups will ignore the %-symbol, "100%" is interpreted as "100"
83         self.height = "600"
84         self.popup = false
85         self.displaytext="OpenStreetMap" --text on button, that loads and displays the OSMap
86         self.hidetext="X" -- text on button, that hides OSMap
87 end
88
89         osm = b:option(OpenStreetMapLonLat, "latlon", translate("Find your coordinates with OpenStreetMap"), translate("Select your location with a mouse click on the map. The map will only show up if you are connected to the Internet."))
90         osm.latfield = "latitude"
91         osm.lonfield = "longitude"
92         osm.centerlat = uci:get_first("system", "system", "latitude") or deflat
93         osm.centerlon = uci:get_first("system", "system", "longitude") or deflon
94         osm.zoom = zoom
95         osm.width = "100%"
96         osm.height = "600"
97         osm.popup = false
98         osm.displaytext=translate("Show OpenStreetMap")
99         osm.hidetext=translate("Hide OpenStreetMap")
100
101 return m, n