[freeside-commits] branch master updated. d5cdad7fae9c5e45701a7e83abeb903d31b7983f

Mark Wells mark at 420.am
Tue Feb 28 16:18:17 PST 2012


The branch, master has been updated
       via  d5cdad7fae9c5e45701a7e83abeb903d31b7983f (commit)
      from  2bfe8d56f1dbf342cb5fac8187953cdb08b9d4cd (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit d5cdad7fae9c5e45701a7e83abeb903d31b7983f
Author: Mark Wells <mark at freeside.biz>
Date:   Tue Feb 28 16:17:59 2012 -0800

    directions to customer address, #16585

diff --git a/httemplate/elements/coord-links.html b/httemplate/elements/coord-links.html
index 907e5f0..6b91a26 100644
--- a/httemplate/elements/coord-links.html
+++ b/httemplate/elements/coord-links.html
@@ -9,14 +9,30 @@
      #'color'
 &>
 
+% if ( $origin ) {
+  <& /elements/popup_link.html,
+      'action'      => $p. "view/directions.html?origin=$origin;". $query,
+      'label'       => mt('dir'),
+      'actionlabel' => $name,
+      'width'       => 763,
+      'height'      => 575,
+  &>
+% }
+
 <A HREF="<%$p%>view/kml.cgi?<% $query %>"><% mt('earth') |h %></A>
 
 <%init>
 
-my ($latitude, $longitude, $name) = @_;
+my ($latitude, $longitude, $name, $agentnum) = @_;
 
 my $query = 'name='. uri_escape($name).
             ';lat='. $latitude.
             ';lon='. $longitude;
 
+my $origin;
+#for directions link
+if ( $agentnum =~ /^\d+$/ ) {
+  $origin = FS::Conf->new->config('company_address', $agentnum);
+  $origin = uri_escape($origin);
+}
 </%init>
diff --git a/httemplate/elements/tr-coords.html b/httemplate/elements/tr-coords.html
index 5539f56..3248dc2 100644
--- a/httemplate/elements/tr-coords.html
+++ b/httemplate/elements/tr-coords.html
@@ -4,11 +4,11 @@
     <FONT STYLE="background-color: #ffffff; border: 1px solid #ffffff"><% $latitude %></FONT>
      <% mt('Longitude') |h %>
     <FONT STYLE="background-color: #ffffff; border: 1px solid #ffffff"><% $longitude %></FONT>
-    <& /elements/coord-links.html, $latitude, $longitude, $name &>
+    <& /elements/coord-links.html, @_ &>
   </TD>
 </TR>
 <%init>
 
-my ($latitude, $longitude, $name) = @_;
+my ($latitude, $longitude, $name, $agentnum) = @_;
 
 </%init>
diff --git a/httemplate/view/cust_main/contacts.html b/httemplate/view/cust_main/contacts.html
index 3d4043a..68e3b17 100644
--- a/httemplate/view/cust_main/contacts.html
+++ b/httemplate/view/cust_main/contacts.html
@@ -70,6 +70,7 @@
   <& /elements/tr-coords.html, $cust_main->get($pre.'latitude'),
                                $cust_main->get($pre.'longitude'),
                                $cust_main->name_short,
+                               $cust_main->agentnum,
   &>
 % }
 
diff --git a/httemplate/view/cust_main/packages/location.html b/httemplate/view/cust_main/packages/location.html
index 1bfca00..34e3a64 100644
--- a/httemplate/view/cust_main/packages/location.html
+++ b/httemplate/view/cust_main/packages/location.html
@@ -18,7 +18,8 @@
         <& /elements/coord-links.html,
              $loc->latitude,
              $loc->longitude,
-             $opt{'cust_main'}->name_short. ': '. $opt{'part_pkg'}->pkg
+             $opt{'cust_main'}->name_short. ': '. $opt{'part_pkg'}->pkg,
+             $opt{'cust_main'}->agentnum,
         &>
         </FONT>
 %   }
