Added automatic mapping for the location address when zip is entered if still have...
authorChuck Scott <cscott@gaslightmedia.com>
Thu, 29 Nov 2018 20:27:17 +0000 (15:27 -0500)
committerChuck Scott <cscott@gaslightmedia.com>
Thu, 29 Nov 2018 20:27:17 +0000 (15:27 -0500)
index.php [changed mode: 0644->0755]
readme.txt [changed mode: 0644->0755]
views/admin/events/edit.html
views/admin/events/editLocation.html

old mode 100644 (file)
new mode 100755 (executable)
index 86fc3b6..e3eefb9
--- a/index.php
+++ b/index.php
@@ -3,7 +3,7 @@
  * Plugin Name: GLM Associate - Events Add-On
  * Plugin URI: http://www.gaslightmedia.com/
  * Description: Gaslight Media Members Database.
- * Version: 1.7.8
+ * Version: 1.7.9
  * Author: Chuck Scott
  * Author URI: http://www.gaslightmedia.com/
  * License: GPL2
@@ -19,7 +19,7 @@
  * @package glmMembersDatabaseEventsAddOn
  * @author Chuck Scott <cscott@gaslightmedia.com>
  * @license http://www.gaslightmedia.com Gaslightmedia
- * @version 1.7.8
+ * @version 1.7.9
  */
 
 // Check that we're being called by WordPress.
