From: Jonathan Prykop Date: Sat, 24 Sep 2016 02:46:14 +0000 (-0500) Subject: 71873: GlobalVision - directions [better error handling] X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=ae14e320388fa5e7f400bff1c251ef885b7952e6 71873: GlobalVision - directions [better error handling] --- diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index 57761bb48..6bfbf983c 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -2071,7 +2071,7 @@ and customer address. Include units.', { 'key' => 'google_maps_api_key', 'section' => 'addresses', - 'description' => 'API key for google maps. This must be set for map and directions links to appear on customer pages. See Getting a Google Maps API Key', + 'description' => 'API key for google maps. This must be set for map and directions links to work. See Getting a Google Maps API Key', 'type' => 'text', }, diff --git a/httemplate/elements/coord-links.html b/httemplate/elements/coord-links.html index a755791ae..f27ffd39f 100644 --- a/httemplate/elements/coord-links.html +++ b/httemplate/elements/coord-links.html @@ -1,7 +1,5 @@ <& /elements/init_overlib.html &> -% if ( $apikey ) { - <& /elements/popup_link.html, 'action' => $p. 'view/map.html?'. $query, 'label' => mt('map'), @@ -21,8 +19,6 @@ &> % } -% } # end if $apikey - <% mt('earth') |h %> <%init> diff --git a/httemplate/elements/google_maps_api_key.html b/httemplate/elements/google_maps_api_key.html new file mode 100644 index 000000000..0a4b7646c --- /dev/null +++ b/httemplate/elements/google_maps_api_key.html @@ -0,0 +1,15 @@ +% if ($opt{'autherror'}) { +

+There was an authentication error when loading google maps. +Please check validity of existing key. +

+% } + +

In order to display google maps, your site administrator will need to set the +google_maps_api_key setting under Configuration -> Settings. Please see the Google Maps +Get +a Key/Authentication documentation for information on acquiring a key.

+ +<%init> +my %opt = @_; + diff --git a/httemplate/view/directions.html b/httemplate/view/directions.html index a07df403b..f23b7eb7f 100644 --- a/httemplate/view/directions.html +++ b/httemplate/view/directions.html @@ -1,3 +1,5 @@ +% if ( $apikey ) { + %# the actual page <& /elements/header-popup.html, { title => '',#$name, @@ -10,6 +12,11 @@
+% } else { +<& /elements/header-popup.html &> +<& /elements/google_maps_api_key.html &> +% } + <%def .head> % my $lat = $cgi->param('lat'); % my $lon = $cgi->param('lon'); @@ -38,8 +45,6 @@ body { height: 100%; margin: 0px; padding: 0px } } -% my $conf = new FS::Conf; -% my $apikey = $conf->config('google_maps_api_key'); @@ -69,6 +74,12 @@ function show_route() { }); } +// function name specified by google maps api, special hook for auth errors +function gm_authFailure () { + document.body.innerHTML = +<% include('/elements/google_maps_api_key.html', autherror => 1) |js_string%>; +} + function initialize() { var myOptions = { zoom: 14, @@ -88,6 +99,8 @@ function initialize() { <%shared> my ($lat, $lon, $name, $origin); +my $conf = new FS::Conf; +my $apikey = $conf->config('google_maps_api_key'); <%init> diff --git a/httemplate/view/map.html b/httemplate/view/map.html index d996a330c..b3459dc1f 100644 --- a/httemplate/view/map.html +++ b/httemplate/view/map.html @@ -1,3 +1,5 @@ +% if ( $apikey ) { + %# the actual page <& /elements/header-popup.html, { title => '',#$name, @@ -9,6 +11,11 @@
+% } else { +<& /elements/header-popup.html &> +<& /elements/google_maps_api_key.html &> +% } + <%def .head> @@ -22,8 +29,6 @@ body { height: 100%; margin: 0px; padding: 0px } @media print { #map_canvas { height: 500px; margin: 0; } } -% my $conf = new FS::Conf; -% my $apikey = $conf->config('google_maps_api_key'); @@ -31,6 +36,13 @@ body { height: 100%; margin: 0px; padding: 0px } var lengthLine=0; var map; +// function name specified by google maps api, special hook for auth errors +function gm_authFailure () { + document.body.innerHTML = +<% include('/elements/google_maps_api_key.html', autherror => 1) |js_string%>; +} + + function initialize() { var latlng = new google.maps.LatLng(<%$lat%>, <%$lon%>); var myOptions = { @@ -57,6 +69,8 @@ function initialize() { <%shared> my ($lat, $lon, $name); +my $conf = new FS::Conf; +my $apikey = $conf->config('google_maps_api_key'); <%init>