rails_admin_place_field 0.0.8 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06dca4f89f425f0fa4e0709b5c73e9420d315677
|
4
|
+
data.tar.gz: e1eb546f328754a779666c14be2cacdaec126b5b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3cfe6dfa1e9dad56a863ebaf6cfb10bbe0b2dfa8bf9ce3fd4d78492eba01ed5a24dc770305e76a3384df7e93b4f17973eda052ff0d90103656afed6596bbaeb
|
7
|
+
data.tar.gz: 52aee01597c3f43d01c58d183aea35959d2ae3f2f5eb92460e1542ba1c56338c1ad1f81fe309ced6c6be8d61fbb8b30bea6ab772212da054e9f2e160c30dcb99
|
data/README.md
CHANGED
@@ -48,6 +48,8 @@ RailsAdmin.config do |config|
|
|
48
48
|
edit do
|
49
49
|
field :latitude, :place do
|
50
50
|
longitude_field :longitude
|
51
|
+
foursquare_field :foursquare
|
52
|
+
gplace_field :gplace
|
51
53
|
google_api_key "a1b2c3d4e5f6deadbeef"
|
52
54
|
places_api_key "a1b2c3d4e5f6deadbeef"
|
53
55
|
foursquare_api_key "a1b2c3d4e5f6deadbeef"
|
@@ -1,23 +1,38 @@
|
|
1
|
-
= javascript_include_tag ("//maps.googleapis.com/maps/api/js?key=#{field.google_api_key}&sensor=false&callback=init_map_field")
|
1
|
+
= javascript_include_tag ("//maps.googleapis.com/maps/api/js?key=#{field.google_api_key}&sensor=false&libraries=places&callback=init_map_field")
|
2
2
|
|
3
3
|
= javascript_tag do
|
4
4
|
:plain
|
5
5
|
function init_map_field()
|
6
6
|
{
|
7
7
|
jQuery(function() {
|
8
|
+
|
8
9
|
var marker = null;
|
9
10
|
var latlng = new google.maps.LatLng(
|
10
11
|
#{form.object.send(field.name) || field.default_latitude},
|
11
12
|
#{form.object.send(field.longitude_field) || field.default_longitude}
|
12
13
|
);
|
13
14
|
|
14
|
-
var
|
15
|
+
var map_options = {
|
15
16
|
zoom: #{field.default_zoom_level},
|
16
17
|
center: latlng,
|
17
18
|
mapTypeId: google.maps.MapTypeId.ROADMAP
|
18
19
|
};
|
19
20
|
|
20
|
-
var map = new google.maps.Map(document.getElementById("#{field.dom_name}"),
|
21
|
+
var map = new google.maps.Map(document.getElementById("#{field.dom_name}"), map_options);
|
22
|
+
|
23
|
+
// Try HTML5 geolocation
|
24
|
+
if ( navigator.geolocation )
|
25
|
+
{
|
26
|
+
navigator.geolocation.getCurrentPosition(
|
27
|
+
function(position) {
|
28
|
+
var pos = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
|
29
|
+
map.setCenter(pos);
|
30
|
+
},
|
31
|
+
function() {
|
32
|
+
handleNoGeolocation(true);
|
33
|
+
}
|
34
|
+
);
|
35
|
+
}
|
21
36
|
|
22
37
|
- if form.object.send(field.name) && form.object.send(field.longitude_field)
|
23
38
|
:plain
|
@@ -30,6 +45,9 @@
|
|
30
45
|
google.maps.event.addListener(map, 'click', function(e) {
|
31
46
|
map_update(e.latLng);
|
32
47
|
foursquare_search(e.latLng.lat() + ',' + e.latLng.lng());
|
48
|
+
places_search(e.latLng);
|
49
|
+
|
50
|
+
$('#foursquare_options #foursquare_venue').html('<select id="foursquare_venue_select"><option></option></select>');
|
33
51
|
});
|
34
52
|
|
35
53
|
function map_update(location)
|
@@ -64,7 +82,7 @@
|
|
64
82
|
if ( response && response.meta.code == 200 )
|
65
83
|
{
|
66
84
|
response.response.venues.forEach(function(venue) {
|
67
|
-
jQuery('#
|
85
|
+
jQuery('#foursquare_venue_select').append('<option value="'+venue.id+'">'+venue.name+'</option>').change(function() {
|
68
86
|
jQuery("##{field.foursquare_dom_name}").val($(this).val());
|
69
87
|
});
|
70
88
|
});
|
@@ -76,13 +94,73 @@
|
|
76
94
|
});
|
77
95
|
}
|
78
96
|
|
97
|
+
// @todo : make this add a new marker so that the user knows that both the original geo + the places geo are recorded
|
98
|
+
function places_search(location)
|
99
|
+
{
|
100
|
+
autocomplete = new google.maps.places.Autocomplete(
|
101
|
+
document.getElementById('google_place_input'),
|
102
|
+
{
|
103
|
+
bounds: new google.maps.Circle({center: location, radius: 100}).getBounds()
|
104
|
+
}
|
105
|
+
);
|
106
|
+
|
107
|
+
google.maps.event.addListener(autocomplete, 'place_changed', function() {
|
108
|
+
var place = autocomplete.getPlace();
|
109
|
+
|
110
|
+
console.log(place.id);
|
111
|
+
|
112
|
+
$("##{field.gplace_dom_name}").val(place.id);
|
113
|
+
|
114
|
+
if ( ! place.geometry )
|
115
|
+
{
|
116
|
+
alert('A place was not found');
|
117
|
+
return;
|
118
|
+
}
|
119
|
+
|
120
|
+
// If the place has a geometry, then present it on a map.
|
121
|
+
if ( place.geometry.viewport )
|
122
|
+
{
|
123
|
+
// Use the viewport if it is provided.
|
124
|
+
map.fitBounds(place.geometry.viewport);
|
125
|
+
}
|
126
|
+
else {
|
127
|
+
// Otherwise use the location and set a chosen zoom level.
|
128
|
+
map.setCenter(place.geometry.location);
|
129
|
+
map.setZoom(17);
|
130
|
+
}
|
131
|
+
var image = {
|
132
|
+
url: place.icon,
|
133
|
+
size: new google.maps.Size(71, 71),
|
134
|
+
origin: new google.maps.Point(0, 0),
|
135
|
+
anchor: new google.maps.Point(17, 34),
|
136
|
+
scaledSize: new google.maps.Size(25, 25)
|
137
|
+
};
|
138
|
+
marker.setIcon(image);
|
139
|
+
marker.setPosition(place.geometry.location);
|
140
|
+
});
|
141
|
+
}
|
142
|
+
|
79
143
|
})};
|
80
144
|
|
81
145
|
|
82
|
-
%
|
83
|
-
%select
|
84
|
-
|
146
|
+
%h3 Geo Location Data
|
147
|
+
%p Click on the map to select a geo location. Once you've selected this, the foursquare and google places boxes will become active (if you've set them up correctly), for you to choose a relevant association.
|
148
|
+
%div.ramf-map-container{:id => field.dom_name, :style => "width:90%; height:300px"}
|
149
|
+
|
150
|
+
%hr
|
151
|
+
|
152
|
+
#places_options
|
153
|
+
%h4 Google Place
|
154
|
+
%input#google_place_input{ :type => 'text', :style => "width: 90%;" }
|
155
|
+
|
156
|
+
%hr
|
157
|
+
|
158
|
+
#foursquare_options
|
159
|
+
%h4 Foursquare Venue
|
160
|
+
#foursquare_venue You have to select a place on the map to retrieve a list of nearby results
|
161
|
+
%br
|
85
162
|
|
86
|
-
= form.send :hidden_field, field.foursquare_field, :id => field.foursquare_dom_name
|
87
163
|
= form.send :hidden_field, field.name, :id => field.latitude_dom_name
|
88
|
-
= form.send :hidden_field, field.longitude_field, :id => field.longitude_dom_name
|
164
|
+
= form.send :hidden_field, field.longitude_field, :id => field.longitude_dom_name
|
165
|
+
= form.send :hidden_field, field.foursquare_field, :id => field.foursquare_dom_name
|
166
|
+
= form.send :hidden_field, field.gplace_field, :id => field.gplace_dom_name
|
@@ -4,7 +4,7 @@ module RailsAdmin::Config::Fields::Types
|
|
4
4
|
RailsAdmin::Config::Fields::Types::register(:place, self)
|
5
5
|
|
6
6
|
def allowed_methods
|
7
|
-
[@name, longitude_field, foursquare_field]
|
7
|
+
[@name, longitude_field, foursquare_field, gplace_field]
|
8
8
|
end
|
9
9
|
|
10
10
|
# THe name of the corresponding longitude field to match the latitude field
|
@@ -17,6 +17,10 @@ module RailsAdmin::Config::Fields::Types
|
|
17
17
|
:foursquare
|
18
18
|
end
|
19
19
|
|
20
|
+
register_instance_option(:gplace_field) do
|
21
|
+
:gplace
|
22
|
+
end
|
23
|
+
|
20
24
|
register_instance_option(:partial) do
|
21
25
|
:place_select
|
22
26
|
end
|
@@ -25,10 +29,6 @@ module RailsAdmin::Config::Fields::Types
|
|
25
29
|
nil
|
26
30
|
end
|
27
31
|
|
28
|
-
register_instance_option(:places_api_key) do
|
29
|
-
nil
|
30
|
-
end
|
31
|
-
|
32
32
|
register_instance_option(:foursquare_api_key) do
|
33
33
|
nil
|
34
34
|
end
|
@@ -68,5 +68,9 @@ module RailsAdmin::Config::Fields::Types
|
|
68
68
|
def foursquare_dom_name
|
69
69
|
@foursquare_dom_name ||= "#{bindings[:form].object_name}_#{foursquare_field}"
|
70
70
|
end
|
71
|
+
|
72
|
+
def gplace_dom_name
|
73
|
+
@gplace_dom_name ||= "#{bindings[:form].object_name}_#{gplace_field}"
|
74
|
+
end
|
71
75
|
end
|
72
76
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_admin_place_field
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Clay McIlrath
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-09-
|
11
|
+
date: 2013-09-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec-rails
|
@@ -52,8 +52,8 @@ dependencies:
|
|
52
52
|
- - '>'
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 0.0.1
|
55
|
-
description: A place field for RailsAdmin that can be used to retrieve
|
56
|
-
or foursquare venue
|
55
|
+
description: A place field for RailsAdmin that can be used to retrieve and associate
|
56
|
+
a google place or foursquare venue
|
57
57
|
email:
|
58
58
|
- clay.mcilrath@gmail.com
|
59
59
|
executables: []
|