@@ -43,7 +43,7 @@ if (!defined('ABSPATH')) {
  *  so that we're sure the other add-ons see an up to date
  *  version from this plugin.
  */
-define('GLM_MEMBERS_EVENTS_PLUGIN_VERSION', '1.7.8');
+define('GLM_MEMBERS_EVENTS_PLUGIN_VERSION', '1.7.9');
 define('GLM_MEMBERS_EVENTS_PLUGIN_DB_VERSION', '0.1.10');
 
 // This is the minimum version of the GLM Members DB plugin require for this plugin.
old mode 100644 (file)
new mode 100755 (executable)
index 3538727..9d65f2f
@@ -25,6 +25,12 @@ e.g.
 1. Activate the plugin through the 'Plugins' menu in WordPress
 
 == Changelog ==
+= 1.7.9 =
+* When editing a location for an event and the map is still showing the default location,
+  it will try to map the address and notify the user that it's doing this.
+* When looking up addresses for the map it will no longer incorrectly match a roadway as
+  the target object.
+
 = 1.6.89 =
 * Fixed date range displayed for an event when included in an event list.
 
index 4e1b3e6..3f2770b 100755 (executable)
 
                     // When estimate location button is clicked, geocode using address
                     var addressMapFail = 'Sorry, we were unable to get a map position from the address provided.';
+
+                    // Do address lookup if "Map Location" button clicked
                     $('#glm-estimate-location_' + locID).on('click', function() {
+                        lookupAddress(locID);
+                    });
+
+                    // Do address lookup if ZIP is changed and the lat/lon is still the default
+                    $('.zipcode-input').on('change', function() {
+                        locID = $(this).attr('data-id');
+                        var addrZip = $('#zip_' + locID).val();
+                        var lat = $('#glmLat_' + locID).val();
+                        var lng = $('#glmLng_' + locID).val();
+                        if ({$newLocation.fieldData.lat} == lat && {$newLocation.fieldData.lon} == lng ) {
+                            alert("The map location for this address has not yet been set.\n\nWe'll try to find it, but if the map location isn't correct,\nyou can drag to pointer to the correct location.");
+                            lookupAddress(locID);
+                        }
+                    });
 
+                    // Do address lookup using Nominatim
+                    function lookupAddress(locID) {
                         var addrStreet = $('#address_' + locID).val();
                         var addrCity = $('#city_' + locID + ' option:selected').text().trim();
                         var addrState = $('#state_' + locID).val();
                         var addrCountry = $('#country_' + locID).val();
                         var addrZip = $('#zip_' + locID).val();
 
+console.log({
+    format: 'json',
+    street: addrStreet,
+    city: addrCity,
+    state: addrState,
+    country: addrCountry,
+    postalcode: addrZip
+});
+
                         var location = $.getJSON( nominatimAPI, {
                             format: 'json',
                             street: addrStreet,
                             city: addrCity,
                             state: addrState,
                             country: addrCountry,
-                            postalcode: addrZip
+                            postalcode: addrZip,
+                            result: 1
                         })
                         .fail(function(data) {
                             alert('Sorry, we had a communications failure. 2');
                         })
                         .done(function( data ) {
+console.log(data);
+                            if( !data[0] || !data[0].lat || !data[0].lon || data[0].type == 'unclassified') {
+
+console.log({
+    format: 'json',
+    street: addrStreet,
+    // city: addrCity,
+    state: addrState,
+    country: addrCountry,
+    postalcode: addrZip
+});
 
-                            if( !data[0] || !data[0].lat || !data[0].lon ) {
                                 // Not found, try again without city name
                                 // Nominatim doesn't always find with the US ZIP preferred city name
                                 var location = $.getJSON( nominatimAPI, {
                                     // city: addrCity,
                                     state: addrState,
                                     country: addrCountry,
-                                    postalcode: addrZip
+                                    postalcode: addrZip,
+                                    result: 1
                                 })
                                 .fail(function(data) {
                                     alert('Sorry, we had a communications failure. 2');
 
                         });
 
-                    });
+                    }
 
                     // Assign a position found by the Nominatim search above
                     function assignNewPosition(data) {
index 954c5ce..1df04bd 100755 (executable)
@@ -97,7 +97,7 @@
                             <tr>
                                 <th>Address:</th>
                                 <td>
-                                    <input id="address_{$loc.id}" data-id="{$loc.id}" type="text" name="Loc{$loc.id}_address" value="{$loc.address}" class="glm-form-text-input-medium location-address">
+                                    <input id="address_{$loc.id}" data-id="{$loc.id}" type="text" name="Loc{$loc.id}_address" value="{$loc.address}" class="glm-form-text-input-medium">
                                 </td>
                             </tr>
                             <tr>
                                     <!--  Add new city dialog -->
                                     <div data-id="{$loc.id}" class="button button-secondary glm-right new-city-button">Add a new City</div>
                                     <!-- City Selection -->
-                                    <select id="city_{$loc.id}" data-id="{$loc.id}" class="city-picklist location-address" name="Loc{$loc.id}_city">
+                                    <select id="city_{$loc.id}" data-id="{$loc.id}" class="city-picklist" name="Loc{$loc.id}_city">
                                         <option value="0"></option>
                         {foreach from=$loc.city.list item=v}
                                         <option value="{$v.value}"{if $v.default} selected="selected"{/if}>
                             <tr>
                                 <th>State:</th>
                                 <td>
-                                    <select id="state_{$loc.id}" data-id="{$loc.id}" class="location-address" name="Loc{$loc.id}_state">
+                                    <select id="state_{$loc.id}" data-id="{$loc.id}" class="" name="Loc{$loc.id}_state">
                                         <option value=""></option>
                         {foreach from=$loc.state.list item=v}
                                         <option value="{$v.value}"{if $v.default} selected="selected"{/if}>
                             <tr>
                                 <th>ZIP / Postal Code:</th>
                                 <td>
-                                    <input id="zip_{$loc.id}" data-id="{$loc.id}" type="text" name="Loc{$loc.id}_zip" value="{$loc.zip}" class="glm-form-text-input-medium location-address">
+                                    <input id="zip_{$loc.id}" data-id="{$loc.id}" type="text" name="Loc{$loc.id}_zip" value="{$loc.zip}" class="glm-form-text-input-medium zipcode-input">
                                 </td>
                             </tr>
                             <tr>
                                 <th>Country:</th>
                                 <td>
-                                    <select id="country_{$loc.id}" data-id="{$loc.id}" class="location-address" name="Loc{$loc.id}_country">
+                                    <select id="country_{$loc.id}" data-id="{$loc.id}" name="Loc{$loc.id}_country">
                         {foreach from=$loc.country.list item=v}
                                         <option value="{$v.value}"{if $v.default} selected="selected"{/if}>
                                             {$v.name} {$v.value}
                 <tr>
                     <th>Address:</th>
                     <td>
-                        <input id="address_{ newLocID }" data-id="{ newLocID }" type="text" name="{ newLocID }_address" value="{$newLocation.fieldData.address}" class="glm-form-text-input-medium location-address">
+                        <input id="address_{ newLocID }" data-id="{ newLocID }" type="text" name="{ newLocID }_address" value="{$newLocation.fieldData.address}" class="glm-form-text-input-medium">
                     </td>
                 </tr>
                 <tr>
                         <!--  Add new city dialog -->
                         <div data-id="{ newLocID }" class="button button-secondary glm-right new-city-button">Add a new City</div>
                         <!-- City Selection -->
-                        <select id="city_{ newLocID }" data-id="{ newLocID }" class="city-picklist location-address" name="{ newLocID }_city">
+                        <select id="city_{ newLocID }" data-id="{ newLocID }" class="city-picklist" name="{ newLocID }_city">
                             <option value="0"></option>
             {foreach from=$newLocation.fieldData.city.list item=v}
                             <option value="{$v.value}"{if $v.default} selected="selected"{/if}>{$v.name}</option>
                 <tr>
                     <th>State:</th>
                     <td>
-                        <select  id="state_{ newLocID }" data-id="{ newLocID }" class="location-address" name="{ newLocID }_state">
+                        <select  id="state_{ newLocID }" data-id="{ newLocID }" name="{ newLocID }_state">
             {foreach from=$newLocation.fieldData.state.list item=v}
                             <option value="{$v.value}"{if $v.value == $eventDefaultState} selected="selected"{/if}>
                                 {$v.name} {if $eventDefaultState == $v.value} (default) {/if}
                 <tr>
                     <th>ZIP / Postal Code:</th>
                     <td>
-                        <input id="zip_{ newLocID }" data-id="{ newLocID }" type="text" name="{ newLocID }_zip" value="{$newLocation.fieldData.zip}" class="glm-form-text-input-medium location-address">
+                        <input id="zip_{ newLocID }" data-id="{ newLocID }" type="text" name="{ newLocID }_zip" value="{$newLocation.fieldData.zip}" class="glm-form-text-input-medium zipcode-input">
                     </td>
                 </tr>
                 <tr>
                     <th>Country:</th>
                     <td>
-                        <select id="country_{ newLocID }" data-id="{ newLocID }" class="location-address" name="{ newLocID }_country">
+                        <select id="country_{ newLocID }" data-id="{ newLocID }" name="{ newLocID }_country">
             {foreach from=$newLocation.fieldData.country.list item=v}
                             <option value="{$v.value}"{if $v.default} selected="selected"{/if}>
                                 {$v.name} {$v.value}