b08366de6c737c58d35dbd9bb867d959c1cc663b
[project/luci.git] / modules / luci-mod-freifunk / luasrc / model / cbi / freifunk / basics.lua
1 -- Copyright 2008 Steven Barth <steven@midlink.org>
2 -- Copyright 2011 Manuel Munz <freifunk at somakoma de>
3 -- Licensed to the public under the Apache License 2.0.
4
5 local fs = require "nixio.fs"
6 local util = require "luci.util"
7 local uci = require "luci.model.uci".cursor()
8 local profiles = "/etc/config/profile_*"
9
10 m = Map("freifunk", translate ("Community"))
11 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."))
12
13 community = c:option(ListValue, "name", translate ("Community"))
14 community.rmempty = false
15
16 local profile
17 for profile in fs.glob(profiles) do
18         local name = uci:get_first(profile, "community", "name") or "?"
19         community:value(string.gsub(profile, "/etc/config/profile_", ""), name)
20 end
21
22
23 n = Map("system", translate("Basic system settings"))
24 function n.on_after_commit(self)
25         luci.http.redirect(luci.dispatcher.build_url("admin", "freifunk", "basics"))
26 end
27
28 b = n:section(TypedSection, "system")
29 b.anonymous = true
30
31 hn = b:option(Value, "hostname", translate("Hostname"))
32 hn.rmempty = false
33 hn.datatype = "hostname"
34
35 loc = b:option(Value, "location", translate("Location"))
36 loc.rmempty = false
37 loc.datatype = "minlength(1)"
38
39 lat = b:option(Value, "latitude", translate("Latitude"), translate("e.g.") .. " 48.12345")
40 lat.datatype = "float"
41 lat.rmempty = false
42
43 lon = b:option(Value, "longitude", translate("Longitude"), translate("e.g.") .. " 10.12345")
44 lon.datatype = "float"
45 lon.rmempty = false
46
47 --[[
48 Opens an OpenStreetMap iframe or popup
49 Makes use of resources/OSMLatLon.htm and htdocs/resources/osm.js
50 ]]--
51
52 local class = util.class
53 local ff = uci:get("freifunk", "community", "name") or ""
54 local co = "profile_" .. ff
55
56 local deflat = uci:get_first("system", "system", "latitude") or uci:get_first(co, "community", "latitude") or 52
57 local deflon = uci:get_first("system", "system", "longitude") or uci:get_first(co, "community", "longitude") or 10
58 local zoom = 12
59 if ( deflat == 52 and deflon == 10 ) then
60         zoom = 4
61 end
62
63 OpenStreetMapLonLat = luci.util.class(AbstractValue)
64     
65 function OpenStreetMapLonLat.__init__(self, ...)
66         AbstractValue.__init__(self, ...)
67         self.template = "cbi/osmll_value"
68         self.latfield = nil
69         self.lonfield = nil
70         self.centerlat = ""
71         self.centerlon = ""
72         self.zoom = "0"
73         self.width = "100%" --popups will ignore the %-symbol, "100%" is interpreted as "100"
74         self.height = "600"
75         self.popup = false
76         self.displaytext="OpenStreetMap" --text on button, that loads and displays the OSMap
77         self.hidetext="X" -- text on button, that hides OSMap
78 end
79
80         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."))
81         osm.latfield = "latitude"
82         osm.lonfield = "longitude"
83         osm.centerlat = uci:get_first("system", "system", "latitude") or deflat
84         osm.centerlon = uci:get_first("system", "system", "longitude") or deflon
85         osm.zoom = zoom
86         osm.width = "100%"
87         osm.height = "600"
88         osm.popup = false
89         osm.displaytext=translate("Show OpenStreetMap")
90         osm.hidetext=translate("Hide OpenStreetMap")
91
92 return m, n