From b480b1a1037068282679534daa88ede498473990 Mon Sep 17 00:00:00 2001 From: Loetie Kruger Date: Fri, 26 May 2017 17:46:22 +0200 Subject: [PATCH 1/2] Added default map location to module config & admin map templates --- lib/js/admin-geo.js | 19 ++++++++++++++++--- templates/_admin_configure_map.tpl | 22 ++++++++++++++++++++++ templates/_admin_configure_module.tpl | 12 ++++++++++++ templates/_geomap_admin_location_map.tpl | 2 +- 4 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 templates/_admin_configure_map.tpl diff --git a/lib/js/admin-geo.js b/lib/js/admin-geo.js index 5213b18..052180c 100644 --- a/lib/js/admin-geo.js +++ b/lib/js/admin-geo.js @@ -13,22 +13,26 @@ var marker; var currentPosition; - window.setupAdminGeoMap = function(rscLat, rscLng, elementId, rscZoomLevel) { + window.setupAdminGeoMap = function(rscLat, rscLng, elementId, rscZoomLevel, defaultLat, defaultLng, defaultZoom) { rscLat = parseFloat(rscLat); rscLng = parseFloat(rscLng); rscZoomLevel = parseInt(rscZoomLevel, 10); + + defaultLat = parseFloat(defaultLat); + defautlLng = parseFloat(defautlLng); + defaultZoom = parseInt(defaultZoom, 10); if (rscLat || rscLng) { currentPosition = new google.maps.LatLng(rscLat, rscLng); } - var center = currentPosition ? currentPosition : new google.maps.LatLng(52.3730438, 4.837568000); + var center = currentPosition ? currentPosition : new google.maps.LatLng(defaultLat, defaultLng); // Init map and center the map on the current position var mapOptions = { center: center, - zoom: rscZoomLevel > 0 ? rscZoomLevel : 12 + zoom: rscZoomLevel > 0 ? rscZoomLevel : defaultZoom }; map = new google.maps.Map(document.getElementById(elementId), mapOptions); @@ -53,6 +57,9 @@ google.maps.event.addListener(map, 'zoom_changed', function(e) { $('#location_zoom_level').val(map.getZoom().toString()); + $('#location_zoom_level').trigger("focus"); + $('#location_zoom_level').trigger("change"); + $('#location_zoom_level').trigger("blur"); }); $('#location_address').click(function(ev) { @@ -91,6 +98,12 @@ marker.setPosition(loc); $('#location_lat').val(latitude.toString()); $('#location_lng').val(longitude.toString()); + $('#location_lat').trigger("focus"); + $('#location_lat').trigger("change"); + $('#location_lat').trigger("blur"); + $('#location_lng').trigger("focus"); + $('#location_lng').trigger("change"); + $('#location_lng').trigger("blur"); if (!is_click) { map.setCenter(loc); z_growl_add("Location has been set."); diff --git a/templates/_admin_configure_map.tpl b/templates/_admin_configure_map.tpl new file mode 100644 index 0000000..2c4fa1b --- /dev/null +++ b/templates/_admin_configure_map.tpl @@ -0,0 +1,22 @@ +{# This template is lazy loaded from the _geomap_admin_location.tpl #} + +
+ + +
+
+ + {% wire id="location_lat" type="blur" action={config_toggle module="mod_geo" key="location_lat" on="change"} %} + + {% wire id="location_lng" type="blur" action={config_toggle module="mod_geo" key="location_lng" on="change"} %} +
+
+ + + + +{% wire id="location_zoom_level" type="blur" action={config_toggle module="mod_geo" key="location_zoom_level" on="change"} %} + +{% javascript %} + setupAdminGeoMap('', '', '{{ #geomap }}', '', '{{ m.config.mod_geo.location_lat.value|escape }}', '{{ m.config.mod_geo.location_lng.value|escape }}', '{{ m.config.mod_geo.location_zoom_level.value|escape }}'); +{% endjavascript %} diff --git a/templates/_admin_configure_module.tpl b/templates/_admin_configure_module.tpl index d1cbdbe..3d233b0 100644 --- a/templates/_admin_configure_module.tpl +++ b/templates/_admin_configure_module.tpl @@ -7,6 +7,18 @@ {% wire id="apikey" type="blur" action={config_toggle module="mod_geo" key="api_key" on="keyup"} %} +
+ +
+ {% if m.config.mod_geo.api_key.value %} +
+ {% lazy action={update target=#lazy id=id template="_admin_configure_map.tpl"}%} +
+ {% else %} + {_ First add the Google maps API key _} + {% endif %} +
+
diff --git a/templates/_geomap_admin_location_map.tpl b/templates/_geomap_admin_location_map.tpl index 2c143b5..f336342 100644 --- a/templates/_geomap_admin_location_map.tpl +++ b/templates/_geomap_admin_location_map.tpl @@ -34,5 +34,5 @@ {% javascript %} - setupAdminGeoMap('{{ id.location_lat }}', '{{ id.location_lng }}', '{{ #geomap }}', '{{ id.location_zoom_level }}'); + setupAdminGeoMap('{{ id.location_lat }}', '{{ id.location_lng }}', '{{ #geomap }}', '{{ id.location_zoom_level }}', '{{ m.config.mod_geo.location_lat.value|escape }}', '{{ m.config.mod_geo.location_lng.value|escape }}', '{{ m.config.mod_geo.location_zoom_level.value|escape }}'); {% endjavascript %} From b5569181e81ed3b1763bce5c0fe093b3b3d7c85d Mon Sep 17 00:00:00 2001 From: Loetie Kruger Date: Mon, 29 May 2017 17:15:55 +0200 Subject: [PATCH 2/2] Feedback: Fix typo, hardcoded original defaults if no custom defaults available, reload template after api key inserted --- lib/js/admin-geo.js | 30 ++++++++++++++---------- templates/_admin_configure_map_field.tpl | 10 ++++++++ templates/_admin_configure_module.tpl | 19 +++++---------- 3 files changed, 33 insertions(+), 26 deletions(-) create mode 100644 templates/_admin_configure_map_field.tpl diff --git a/lib/js/admin-geo.js b/lib/js/admin-geo.js index 052180c..b808231 100644 --- a/lib/js/admin-geo.js +++ b/lib/js/admin-geo.js @@ -1,6 +1,6 @@ (function() { - // disable the 'entered address' button when there is no address on the edit page + // disable the 'entered address' button when there is no address on the edit page if ($('#address_country').length == 0) { $('#location_address').addClass('disabled'); } @@ -12,23 +12,27 @@ var map_location; var marker; var currentPosition; - + window.setupAdminGeoMap = function(rscLat, rscLng, elementId, rscZoomLevel, defaultLat, defaultLng, defaultZoom) { rscLat = parseFloat(rscLat); rscLng = parseFloat(rscLng); rscZoomLevel = parseInt(rscZoomLevel, 10); + if(!defaultLat) { defaultLat = "52.3730438" } + if(!defaultLng) { defaultLng = "4.837568000" } + if(!defaultZoom) { defaultZoom = "10" } + defaultLat = parseFloat(defaultLat); - defautlLng = parseFloat(defautlLng); + defaultLng = parseFloat(defaultLng); defaultZoom = parseInt(defaultZoom, 10); - + if (rscLat || rscLng) { currentPosition = new google.maps.LatLng(rscLat, rscLng); } var center = currentPosition ? currentPosition : new google.maps.LatLng(defaultLat, defaultLng); - + // Init map and center the map on the current position var mapOptions = { center: center, @@ -41,15 +45,15 @@ draggable: true, animation: google.maps.Animation.DROP }); - + if (currentPosition) { marker.setPosition(currentPosition); marker.setMap(map); } - google.maps.event.addListener(marker, "dragend", function(e) { + google.maps.event.addListener(marker, "dragend", function(e) { map_mark_location(e.latLng.lng(), e.latLng.lat(), true); - }); + }); google.maps.event.addListener(map, 'click', function(e) { map_mark_location(e.latLng.lng(), e.latLng.lat(), true); @@ -75,16 +79,16 @@ z_notify("address_lookup", args); $(this).addClass('disabled'); } - ev.preventDefault(); + ev.preventDefault(); }); - - $('#location_clear').click(function(ev) { + + $('#location_clear').click(function(ev) { $('#location_lat').val(''); $('#location_lng').val(''); marker.setMap(null); ev.preventDefault(); }); - + } window.map_mark_location_error = function() { @@ -110,5 +114,5 @@ $('#location_address').removeClass('disabled'); } }; - + })(); diff --git a/templates/_admin_configure_map_field.tpl b/templates/_admin_configure_map_field.tpl new file mode 100644 index 0000000..e93f3fe --- /dev/null +++ b/templates/_admin_configure_map_field.tpl @@ -0,0 +1,10 @@ +
+ +
+ {% if m.config.mod_geo.api_key.value %} +
+ {% lazy action={update target=#lazy id=id template="_admin_configure_map.tpl"}%} +
+ {% endif %} +
+
diff --git a/templates/_admin_configure_module.tpl b/templates/_admin_configure_module.tpl index 3d233b0..2db01a2 100644 --- a/templates/_admin_configure_module.tpl +++ b/templates/_admin_configure_module.tpl @@ -7,19 +7,12 @@ {% wire id="apikey" type="blur" action={config_toggle module="mod_geo" key="api_key" on="keyup"} %} -
- -
- {% if m.config.mod_geo.api_key.value %} -
- {% lazy action={update target=#lazy id=id template="_admin_configure_map.tpl"}%} -
- {% else %} - {_ First add the Google maps API key _} - {% endif %} -
-
- + {% if m.config.mod_geo.api_key.value %} + {% include "_admin_configure_map_field.tpl" %} + {% else %} + {% wire id="apikey" type="blur" action={update target="showmap" template="_admin_configure_map_field.tpl" } %} +
+ {% endif %}