diff --git a/httemplate/view/directions.html b/httemplate/view/directions.html
new file mode 100644
index 0000000..599d049
--- /dev/null
+++ b/httemplate/view/directions.html
@@ -0,0 +1,101 @@
+%# the actual page
+<& /elements/header-popup.html, {
+     title => '',#$name,
+     head  => include('.head'),
+     etc   => 'onload="initialize()"',
+     nobr  => 1,
+   }
+&>
+
+<div id="directions_panel"></div>
+<div id="map_canvas"></div>
+
+<%def .head>
+% my $lat = $cgi->param('lat');
+% my $lon = $cgi->param('lon');
+<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
+
+<style type="text/css">
+html { height: 100% }
+
+body { height: 100%; margin: 0px; padding: 0px }
+
+#map_canvas {
+  height: 100%;
+  margin-right: 320px;
+}
+
+#directions_panel {
+  height: 100%;
+  float: right;
+  width: 310px;
+  overflow: auto;
+  font-size: 80%;
+}
+
+ at media print {
+  #map_canvas { height: 500px; margin: 0; }
+  #directions_panel { float: none; width: auto; }
+}
+</style>
+
+<script type="text/javascript" 
+src="https://maps.google.com/maps/api/js?v=3.4&sensor=false">
+</script>
+
+<script type="text/javascript">
+var lengthLine=0;
+var map;
+
+function show_route() {
+  var panel = document.getElementById('directions_panel');
+  var directionsService = new google.maps.DirectionsService;
+  var directionsDisplay = new google.maps.DirectionsRenderer;
+  directionsDisplay.setMap(map);
+  directionsDisplay.setPanel(panel);
+
+  var directionsRequest = {
+    origin: <%$origin |js_string%>,
+    destination: <% $lat %>+","+<% $lon %>,
+    travelMode: google.maps.TravelMode.DRIVING
+  };
+
+  directionsService.route(directionsRequest, function(result, status) {
+    if ( status == google.maps.DirectionsStatus.OK ) {
+      directionsDisplay.setDirections(result);
+    }
+  });
+}
+
+function initialize() {
+  var myOptions = {
+    zoom: 14,
+    rotateControl: true,
+    mapTypeId: google.maps.MapTypeId.ROADMAP
+  };
+
+  map = new google.maps.Map(
+    document.getElementById("map_canvas"),
+    myOptions
+  );
+  map.setOptions( {rotateControl : true });
+
+  show_route();
+}
+</script>
+</%def>
+<%shared>
+my ($lat, $lon, $name, $origin);
+</%shared>
+<%init>
+
+$name = $cgi->param('name');
+
+$lat = $cgi->param('lat');
+$lon = $cgi->param('lon');
+$lat =~ /^-?\d+(\.\d+)?$/ or die "bad latitude: $lat";
+$lon =~ /^-?\d+(\.\d+)?$/ or die "bad longitude: $lat";
+
+$origin = $cgi->param('origin') or die "no origin specified";
+
+</%init>
diff --git a/httemplate/view/map.html b/httemplate/view/map.html
index 1725fd8..3122de6 100644
--- a/httemplate/view/map.html
+++ b/httemplate/view/map.html
@@ -1,120 +1,69 @@
+%# the actual page
 <& /elements/header-popup.html, {
      title => '',#$name,
-     head  => $head,
-     etc   => 'onload="html_googlemaps_initialize()"',
+     head  => include('.head'),
+     etc   => 'onload="initialize()"',
      nobr  => 1,
    }
 &>
 
-<% $map_div %>
+<div id="map_canvas"></div>
 
-<%init>
-
-my $name = js_string( scalar($cgi->param('name')) );
+<%def .head>
+<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
 
-my $point = [ map scalar($cgi->param($_)), qw( longitude latitude ) ];
+<style type="text/css">
+html { height: 100% }
 
