Miglioramento interfaccia di geolocalizzazione

This commit is contained in:
Dasc3er 2020-09-07 10:34:42 +02:00
parent 1377bb61cd
commit 6d2aebf1d7
6 changed files with 92 additions and 70 deletions

View File

@ -201,10 +201,6 @@ $anagrafica_azienda = Anagrafica::find(setting('Azienda predefinita'));
$sede_azienda = $anagrafica_azienda->sedeLegale; $sede_azienda = $anagrafica_azienda->sedeLegale;
$google = setting('Google Maps API key'); $google = setting('Google Maps API key');
if (!empty($google)) {
echo '
<script src="//maps.googleapis.com/maps/api/js?libraries=places&key='.$google.'"></script>';
}
echo ' echo '
<div class="col-md-4"> <div class="col-md-4">
@ -214,6 +210,7 @@ echo '
</div> </div>
<div class="panel-body">'; <div class="panel-body">';
$map_load_message = '<p>'.tr('Clicca per visualizzare').'</p>';
if (empty($google)) { if (empty($google)) {
echo ' echo '
<div class="alert alert-info"> <div class="alert alert-info">
@ -221,7 +218,9 @@ if (empty($google)) {
</div>'; </div>';
} elseif (!empty($sede_cliente->gaddress) || (!empty($sede_cliente->lat) && !empty($sede_cliente->lng))) { } elseif (!empty($sede_cliente->gaddress) || (!empty($sede_cliente->lat) && !empty($sede_cliente->lng))) {
echo ' echo '
<div id="map-edit" style="height:200px; width:100%"></div> <div id="map-edit" style="height: 200px;width: 100%;display: flex;align-items: center;justify-content: center;" onclick="caricaMappa()">
'.$map_load_message.'
</div>
<div class="clearfix"></div> <div class="clearfix"></div>
<br>'; <br>';
@ -305,32 +304,39 @@ echo '
return lat + "," + lng; return lat + "," + lng;
} }
$(document).ready(function() { function caricaMappa() {
const map_element = $("#map-edit")[0]; const map_div = $("#map-edit");
const lat = parseFloat("'.$sede_cliente->lat.'"); if (map_div.html().trim() !== "'.$map_load_message.'"){
const lng = parseFloat("'.$sede_cliente->lng.'"); return;
}
if (!lat || !lng) return; $.getScript("//maps.googleapis.com/maps/api/js?libraries=places&key='.$google.'", function() {
const position = new google.maps.LatLng(lat, lng); const map_element = map_div[0];
const lat = parseFloat("'.$sede_cliente->lat.'");
const lng = parseFloat("'.$sede_cliente->lng.'");
// Create a Google Maps native view under the map_canvas div. if (!lat || !lng) return;
const map = new google.maps.Map(map_element, { const position = new google.maps.LatLng(lat, lng);
zoom: 14,
scrollwheel: false,
mapTypeControl: true,
mapTypeId: "roadmap",
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.DROPDOWN_MENU,
mapTypeIds: ["roadmap", "terrain"],
}
});
map.setCenter(position); // Create a Google Maps native view under the map_canvas div.
const marker = new google.maps.Marker({ const map = new google.maps.Map(map_element, {
position: position, zoom: 14,
map: map, scrollwheel: false,
}); mapTypeControl: true,
}); mapTypeId: "roadmap",
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.DROPDOWN_MENU,
mapTypeIds: ["roadmap", "terrain"],
}
});
map.setCenter(position);
const marker = new google.maps.Marker({
position: position,
map: map,
});
});
}
</script>'; </script>';
if ($is_cliente or $is_fornitore or $is_tecnico) { if ($is_cliente or $is_fornitore or $is_tecnico) {

View File

@ -3,6 +3,8 @@
include_once __DIR__.'/../../../core.php'; include_once __DIR__.'/../../../core.php';
include_once __DIR__.'/../init.php'; include_once __DIR__.'/../init.php';
$google = setting('Google Maps API key');
echo ' echo '
<form action="" method="post" id="form-posizione"> <form action="" method="post" id="form-posizione">
<input type="hidden" name="backto" value="record-edit"> <input type="hidden" name="backto" value="record-edit">
@ -38,15 +40,25 @@ echo '
<script>$(document).ready(init)</script> <script>$(document).ready(init)</script>
<script> <script>
$("#geocomplete input").geocomplete({ if(window.google){
map: $("#map").length ? "#map" : false, initGeocomplete();
location: $("#gaddress").val() ? $("#gaddress").val() : [$("#lat").val(), $("#lng").val()], } else {
details: ".details", $.getScript("//maps.googleapis.com/maps/api/js?libraries=places&key='.$google.'", function() {
detailsAttribute: "data-geo" initGeocomplete();
}).bind("geocode:result", function (event, result) { });
$("#lat").val(result.geometry.location.lat()); }
$("#lng").val(result.geometry.location.lng());
}); function initGeocomplete() {
$("#geocomplete input").geocomplete({
map: $("#map").length ? "#map" : false,
location: $("#gaddress").val() ? $("#gaddress").val() : [$("#lat").val(), $("#lng").val()],
details: ".details",
detailsAttribute: "data-geo"
}).bind("geocode:result", function (event, result) {
$("#lat").val(result.geometry.location.lat());
$("#lng").val(result.geometry.location.lng());
});
}
// Ricaricamento della pagina alla chiusura // Ricaricamento della pagina alla chiusura
$("#modals > div button.close").on("click", function() { $("#modals > div button.close").on("click", function() {

View File

@ -14,7 +14,6 @@ echo '
<input type="hidden" name="backto" value="record-edit"> <input type="hidden" name="backto" value="record-edit">
<input type="hidden" name="id_record" value="'.$id_record.'"> <input type="hidden" name="id_record" value="'.$id_record.'">
<div class="row"> <div class="row">
<div class="col-md-8"> <div class="col-md-8">
<!-- DATI CLIENTE --> <!-- DATI CLIENTE -->
@ -85,10 +84,6 @@ $anagrafica_azienda = Anagrafica::find(setting('Azienda predefinita'));
$sede_azienda = $anagrafica_azienda->sedeLegale; $sede_azienda = $anagrafica_azienda->sedeLegale;
$google = setting('Google Maps API key'); $google = setting('Google Maps API key');
if (!empty($google)) {
echo '
<script src="//maps.googleapis.com/maps/api/js?libraries=places&key='.$google.'"></script>';
}
echo ' echo '
<div class="col-md-4"> <div class="col-md-4">
@ -98,6 +93,7 @@ echo '
</div> </div>
<div class="panel-body">'; <div class="panel-body">';
$map_load_message = '<p>'.tr('Clicca per visualizzare').'</p>';
if (empty($google)) { if (empty($google)) {
echo ' echo '
<div class="alert alert-info"> <div class="alert alert-info">
@ -105,7 +101,9 @@ if (empty($google)) {
</div>'; </div>';
} elseif (!empty($sede_cliente->gaddress) || (!empty($sede_cliente->lat) && !empty($sede_cliente->lng))) { } elseif (!empty($sede_cliente->gaddress) || (!empty($sede_cliente->lat) && !empty($sede_cliente->lng))) {
echo ' echo '
<div id="map-edit" style="height:200px; width:100%"></div> <div id="map-edit" style="height: 200px;width: 100%;display: flex;align-items: center;justify-content: center;" onclick="caricaMappa()">
'.$map_load_message.'
</div>
<div class="clearfix"></div> <div class="clearfix"></div>
<br>'; <br>';
@ -177,32 +175,39 @@ echo '
return lat + "," + lng; return lat + "," + lng;
} }
$(document).ready(function() { function caricaMappa() {
const map_element = $("#map-edit")[0]; const map_div = $("#map-edit");
const lat = parseFloat("'.$sede_cliente->lat.'"); if (map_div.html().trim() !== "'.$map_load_message.'"){
const lng = parseFloat("'.$sede_cliente->lng.'"); return;
}
if (!lat || !lng) return; $.getScript("//maps.googleapis.com/maps/api/js?libraries=places&key='.$google.'", function() {
const position = new google.maps.LatLng(lat, lng); const map_element = map_div[0];
const lat = parseFloat("'.$sede_cliente->lat.'");
const lng = parseFloat("'.$sede_cliente->lng.'");
// Create a Google Maps native view under the map_canvas div. if (!lat || !lng) return;
const map = new google.maps.Map(map_element, { const position = new google.maps.LatLng(lat, lng);
zoom: 14,
scrollwheel: false,
mapTypeControl: true,
mapTypeId: "roadmap",
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.DROPDOWN_MENU,
mapTypeIds: ["roadmap", "terrain"],
}
});
map.setCenter(position); // Create a Google Maps native view under the map_canvas div.
const marker = new google.maps.Marker({ const map = new google.maps.Map(map_element, {
position: position, zoom: 14,
map: map, scrollwheel: false,
}); mapTypeControl: true,
}); mapTypeId: "roadmap",
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.DROPDOWN_MENU,
mapTypeIds: ["roadmap", "terrain"],
}
});
map.setCenter(position);
const marker = new google.maps.Marker({
position: position,
map: map,
});
});
}
</script>'; </script>';
?> ?>

View File

@ -40,8 +40,8 @@ foreach ($articoli as $elenco) {
WHERE or_ordini.id != '.prepare($ordine->id).' WHERE or_ordini.id != '.prepare($ordine->id).'
AND idstatoordine = (SELECT id FROM or_statiordine WHERE descrizione = 'Bozza') AND idstatoordine = (SELECT id FROM or_statiordine WHERE descrizione = 'Bozza')
AND idtipoordine IN (SELECT id FROM or_tipiordine WHERE dir = 'entrata') AND idtipoordine IN (SELECT id FROM or_tipiordine WHERE dir = 'entrata')
AND idarticolo=".prepare($articolo->id)." AND idarticolo=".prepare($articolo->id).'
GROUP BY idarticolo")['qta']; GROUP BY idarticolo')['qta'];
$qta_impegnata = floatval($qta_impegnata); $qta_impegnata = floatval($qta_impegnata);
$class = $qta_impegnata + $qta > $articolo->qta ? 'danger' : 'success'; $class = $qta_impegnata + $qta > $articolo->qta ? 'danger' : 'success';

View File

@ -2,7 +2,6 @@
namespace Plugins\ReceiptFE; namespace Plugins\ReceiptFE;
use Carbon\Carbon;
use Modules; use Modules;
use Modules\Fatture\Fattura; use Modules\Fatture\Fattura;
use Plugins; use Plugins;

View File

@ -27,7 +27,7 @@ echo "
<table class='table table-striped table-bordered' id='contents'> <table class='table table-striped table-bordered' id='contents'>
<thead> <thead>
<tr> <tr>
<th class='text-center' style='width:5%'>".tr('#', [], ['upper' => true])."</th>"; <th class='text-center' style='width:5%'>".tr('#', [], ['upper' => true]).'</th>';
if ($has_image) { if ($has_image) {
echo " echo "
<th class='text-center' style='width:20%'>".tr('Immagine', [], ['upper' => true]).'</th>'; <th class='text-center' style='width:20%'>".tr('Immagine', [], ['upper' => true]).'</th>';