diff --git a/lib/js/admin-geo.js b/lib/js/admin-geo.js index 5213b18..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,31 @@ var map_location; 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); + + if(!defaultLat) { defaultLat = "52.3730438" } + if(!defaultLng) { defaultLng = "4.837568000" } + if(!defaultZoom) { defaultZoom = "10" } + defaultLat = parseFloat(defaultLat); + 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(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); @@ -37,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); @@ -53,6 +61,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) { @@ -68,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() { @@ -91,11 +102,17 @@ 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."); $('#location_address').removeClass('disabled'); } }; - + })(); 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_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 d1cbdbe..2db01a2 100644 --- a/templates/_admin_configure_module.tpl +++ b/templates/_admin_configure_module.tpl @@ -7,7 +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 %} + {% include "_admin_configure_map_field.tpl" %} + {% else %} + {% wire id="apikey" type="blur" action={update target="showmap" template="_admin_configure_map_field.tpl" } %} +
+ {% endif %}