71873: GlobalVision - directions [better error handling]
[freeside.git] / httemplate / view / directions.html
index f14a11a..f23b7eb 100644 (file)
@@ -1,3 +1,5 @@
+% if ( $apikey ) {
+
 %# the actual page
 <& /elements/header-popup.html, {
      title => '',#$name,
 <div id="directions_panel"></div>
 <div id="map_canvas"></div>
 
+% } 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,7 @@ body { height: 100%; margin: 0px; padding: 0px }
 }
 </style>
 
-<script type="text/javascript" 
-src="https://maps.google.com/maps/api/js?v=3.4&sensor=false">
+<script type="text/javascript" src="https://maps.google.com/maps/api/js?v=3&key=<% $apikey %>">
 </script>
 
 <script type="text/javascript">
@@ -62,10 +68,18 @@ function show_route() {
   directionsService.route(directionsRequest, function(result, status) {
     if ( status == google.maps.DirectionsStatus.OK ) {
       directionsDisplay.setDirections(result);
+    } else { 
+      document.body.innerHTML = ('<P STYLE="color: red;">Directions lookup failed with the following error: '+status+'</P>');
     }
   });
 }
 
+// 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,
@@ -85,6 +99,8 @@ function initialize() {
 </%def>
 <%shared>
 my ($lat, $lon, $name, $origin);
+my $conf = new FS::Conf;
+my $apikey = $conf->config('google_maps_api_key');
 </%shared>
 <%init>