Add support for Google Maps API keys since they're required now. Closes #64

This commit is contained in:
Eric Schultz 2018-06-06 12:44:52 -05:00
parent 867fe73f05
commit 065e1582c2
5 changed files with 23 additions and 3 deletions

View file

@ -19,6 +19,7 @@ var app = {
, autocomplete: <%= @nonprofit ? @nonprofit.autocomplete_supporter_address : 'undefined'%>
, facebook_app_id: "<%= ENV['FACEBOOK_APP_ID'] %>"
, map_provider: "<%= Settings.maps&.provider %>"
, map_provider_options: <%= Settings.maps&.options ? raw(Settings.maps.options.to_json) : {} %>
, editor: "<%= Settings.page_editor.editor%>"
<% if Settings&.page_editor&.editor == 'froala' and Settings&.page_editor&.editor_options&.froala_key %>, froala_key: "<%= Settings.page_editor.editor_options.froala_key %>"<% end %>
};

View file

@ -10,7 +10,17 @@
</div>
<% elsif Format::Address.full_address(@nonprofit.address, @nonprofit.city, @nonprofit.state_code) %>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&libraries=places"></script>
<script>
var script = document.createElement('script')
script.type = 'text/javascript'
script.id = 'google_maps'
let key = ""
if (app.map_provider_options && app.map_provider_options.key) {
key = `api_key=${app.map_provider_options.key}&`
}
script.src = `https://maps.googleapis.com/maps/api/js?${key}v=3.exp&sensor=false&libraries=places`
document.body.appendChild(script)
</script>
<% npo_full_address = Format::Address.full_address(@nonprofit.address, @nonprofit.city, @nonprofit.state_code, @nonprofit.zip_code) %>
<div class='overview-map' id='js-map' data-address='<%= npo_full_address %>'>

View file

@ -49,7 +49,7 @@
<td>
<p><%= @event.address %></p>
<p><%= @event.city %>, <%= @event.state_code %> <%= @event.zip_code %></p>
<p><a href='http://maps.google.com/?q=<%= Format::Address.full_address(@event.address, @event.city, @event.state_code) %>'>Map link</a></p>
<p><a href='https://maps.google.com/?q=<%= Format::Address.full_address(@event.address, @event.city, @event.state_code) %>'>Map link</a></p>
</td>
</tr>
<% if !@event.directions.blank? %>

View file

@ -19,7 +19,11 @@ cc_map.init = function(endpoint, options_obj, query) {
var script = document.createElement('script')
script.type = 'text/javascript'
script.id = 'google_maps'
script.src = 'https://maps.googleapis.com/maps/api/js?sensor=false&callback=draw_map'
let key = ""
if (app.map_provider_options && app.map_provider_options.key) {
key = `api_key=${app.map_provider_options.key}&`
}
script.src = `https://maps.googleapis.com/maps/api/js?${key}sensor=false&callback=draw_map`
document.body.appendChild(script)
set_extra_options(options_obj)
} else {

View file

@ -120,6 +120,11 @@ Config.schema do
# the map provider to use. Currently that's just Google Maps or nothing
# Default is nil
optional(:provider).value(included_in?:['google', nil])
optional(:options).schema do
#key for your google maps instance
optional(:key).filled(:str?)
end
end
required(:page_editor).schema do