2c22f7b49fb083b15cadc46d883c4fc336f4fad7
[project/luci.git] / modules / freifunk / luasrc / model / cbi / freifunk / basics.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2008 Steven Barth <steven@midlink.org>
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 local fs = require "luci.fs"
14 local util = require "luci.util"
15 local uci = require "luci.model.uci".cursor()
16 local profiles = "/etc/config/profile_"
17
18 m = Map("freifunk", translate ("Community"))
19 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."))
20
21 community = c:option(ListValue, "name", translate ("Community"))
22 community.rmempty = false
23
24 local list = { }
25 local list = fs.glob(profiles .. "*")
26
27 for k,v in ipairs(list) do
28         local name = uci:get_first(v, "community", "name") or "?"
29         local n = string.gsub(v, profiles, "")
30         community:value(n, name)
31 end
32
33 n = Map("system", translate("Basic system settings"))
34 b = n:section(TypedSection, "system")
35 b.anonymous = true
36
37 hn = b:option(Value, "hostname", translate("Hostname"))
38 hn.rmempty = false
39 hn.datatype = "hostname"
40
41 loc = b:option(Value, "location", translate("Location"))
42 loc.rmempty = false
43
44 lat = b:option(Value, "latitude", translate("Latitude"), translate("e.g.") .. " 48.12345")
45 lat.rmempty = false
46
47 lon = b:option(Value, "longitude", translate("Longitude"), translate("e.g.") .. " 10.12345")
48 lon.rmempty = false
49
50 --[[
51 Opens an OpenStreetMap iframe or popup
52 Makes use of resources/OSMLatLon.htm and htdocs/resources/osm.js
53 (is that the right place for files like these?)
54 ]]--
55
56 --[[ this needs to be fixed
57 local class = util.class
58 local co = "profile_augsburg"
59 local syslat = uci:get_first(co, "community", "latitude")
60 local syslon = uci:get_first(co, "community", "longitude")
61
62 OpenStreetMapLonLat = class(AbstractValue)
63
64 function OpenStreetMapLonLat.__init__(self, ...)
65         AbstractValue.__init__(self, ...)
66         self.template = "cbi/osmll_value"
67         self.latfield = nil
68         self.lonfield = nil
69         self.centerlat = ""
70         self.centerlon = ""
71         self.zoom = "0"
72         self.width = "100%" --popups will ignore the %-symbol, "100%" is interpreted as "100"
73         self.height = "600"
74         self.popup = false
75         self.displaytext="OpenStreetMap" --text on button, that loads and displays the OSMap
76         self.hidetext="X" -- text on button, that hides OSMap
77 end
78
79
80 f = SimpleForm("ffwizward", "OpenStreetMap", "Hier kann man die Geokoordinaten des Knotens herausfinden.")
81
82 osm = f:field(OpenStreetMapLonLat, "latlon", "Geokoordinaten mit OpenStreetMap ermitteln:", "Klicken Sie auf Ihren Standort in der Karte. Diese Karte funktioniert nur, wenn das Gerät bereits eine Verbindung zum Internet hat.")
83 osm.latfield = "lat"
84 osm.lonfield = "lon"
85 osm.centerlat = syslat
86 osm.centerlon = syslon
87 osm.width = "100%"
88 osm.height = "600"
89 osm.popup = false
90
91 syslatlengh = string.len(syslat)
92 if syslatlengh > 7 then
93         osm.zoom = "15"
94 elseif syslatlengh > 5 then
95         osm.zoom = "12"
96 else
97         osm.zoom = "6"
98 end
99
100 osm.displaytext="OpenStreetMap anzeigen"
101 osm.hidetext="OpenStreetMap verbergen"
102 ]]
103
104 return m, n