71873: GlobalVision - directions
authorJonathan Prykop <jonathan@freeside.biz>
Sat, 24 Sep 2016 00:00:29 +0000 (19:00 -0500)
committerJonathan Prykop <jonathan@freeside.biz>
Sat, 24 Sep 2016 00:00:29 +0000 (19:00 -0500)
FS/FS/Conf.pm
httemplate/elements/coord-links.html
httemplate/view/directions.html
httemplate/view/map.html

index 2da69f8..57761bb 100644 (file)
@@ -2069,6 +2069,13 @@ 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 <a href="https://developers.google.com/maps/documentation/javascript/get-api-key">Getting a Google Maps API Key</a>',
+    'type'        => 'text',
+  },
+
+  {
     'key'         => 'show_ship_company',
     'section'     => 'addresses',
     'description' => 'Turns on display/collection of a "service company name" field for customers.',
     'key'         => 'show_ship_company',
     'section'     => 'addresses',
     'description' => 'Turns on display/collection of a "service company name" field for customers.',
index 45b8132..a755791 100644 (file)
@@ -1,5 +1,7 @@
 <& /elements/init_overlib.html &>
 
 <& /elements/init_overlib.html &>
 
+% if ( $apikey ) {
+
 <& /elements/popup_link.html,
      'action'      => $p. 'view/map.html?'. $query,
      'label'       => mt('map'),
 <& /elements/popup_link.html,
      'action'      => $p. 'view/map.html?'. $query,
      'label'       => mt('map'),
@@ -19,6 +21,8 @@
   &>
 % }
 
   &>
 % }
 
+% } # end if $apikey
+
 <A HREF="<%$p%>view/kml.cgi?<% $query %>"><% mt('earth') |h %></A>
 
 <%init>
 <A HREF="<%$p%>view/kml.cgi?<% $query %>"><% mt('earth') |h %></A>
 
 <%init>
@@ -45,10 +49,13 @@ $m->interp->apply_escapes($js_name, 'js_string');
 $js_name =~ s/^'//;
 $js_name =~ s/'$//;
 
 $js_name =~ s/^'//;
 $js_name =~ s/'$//;
 
+my $conf = new FS::Conf;
+my $apikey = $conf->config('google_maps_api_key');
+
 #for directions link
 my @origin = $opt{company_address}
                ? @{ $opt{company_address} }
 #for directions link
 my @origin = $opt{company_address}
                ? @{ $opt{company_address} }
-               : FS::Conf->new->config('company_address', $agentnum);
+               : $conf->config('company_address', $agentnum);
 my $origin = uri_escape(join(',', @origin));
 
 </%init>
 my $origin = uri_escape(join(',', @origin));
 
 </%init>
index f14a11a..a07df40 100644 (file)
@@ -38,8 +38,9 @@ body { height: 100%; margin: 0px; padding: 0px }
 }
 </style>
 
 }
 </style>
 
-<script type="text/javascript" 
-src="https://maps.google.com/maps/api/js?v=3.4&sensor=false">
+% my $conf = new FS::Conf;
+% my $apikey = $conf->config('google_maps_api_key');
+<script type="text/javascript" src="https://maps.google.com/maps/api/js?v=3&key=<% $apikey %>">
 </script>
 
 <script type="text/javascript">
 </script>
 
 <script type="text/javascript">
@@ -62,6 +63,8 @@ function show_route() {
   directionsService.route(directionsRequest, function(result, status) {
     if ( status == google.maps.DirectionsStatus.OK ) {
       directionsDisplay.setDirections(result);
   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>');
     }
   });
 }
     }
   });
 }
index 3122de6..d996a33 100644 (file)
@@ -22,8 +22,9 @@ body { height: 100%; margin: 0px; padding: 0px }
 @media print { #map_canvas { height: 500px; margin: 0; } }
 </style>
 
 @media print { #map_canvas { height: 500px; margin: 0; } }
 </style>
 
-<script type="text/javascript" 
-src="https://maps.google.com/maps/api/js?v=3.4&sensor=false">
+% my $conf = new FS::Conf;
+% my $apikey = $conf->config('google_maps_api_key');
+<script type="text/javascript" src="https://maps.google.com/maps/api/js?v=3&key=<% $apikey %>">
 </script>
 
 <script type="text/javascript">
 </script>
 
 <script type="text/javascript">