1cd5c6d9c4aff90538e3f65bc9c382a34b2ef24f
[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 $Id: freifunk.lua 3291 2008-09-14 21:59:14Z Cyrus $
13 ]]--
14
15 local fs = require "luci.fs"
16 local util = require "luci.util"
17 local uci = require "luci.model.uci".cursor()
18 local profiles = "/etc/config/profile_"
19
20 m = Map("freifunk", "Freifunk")
21 c = m:section(NamedSection, "community", "public", "Gemeinschaft", [[Dies sind die Grundeinstellungen
22 für die lokale Freifunkgemeinschaft. Diese Werte wirken sich NICHT auf die Konfiguration
23 des Routers aus, sondern definieren nur die Vorgaben für den Freifunkassistenten.]])
24
25 community = c:option(ListValue, "name", "Gemeinschaft")
26 community.rmempty = false
27
28 local list = { }
29 local list = fs.glob(profiles .. "*")
30
31 for k,v in ipairs(list) do
32         local name = uci:get_first(v, "community", "name") or "?"
33         local n = string.gsub(v, profiles, "")
34         community:value(n, name)
35 end
36
37 n = Map("system", translate("Basic system settings"))
38 b = n:section(TypedSection, "system", "Basic system settings")
39 b.anonymous = true
40
41 hn = b:option(Value, "hostname", "hostname")
42 hn.rmempty = false
43 function hn.validate(self, value)
44         if value == nil then
45                 return
46         elseif (#value > 24) or string.match(value, "[^%w%.%-]") or string.match(value, "^[%-%.]") or string.match(value, "[%-%.]$") then
47                 return nil, translate("Hostname may contain up to 24 alphanumeric characters. Minus and period are also allowed, but not in the beginning or the end of the hostname.")
48         else
49                 return value
50         end
51 end
52
53 loc = b:option(Value, "location", "Location")
54 loc.rmempty = false
55
56 lat = b:option(Value, "latitude", "latitude")
57 lat.rmempty = false
58
59 lon = b:option(Value, "longitude", "longitude")
60 lon.rmempty = false
61
62 --[[
63 Opens an OpenStreetMap iframe or popup
64 Makes use of resources/OSMLatLon.htm and htdocs/resources/osm.js
65 (is that the right place for files like these?)
66 ]]--
67
68 local class = util.class
69 local co = "profile_augsburg"
70 local syslat = uci:get_first(co, "community", "latitude")
71 local syslon = uci:get_first(co, "community", "longitude")
72
73 OpenStreetMapLonLat = class(AbstractValue)
74
75 function OpenStreetMapLonLat.__init__(self, ...)
76         AbstractValue.__init__(self, ...)
77         self.template = "cbi/osmll_value"
78         self.latfield = nil
79         self.lonfield = nil
80         self.centerlat = ""
81         self.centerlon = ""
82         self.zoom = "0"
83         self.width = "100%" --popups will ignore the %-symbol, "100%" is interpreted as "100"
84         self.height = "600"
85         self.popup = false
86         self.displaytext="OpenStreetMap" --text on button, that loads and displays the OSMap
87         self.hidetext="X" -- text on button, that hides OSMap
88 end
89
90
91 f = SimpleForm("ffwizward", "OpenStreetMap", "Hier kann man die Geokoordinaten des Knotens herausfinden.")
92
93 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.")
94 osm.latfield = "lat"
95 osm.lonfield = "lon"
96 osm.centerlat = syslat
97 osm.centerlon = syslon
98 osm.width = "100%"
99 osm.height = "600"
100 osm.popup = false
101
102 syslatlengh = string.len(syslat)
103 if syslatlengh > 7 then
104         osm.zoom = "15"
105 elseif syslatlengh > 5 then
106         osm.zoom = "12"
107 else
108         osm.zoom = "6"
109 end
110
111 osm.displaytext="OpenStreetMap anzeigen"
112 osm.hidetext="OpenStreetMap verbergen"
113
114
115 return m, n