-my( $head, $map_div ) = onload_render(
-  $name,
-  map scalar($cgi->param($_)), qw( lat lon )
-);
-
-#false laziness w/Mason.pm
-sub js_string {
-    my $string = shift;
-    $string =~ s/(['\\])/\\$1/g;
-    $string =~ s/\r/\\r/g;
-    $string =~ s/\n/\\n/g;
-    $string = "'". $string. "'";
-    return $string;
-}
+body { height: 100%; margin: 0px; padding: 0px }
 
-#subroutines below derived from HTML::GoogleMapsV3, but without using
-#Geo::Coder::Google or GPS::Point
-sub onload_render 
-{
-##	my $self = shift;
-        my( $name, $latitude, $longitude ) = @_;
+#map_canvas { height: 100%; }
 
-	#map_canvas { height: 100% }
-	
-	my $header='
-	<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
-	<style type="text/css">
-  		html { height: 100% }
-  		body { height: 100%; margin: 0px; padding: 0px }
-  		#map_canvas { height: 100% }
-	</style>
-	<script type="text/javascript" src="https://maps.google.com/maps/api/js?libraries=panoramio,geometry&v=3.4&sensor=false">
-	</script>
-	<script type="text/javascript">
-  	var lengthLine=0;
-  	function html_googlemaps_initialize() {
-    var latlng = new google.maps.LatLng(' .$latitude . ',' . $longitude . ');
-    var myOptions = {
-      zoom: 14,
-      center: latlng,
-      rotateControl: true,
-      mapTypeId: google.maps.MapTypeId.ROADMAP
-    };
-    
-    map = new google.maps.Map(document.getElementById("map_canvas"),
-        myOptions);
-    
-    map.setOptions( {rotateControl : true });
-    
+ at 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">
+</script>
 
-##our own hacked in code for displaying a marker at the center
-$header .= '
-var markerOptions = {
-  map: map,
-  position: latlng,
-  title: '. $name. '
-};
-var marker = new google.maps.Marker(markerOptions);
-';
+<script type="text/javascript">
+var lengthLine=0;
+var map;
 
-##	if( defined $self->{polyline} ) {
-##		foreach my $polyline ( keys %{$self->{polyline}} ) {
-##			$header .= $self->{polyline}->{$polyline} . "\n";
-##		}
-##	}
-	
-	$header .= '}
-	</script>';
-	
-	
-	#my $div = '<div id="map_canvas" style="width:80%; height:75%"></div>';
-	my $div = '<div id="map_canvas" style="width:100%; height:100%"></div>';
+function initialize() {
+  var latlng = new google.maps.LatLng(<%$lat%>, <%$lon%>);
+  var myOptions = {
+    center: latlng,
+    zoom: 14,
+    rotateControl: true,
+    mapTypeId: google.maps.MapTypeId.ROADMAP
+  };
 
+  map = new google.maps.Map(
+    document.getElementById("map_canvas"),
+    myOptions
+  );
+  map.setOptions( {rotateControl : true });
 
-	$header .= "<SCRIPT>
-	
-	panoramioLayer = new google.maps.panoramio.PanoramioLayer();
-	
-	function panoramioOn(){ 
-								panoramioLayer.setMap(map);
-	}
-	function panoramioOff() {
-		panoramioLayer.setMap(null);
-	}
-	
-	function panoramioToggle() {
-		if( panoramioLayer.getMap() == null ) {
-			panoramioOn(); 
-		} else {
-			panoramioOff();
-		}
-	}	
-	
+  var markerOptions = {
+    map: map,
+    position: latlng,
+    title: <%$name |js_string%>
+  };
+  var marker = new google.maps.Marker(markerOptions);
+}
+</script>
+</%def>
+<%shared>
+my ($lat, $lon, $name);
+</%shared>
+<%init>
 
-		
-	</SCRIPT>";
+$name = $cgi->param('name');
 
-	return ($header,$div)
-	
-}
+$lat = $cgi->param('lat');
+$lon = $cgi->param('lon');
+$lat =~ /^-?\d+(\.\d+)?$/ or die "bad latitude: $lat";
+$lon =~ /^-?\d+(\.\d+)?$/ or die "bad longitude: $lat";
 
 </%init>
diff --git a/httemplate/view/svc_broadband.cgi b/httemplate/view/svc_broadband.cgi
index 05ae632..961374e 100644
--- a/httemplate/view/svc_broadband.cgi
+++ b/httemplate/view/svc_broadband.cgi
@@ -89,14 +89,22 @@ sub coordinates {
   return '' unless $s->latitude && $s->longitude;
 
   my $d = $s->description;
+  my $agentnum;
   unless ($d) {
-    my $cust_pkg = $s->cust_svc->cust_pkg;
-    $d = $cust_pkg->cust_main->name_short if $cust_pkg;
+    if ( my $cust_pkg = $s->cust_svc->cust_pkg ) {
+      $d = $cust_pkg->cust_main->name_short;
+      $agentnum = $cust_pkg->cust_main->agentnum;
+    }
   }
   
   #'Latitude: '. $s->latitude. ', Longitude: '. $s->longitude. ' '.
   $s->latitude. ', '. $s->longitude. ' '.
-    include('/elements/coord-links.html', $s->latitude, $s->longitude, $d);
+    include('/elements/coord-links.html', 
+      $s->latitude,
+      $s->longitude,
+      $d,
+      $agentnum
+    );
 }
 
 sub svc_callback {

-----------------------------------------------------------------------

Summary of changes:
 httemplate/elements/coord-links.html             |   18 +++-
 httemplate/elements/tr-coords.html               |    4 +-
 httemplate/view/cust_main/contacts.html          |    1 +
 httemplate/view/cust_main/packages/location.html |    3 +-
 httemplate/view/directions.html                  |  101 +++++++++++++++
 httemplate/view/map.html                         |  149 +++++++---------------
 httemplate/view/svc_broadband.cgi                |   14 ++-
 7 files changed, 183 insertions(+), 107 deletions(-)
 create mode 100644 httemplate/view/directions.html




More information about the freeside-commits mailing list