Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Usage
rails_admin_map_field expects that the model will have two attributes, one for latitude and one for longitude of the point represented. To enable rails_admin_map_field, add the following to your `Gemfile`:

```ruby
gem "rails_admin_map_field", :git => "git://github.com/jasonl/rails_admin_map_field.git"
gem "rails_admin_map_field", :git => "git://github.com/beyondthestory/rails_admin_map_field.git"
```

Then, add in your `config/initializers/rails_admin.rb` initializer:
Expand Down
27 changes: 22 additions & 5 deletions app/views/rails_admin/main/_form_map.html.haml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
= javascript_include_tag ("http://maps.googleapis.com/maps/api/js?key=#{field.google_api_key}&sensor=false&callback=init_map_field")

= javascript_tag do
:plain
function init_map_field(){
Expand Down Expand Up @@ -27,6 +25,22 @@
updateLocation(e.latLng);
});

jQuery(document).on("keyup", "##{field.latitude_dom_name}", function(e){
var value = $(this).val();
if (value.endsWith(".")) { value += "0"; }

var latlng = new google.maps.LatLng(value, jQuery("##{field.longitude_dom_name}").val());
updateLocation(latlng)
});

jQuery(document).on("keyup", "##{field.longitude_dom_name}", function(e){
var value = $(this).val();
if (value.endsWith(".")) { value += "0"; }

var latlng = new google.maps.LatLng(jQuery("##{field.latitude_dom_name}").val(), value);
updateLocation(latlng)
});

function updateLocation(location) {
if(marker) {
marker.setPosition(location);
Expand All @@ -43,6 +57,9 @@
}

})};
%div.ramf-map-container{:id => field.dom_name, :style => "width:300px;height:200px"}
= form.send :hidden_field, field.name, :id => field.latitude_dom_name
= form.send :hidden_field, field.longitude_field, :id => field.longitude_dom_name

= javascript_include_tag ("https://maps.googleapis.com/maps/api/js?key=#{field.google_api_key}&callback=init_map_field")

%div.ramf-map-container{:id => field.dom_name, :style => "width:100%;height:450px"}
= form.send :text_field, field.name, :id => field.latitude_dom_name
= form.send :text_field, field.longitude_field, :id => field.longitude_dom_name
2 changes: 1 addition & 1 deletion gem.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Gem::Specification.new do |s|


s.name = "rails_admin_map_field"
s.version = "0.0.1"
s.version = "0.0.3"
s.platform = Gem::Platform::RUBY
s.authors = ["Jason Langenauer"]
s.email = ["[email protected]"]
Expand Down