modules/freifunk: Add minlength datatype to location, #444
[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 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 "luci.fs"
15 local util = require "luci.util"
16 local uci = require "luci.model.uci".cursor()
17 local profiles = "/etc/config/profile_"
18 luci.i18n.loadc("freifunk")
19
20 m = Map("freifunk", translate ("Community"))
21 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."))
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
36 n = Map("system", translate("Basic system settings"))
37 function n.on_after_commit(self)
38 luci.http.redirect(luci.dispatcher.build_url("admin", "freifunk", "basics"))
39 end
40
41 b = n:section(TypedSection, "system")
42 b.anonymous = true
43
44 hn = b:option(Value, "hostname", translate("Hostname"))
45 hn.rmempty = false
46 hn.datatype = "hostname"
47
48 loc = b:option(Value, "location", translate("Location"))
49 loc.rmempty = false
50 loc.datatype = "minlength(1)"
51
52 lat = b:option(Value, "latitude", translate("Latitude"), translate("e.g.") .. " 48.12345")
53 lat.datatype = "float"
54 lat.rmempty = false
55
56 lon = b:option(Value, "longitude", translate("Longitude"), translate("e.g.") .. " 10.12345")
57 lon.datatype = "float"
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 ]]--
64
65 local class = util.class
66 local ff = uci:get("freifunk", "community", "name") or ""
67 local co = "profile_" .. ff
68
69 local deflat = uci:get_first("system", "system", "latitude") or uci:get_first(co, "community", "latitude") or 52
70 local deflon = uci:get_first("system", "system", "longitude") or uci:get_first(co, "community", "longitude") or 10
71 local zoom = 12
72 if ( deflat == 52 and deflon == 10 ) then
73 zoom = 4
74 end
75
76 OpenStreetMapLonLat = luci.util.class(AbstractValue)
77
78 function OpenStreetMapLonLat.__init__(self, ...)
79 AbstractValue.__init__(self, ...)
80 self.template = "cbi/osmll_value"
81 self.latfield = nil
82 self.lonfield = nil
83 self.centerlat = ""
84 self.centerlon = ""
85 self.zoom = "0"
86 self.width = "100%" --popups will ignore the %-symbol, "100%" is interpreted as "100"
87 self.height = "600"
88 self.popup = false
89 self.displaytext="OpenStreetMap" --text on button, that loads and displays the OSMap
90 self.hidetext="X" -- text on button, that hides OSMap
91 end
92
93 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."))
94 osm.latfield = "latitude"
95 osm.lonfield = "longitude"
96 osm.centerlat = uci:get_first("system", "system", "latitude") or deflat
97 osm.centerlon = uci:get_first("system", "system", "longitude") or deflon
98 osm.zoom = zoom
99 osm.width = "100%"
100 osm.height = "600"
101 osm.popup = false
102 osm.displaytext=translate("Show OpenStreetMap")
103 osm.hidetext=translate("Hide OpenStreetMap")
104
105 return m, n