activeadmin_latlng 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -5
- data/lib/activeadmin/views/activeadmin_form.rb +69 -6
- data/lib/activeadmin_latlng/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 752cb8ab7b12852967a633c1d158f4378115c6a2
|
4
|
+
data.tar.gz: 1658d4a68d4156ff3b2c00f4d1353a7d8313a01d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a85d7ecda364672bf201f328a2b656f16c31ca19ed4a7bb4f4acfd92ada2b96cdd1d94e56dd1c6cf59f2821197e3067b530abe0e53103bd551ebd1a6a8a4b0dd
|
7
|
+
data.tar.gz: 1a8fbc6b2a40b70d3be9c2a1004a56c0b3a3489a28435790ffe7bc892ba67aa796693773eacb1251492096d994fc00d0f4d91952d1306568dbd2a9143f82d597
|
data/README.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
|
+
# ActiveadminLatlng
|
2
|
+
|
1
3
|
Active Admin latitude and longitude plugin
|
2
4
|
|
5
|
+
![alt tag](https://raw.githubusercontent.com/forsaken1/activeadmin-latlng/master/aa_latlng.png)
|
6
|
+
|
3
7
|
|
4
8
|
|
5
9
|
## Getting started
|
@@ -23,13 +27,15 @@ end
|
|
23
27
|
|
24
28
|
## Settings
|
25
29
|
|
26
|
-
* `lang` - language, `
|
30
|
+
* `lang` - language, `en` by default.
|
31
|
+
|
32
|
+
* `map` - map provider, `google` by default. Available: `google`, `yandex`.
|
27
33
|
|
28
|
-
* `
|
34
|
+
* `id_lat` and `id_lng` - identificator of latitude and longitude inputs. `<model_name>_lat` and `<model_name>_lng` by default.
|
29
35
|
|
30
|
-
* `
|
36
|
+
* `height` - map height in pixels, `400` by default.
|
31
37
|
|
32
|
-
* `
|
38
|
+
* `loading_map` - loading map library. `true` by default. Set to `false`, if map loaded in other place.
|
33
39
|
|
34
40
|
|
35
41
|
|
@@ -39,4 +45,4 @@ Alexey Krylov
|
|
39
45
|
|
40
46
|
## License
|
41
47
|
|
42
|
-
MIT License. Copyright 2016 Alexey Krylov
|
48
|
+
MIT License. Copyright 2016 Alexey Krylov
|
@@ -3,27 +3,90 @@ module ActiveAdmin
|
|
3
3
|
class ActiveAdminForm
|
4
4
|
def latlng **args
|
5
5
|
class_name = form_builder.object.class.model_name.element
|
6
|
-
lang
|
7
|
-
map
|
6
|
+
lang = args[:lang] || 'en'
|
7
|
+
map = args[:map] || :google
|
8
8
|
id_lat = args[:id_lat] || "#{class_name}_lat"
|
9
9
|
id_lng = args[:id_lng] || "#{class_name}_lng"
|
10
10
|
height = args[:height] || 400
|
11
|
+
loading_map = args[:loading_map].nil? ? true : args[:loading_map]
|
11
12
|
|
12
13
|
case map
|
13
14
|
when :yandex
|
14
|
-
insert_tag(YandexMapProxy, form_builder, lang, id_lat, id_lng, height)
|
15
|
+
insert_tag(YandexMapProxy, form_builder, lang, id_lat, id_lng, height, loading_map)
|
16
|
+
when :google
|
17
|
+
insert_tag(GoogleMapProxy, form_builder, lang, id_lat, id_lng, height, loading_map)
|
18
|
+
else
|
19
|
+
insert_tag(GoogleMapProxy, form_builder, lang, id_lat, id_lng, height, loading_map)
|
15
20
|
end
|
16
21
|
end
|
17
22
|
end
|
18
23
|
|
19
|
-
class
|
24
|
+
class LatlngProxy < FormtasticProxy
|
20
25
|
def build(form_builder, *args, &block)
|
21
|
-
@lang, @id_lat, @id_lng, @height = *args
|
26
|
+
@lang, @id_lat, @id_lng, @height, @loading_map = *args
|
22
27
|
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class GoogleMapProxy < LatlngProxy
|
31
|
+
def to_s
|
32
|
+
loading_map_code = @loading_map ? "<script src=\"https://maps.googleapis.com/maps/api/js?language=#{@lang}&callback=googleMapObject.init\" async defer></script>" : ''
|
33
|
+
"<li>" \
|
34
|
+
"#{loading_map_code}" \
|
35
|
+
"<div id=\"google_map\" style=\"height: #{@height}px\"></div>" \
|
36
|
+
"<script>
|
37
|
+
var googleMapObject = {
|
38
|
+
coords: null,
|
39
|
+
map: null,
|
40
|
+
marker: null,
|
41
|
+
|
42
|
+
getCoordinates: function() {
|
43
|
+
return {
|
44
|
+
lat: parseFloat($(\"##{@id_lat}\").val()) || 55.7522200,
|
45
|
+
lng: parseFloat($(\"##{@id_lng}\").val()) || 37.6155600,
|
46
|
+
};
|
47
|
+
},
|
48
|
+
|
49
|
+
saveCoordinates: function() {
|
50
|
+
$(\"##{@id_lat}\").val( googleMapObject.coords.lat.toFixed(10) );
|
51
|
+
$(\"##{@id_lng}\").val( googleMapObject.coords.lng.toFixed(10) );
|
52
|
+
},
|
53
|
+
|
54
|
+
init: function() {
|
55
|
+
googleMapObject.coords = googleMapObject.getCoordinates();
|
56
|
+
googleMapObject.saveCoordinates();
|
57
|
+
|
58
|
+
googleMapObject.map = new google.maps.Map(document.getElementById('google_map'), {
|
59
|
+
center: googleMapObject.coords,
|
60
|
+
zoom: 12
|
61
|
+
});
|
62
|
+
|
63
|
+
var latLngCoord = new google.maps.LatLng(googleMapObject.coords.lat, googleMapObject.coords.lng);
|
64
|
+
googleMapObject.marker = new google.maps.Marker({
|
65
|
+
position: latLngCoord,
|
66
|
+
map: googleMapObject.map,
|
67
|
+
draggable: true
|
68
|
+
});
|
69
|
+
googleMapObject.map.addListener('click', function(e) {
|
70
|
+
googleMapObject.coords = { lat: e.latLng.lat(), lng: e.latLng.lng() };
|
71
|
+
googleMapObject.saveCoordinates();
|
72
|
+
googleMapObject.marker.setPosition(googleMapObject.coords);
|
73
|
+
});
|
74
|
+
googleMapObject.marker.addListener('drag', function(e) {
|
75
|
+
googleMapObject.coords = { lat: e.latLng.lat(), lng: e.latLng.lng() };
|
76
|
+
googleMapObject.saveCoordinates();
|
77
|
+
});
|
78
|
+
}
|
79
|
+
}
|
80
|
+
</script>" \
|
81
|
+
"</li>"
|
82
|
+
end
|
83
|
+
end
|
23
84
|
|
85
|
+
class YandexMapProxy < LatlngProxy
|
24
86
|
def to_s
|
87
|
+
loading_map_code = @loading_map ? "<script src=\"https://api-maps.yandex.ru/2.1/?lang=#{@lang}&load=Map,Placemark\" type=\"text/javascript\"></script>" : ''
|
25
88
|
"<li>" \
|
26
|
-
"
|
89
|
+
"#{loading_map_code}" \
|
27
90
|
"<div id=\"yandex_map\" style=\"height: #{@height}px\"></div>" \
|
28
91
|
"<script type=\"text/javascript\">
|
29
92
|
var yandexMapObject = {
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activeadmin_latlng
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexey Krylov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activeadmin
|