modules/freifunk: i18n
[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
20 settings for your local wireless community. These settings define the default values for the wizard
21 and DO NOT affect the actual configuration of the router.]]))
22
23 community = c:option(ListValue, "name", translate ("Community"))
24 community.rmempty = false
25
26 local list = { }
27 local list = fs.glob(profiles .. "*")
28
29 for k,v in ipairs(list) do
30         local name = uci:get_first(v, "community", "name") or "?"
31         local n = string.gsub(v, profiles, "")
32         community:value(n, name)
33 end
34
35 n = Map("system", translate("Basic system settings"))
36 b = n:section(TypedSection, "system")
37 b.anonymous = true
38
39 hn = b:option(Value, "hostname", "hostname")
40 hn.rmempty = false
41 function hn.validate(self, value)
42         if value == nil then
43                 return
44         elseif (#value > 24) or string.match(value, "[^%w%.%-]") or string.match(value, "^[%-%.]") or string.match(value, "[%-%.]$") then
45                 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.")
46         else
47                 return value
48         end
49 end
50
51 loc = b:option(Value, "location", "Location")
52 loc.rmempty = false
53
54 lat = b:option(Value, "latitude", "latitude")
55 lat.rmempty = false
56
57 lon = b:option(Value, "longitude", "longitude")
58 lon.rmempty = false
59
60 --[[
61 Opens an OpenStreetMap iframe or popup
62 Makes use of resources/OSMLatLon.htm and htdocs/resources/osm.js
63 (is that the right place for files like these?)
64 ]]--
65
66 local class = util.class
67 local co = "profile_augsburg"
68 local syslat = uci:get_first(co, "community", "latitude")
69 local syslon = uci:get_first(co, "community", "longitude")
70
71 OpenStreetMapLonLat = class(AbstractValue)
72
73 function OpenStreetMapLonLat.__init__(self, ...)
74         AbstractValue.__init__(self, ...)
75         self.template = "cbi/osmll_value"
76         self.latfield = nil
77         self.lonfield = nil
78         self.centerlat = ""
79         self.centerlon = ""
80         self.zoom = "0"
81         self.width = "100%" --popups will ignore the %-symbol, "100%" is interpreted as "100"
82         self.height = "600"
83         self.popup = false
84         self.displaytext="OpenStreetMap" --text on button, that loads and displays the OSMap
85         self.hidetext="X" -- text on button, that hides OSMap
86 end
87
88
89 f = SimpleForm("ffwizward", "OpenStreetMap", "Hier kann man die Geokoordinaten des Knotens herausfinden.")
90
91 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.")
92 osm.latfield = "lat"
93 osm.lonfield = "lon"
94 osm.centerlat = syslat
95 osm.centerlon = syslon
96 osm.width = "100%"
97 osm.height = "600"
98 osm.popup = false
99
100 syslatlengh = string.len(syslat)
101 if syslatlengh > 7 then
102         osm.zoom = "15"
103 elseif syslatlengh > 5 then
104         osm.zoom = "12"
105 else
106         osm.zoom = "6"
107 end
108
109 osm.displaytext="OpenStreetMap anzeigen"
110 osm.hidetext="OpenStreetMap verbergen"
111
112
113 return m, n