From 001496e7dc381b8ce5e085f36bd998af0e9d288f Mon Sep 17 00:00:00 2001 From: Darryl Quinn Date: Thu, 4 Feb 2016 17:55:57 -0600 Subject: [PATCH] bugfix: re-worked wifi distance setting to show all values (miles, KM, meters) --- files/www/cgi-bin/setup | 59 ++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 30 deletions(-) diff --git a/files/www/cgi-bin/setup b/files/www/cgi-bin/setup index 92374f2e..4ad5eca6 100755 --- a/files/www/cgi-bin/setup +++ b/files/www/cgi-bin/setup @@ -182,7 +182,6 @@ $wifi_distance = 0 if $wifi_distance =~ /\D/; $parms{wifi_distance} = $wifi_distance; $parms{wifi_txpower} = $wifi_txpower; - # # apply the wifi settings # @@ -202,7 +201,6 @@ if($parms{button_apply} or $parms{button_save}) } - if($parms{button_updatelocation}) { # Process gridsquare ----------------------------------- @@ -506,35 +504,34 @@ function noLocation() alert('Could not find location. Try pinning it on the map.'); } function updDist(x) { - var u = document.getElementById('distance_unit_text').innerHTML; - var xc= calcDistance(x,u); + var dvs= calcDistance(x); + var xcm=dvs['miles']; + var xc=dvs['meters']; + var xck=dvs['kilometers']; + var distBox = document.getElementById('dist'); - var dist_hidden=document.getElementsByName('wifi_distance')[0]; - document.getElementsByName('wifi_distance_disp')[0].value = x; - dist_hidden.value = xc; + var dist_meters=document.getElementsByName('wifi_distance')[0]; + document.getElementsByName('wifi_distance_disp_miles')[0].value = xcm; + document.getElementsByName('wifi_distance_disp_km')[0].value = xck; + document.getElementsByName('wifi_distance_disp_meters')[0].value = xc; + dist_meters.value = xc; + // if default, then ALERT! - if(dist_hidden.value==0) { + if(dist_meters.value==0) { distBox.className = 'dist-alert'; } else { distBox.className = 'dist-norm'; } } -function updDistUnit(u) { - document.getElementById('distance_unit_text').innerHTML = u; - var x=document.getElementsByName('wifi_distance_disp')[0].value; - updDist(x,u); -} -function calcDistance(x, u) { - var dv=0.0; - if(u=='kilometers') { - dv=x*1000; - } else { - dv=x/0.00062137; - } - dv=Math.ceil(dv); - return dv; +function calcDistance(x) { + // x is in KILOMETERS + var dvs = new Object(); + dvs['miles']=(x*0.621371192).toFixed(2); + dvs['meters']=Math.ceil(x*1000); + dvs['kilometers']=x; + return dvs; }"; print " @@ -798,14 +795,17 @@ if($wifi_proto ne "disabled") print "  \n"; print "Distance to
FARTHEST Neighbor\n"; - $wifi_distance_disp=int($wifi_distance/1000); - - print " kilometers
"; - print "
"; - print "Miles "; - print "Kilometers
"; - print ""; + $wifi_distance=int($wifi_distance); # in meters + $wifi_distance_disp_km=int($wifi_distance/1000); + $wifi_distance_disp_miles=sprintf("%.2f",$wifi_distance_disp_km*.621371192); + + print " miles
"; + print " kilometers
"; + print " meters
"; + + print "
"; + print ""; print "\n"; @@ -1131,4 +1131,3 @@ EOF } print "\n"; print "\n"; -