Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Save and display data on form submission
- Loading branch information
Showing
2 changed files
with
60 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,48 @@ | ||
= javascript_include_tag ("http://maps.googleapis.com/maps/api/js?key=#{field.google_api_key}&sensor=false") | ||
= #require_asset('ramf.js') | ||
|
||
:javascript | ||
jQuery(function(){ | ||
var latlng = new google.maps.LatLng( #{form.object.send(field.name) || field.default_latitude}, #{form.object.send(field.name) || field.default_longitude}); | ||
var myOptions = { | ||
zoom: 8, | ||
center: latlng, | ||
mapTypeId: google.maps.MapTypeId.ROADMAP | ||
}; | ||
var map = new google.maps.Map(document.getElementById("#{field.dom_name}"), myOptions); | ||
}); | ||
= javascript_tag do | ||
:plain | ||
jQuery(function(){ | ||
var marker = null; | ||
var latlng = new google.maps.LatLng(#{form.object.send(field.name) || field.default_latitude}, #{form.object.send(field.longitude_field) || field.default_longitude}); | ||
|
||
var myOptions = { | ||
zoom: 8, | ||
center: latlng, | ||
mapTypeId: google.maps.MapTypeId.ROADMAP | ||
}; | ||
|
||
var map = new google.maps.Map(document.getElementById("#{field.dom_name}"), myOptions); | ||
|
||
- if form.object.send(field.name) && form.object.send(field.longitude_field) | ||
:plain | ||
marker = new google.maps.Marker({ | ||
position: new google.maps.LatLng(#{form.object.send(field.name)},#{form.object.send(field.longitude_field)}), | ||
map: map | ||
}); | ||
|
||
:plain | ||
google.maps.event.addListener(map, 'click', function(e) { | ||
updateLocation(e.latLng); | ||
}); | ||
|
||
function updateLocation(location) { | ||
if(marker) { | ||
marker.setPosition(location); | ||
} else { | ||
marker = new google.maps.Marker({ | ||
position: location, | ||
map: map | ||
}); | ||
} | ||
|
||
map.setCenter(location); | ||
jQuery("##{field.latitude_dom_name}").val(location.lat()); | ||
jQuery("##{field.longitude_dom_name}").val(location.lng()); | ||
} | ||
|
||
}); | ||
%div.ramf-map-container{:id => field.dom_name, :style => "width:300px;height:200px"} | ||
= form.send :hidden_field, field.name | ||
= form.send :hidden_field, field.longitude_field | ||
= form.send :hidden_field, field.name, :id => field.latitude_dom_name | ||
= form.send :hidden_field, field.longitude_field, :id => field.longitude_dom_name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters