Updated event code to have automatic updates to the map location when entering an...
authorChuck Scott <cscott@gaslightmedia.com>
Thu, 23 Jun 2016 18:17:56 +0000 (14:17 -0400)
committerChuck Scott <cscott@gaslightmedia.com>
Thu, 23 Jun 2016 18:17:56 +0000 (14:17 -0400)
* The event is submitted (will not auto update when editing later.
* The user clicks the "Map Location Using Above Address" button
* The user drags the map pointer to a new location.
* "Update pointer" button is clicked to use specified lat/lon values.

Also added more instructions on how to use the map below the "Update pointer" button.

Tested and committed to code as HotFix

index.php
views/admin/events/edit.html
views/admin/events/editLocation.html

index a822126..9a03a9c 100644 (file)
--- a/index.php
+++ b/index.php
@@ -3,7 +3,7 @@
  * Plugin Name: GLM Members Database Events
  * Plugin URI: http://www.gaslightmedia.com/
  * Description: Gaslight Media Members Database.
- * Version: 1.2.10
+ * Version: 1.2.11
  * Author: Chuck Scott
  * Author URI: http://www.gaslightmedia.com/
  * License: GPL2
@@ -20,7 +20,7 @@
  * @package glmMembersDatabaseEventsAddOn
  * @author Chuck Scott <cscott@gaslightmedia.com>
  * @license http://www.gaslightmedia.com Gaslightmedia
- * @version 1.2.10
+ * @version 1.2.11
  */
 
 /*
@@ -38,7 +38,7 @@
  *  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.2.10');
+define('GLM_MEMBERS_EVENTS_PLUGIN_VERSION', '1.2.11');
 define('GLM_MEMBERS_EVENTS_PLUGIN_DB_VERSION', '0.0.18');
 
 // This is the minimum version of the GLM Members DB plugin require for this plugin.
index b60e9a3..21a6d5b 100644 (file)
             }
 
             // Function to initialize actions related to a specific location
+            var mapLocationAuto = new Array(1);      // Flags for each location indicating whether the location should be doing auto map updates when entering the address
             function initLocation(locID) {
 
+                // Get lat and lon from the input fields
+                var glmLat = $('#glmLat_' + locID).val();
+                var glmLng = $('#glmLng_' + locID).val();
+                
+                // If Lat and Lon for this event are currently set to default, then set that location to mapLocationAuto true.
+                mapLocationAuto[locID] = false;
+                if (glmLat == {$settings.maps_default_lat} || glmLng == {$settings.maps_default_lon}) {
+                    mapLocationAuto[locID] = true;                    
+                }
+                
                 // Delete a location
                 $('.delete-location').on( 'click', function() {
                     locID = $(this).attr('data-id');
                 // Listen for changes in the lat/lon inputs
                 $('.latLonRecenter').on('click', function() {
 
+                    // Stop any automatic updates
+                    mapLocationAuto[locID] = false;
+
                     locID = $(this).attr('data-id');
                     
                     // Get lat and lon from the input fields
                 // Listen for an end of drag event for the map marker
                 google.maps.event.addListener(marker[locID],'dragend',function(event) {
 
+                    // Stop any automatic updates
+                    mapLocationAuto[locID] = false;
+
                     // Get the end postion
                     glmLat = this.position.lat();
                     glmLng = this.position.lng();
 
                 // When estimate location button is clicked, geocode using address
                 $('#glm-estimate-location_' + locID).on('click', function() {
+
+                    // Stop any automatic updates
+                    mapLocationAuto[locID] = false;
+
                     glmGeocode(locID);
                 });
 
+                // When an address is updated and mapLocationAuto is set for that locID, geocode using address
+                $('.location-address').on('change', function() {
+                    locID = $(this).attr('data-id');
+                    if (mapLocationAuto[locID]) {
+                        glmGeocode(locID);
+                    }
+                });
+
             }
 
             function glmGeocode(locID) {
 
                         // Otherwise tell the user.
                     } else {
-                        alert('Not able to estimate position from the current address.');
+                        alert('Not able to estimate map position from the current address.');
                     }
                 });
 
index d3ba261..29b82a2 100644 (file)
@@ -76,7 +76,7 @@
                             <tr>
                                 <th>Address:</th>
                                 <td>
-                                    <input id="address_{$loc.id}" type="text" name="Loc{$loc.id}_address" value="{$loc.address}" class="glm-form-text-input-medium">
+                                    <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">
                                 </td>
                             </tr>
                             <tr>
@@ -85,7 +85,7 @@
                                     <!--  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}" class="city-picklist" name="Loc{$loc.id}_city">
+                                    <select id="city_{$loc.id}" data-id="{$loc.id}" class="city-picklist location-address" 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}>
@@ -98,7 +98,7 @@
                             <tr>
                                 <th>State:</th>
                                 <td>
-                                    <select id="state_{$loc.id}" name="Loc{$loc.id}_state">
+                                    <select id="state_{$loc.id}" data-id="{$loc.id}" class="location-address" name="Loc{$loc.id}_state">
                         {foreach from=$loc.state.list item=v}
                                         <option value="{$v.value}"{if $v.default} selected="selected"{/if}>
                                             {$v.name}
                             <tr>
                                 <th>ZIP / Postal Code:</th>
                                 <td>
-                                    <input id="zip_{$loc.id}" type="text" name="Loc{$loc.id}_zip" value="{$loc.zip}" class="glm-form-text-input-medium">
+                                    <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">
                                 </td>
                             </tr>
                             <tr>
                                 <th>Country:</th>
                                 <td>
-                                    <select id="country_{$loc.id}" name="Loc{$loc.id}_country">
+                                    <select id="country_{$loc.id}" data-id="{$loc.id}" class="location-address" 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}
                                             <b>Position:</b> 
                                             &nbsp;Lat <input id="glmLat_{$loc.id}" name="Loc{$loc.id}_lat" type="text" value="{$loc.lat}" class="glm-form-text-input-veryshort">
                                             &nbsp;Lon <input id="glmLng_{$loc.id}" name="Loc{$loc.id}_lon" type="text" value="{$loc.lon}" class="glm-form-text-input-veryshort">
-                                            &nbsp;&nbsp;<span data-id="{$loc.id}" class="button button-secondary latLonRecenter">Update pointer</span>
+                                            &nbsp;&nbsp;<span data-id="{$loc.id}" class="button button-secondary latLonRecenter">Update pointer</span><br>
+                                            You may drag the map marker to the exact location desired. Also consider selecting "Satellite" view to better locate the marker.
                                         </p>
                                     </p>
                                 </td>
                 <tr>
                     <th>Address:</th>
                     <td>
-                        <input id="address_{ newLocID }" type="text" name="{ newLocID }_address" value="{$newLocation.fieldData.address}" class="glm-form-text-input-medium">
+                        <input id="address_{ newLocID }" data-id="{ newLocID }" type="text" name="{ newLocID }_address" value="{$newLocation.fieldData.address}" class="glm-form-text-input-medium location-address">
                     </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 }" class="city-picklist" name="{ newLocID }_city">
+                        <select id="city_{ newLocID }" data-id="{ newLocID }" class="city-picklist location-address" 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}>
                 <tr>
                     <th>State:</th>
                     <td>
-                        <select  id="state_{ newLocID }" name="{ newLocID }_state">
+                        <select  id="state_{ newLocID }" data-id="{ newLocID }" class="location-address" name="{ newLocID }_state">
             {foreach from=$newLocation.fieldData.state.list item=v}
                             <option value="{$v.value}"{if $v.default} selected="selected"{/if}>
                                 {$v.name}
                 <tr>
                     <th>ZIP / Postal Code:</th>
                     <td>
-                        <input id="zip_{ newLocID }" type="text" name="{ newLocID }_zip" value="{$newLocation.fieldData.zip}" class="glm-form-text-input-medium">
+                        <input id="zip_{ newLocID }" data-id="{ newLocID }" type="text" name="{ newLocID }_zip" value="{$newLocation.fieldData.zip}" class="glm-form-text-input-medium location-address">
                     </td>
                 </tr>
                 <tr>
                     <th>Country:</th>
                     <td>
-                        <select id="country_{ newLocID }" name="{ newLocID }_country">
+                        <select id="country_{ newLocID }" data-id="{ newLocID }" class="location-address" 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}
                 <tr>
                     <th>Location:</th>
                     <td>
-                        <input id="glmLat_{ newLocID }" name="{ newLocID }_lat" type="hidden" value="{$newLocation.fieldData.lat}">
-                        <input id="glmLng_{ newLocID }" name="{ newLocID }_lon" type="hidden" value="{$newLocation.fieldData.lon}">
                     <!-- Only doing one event per location now.
                         <span class="glm-right"><a id="deleteLocation_{ newLocID }" data-id="{ newLocID }" class="button button-primary glm-button glm-right delete-location">Delete Location</a></span>
                     -->
                         <div id="glm-estimate-location_{ newLocID }" class="button button-secondary">Map Location Using Address</div>
                         <p>
-                            locationMap_{ newLocID }
                             <div id="locationMap_{ newLocID }" class="glm-map-edit">(map loads here)</div>
                             <p>                            
                                 <b>Position:</b> 
-                                &nbsp;Lat <input id="glmLat_{ newLocID }" name="lat" type="text" value="{$newLocation.fieldData.lat}" class="glm-form-text-input-veryshort">
-                                &nbsp;Lon <input id="glmLng_{ newLocID }" name="lon" type="text" value="{$newLocation.fieldData.lon}" class="glm-form-text-input-veryshort">
-                                &nbsp;&nbsp;<span data-id="{ newLocID }" class="button button-secondary latLonRecenter">Update pointer.</span>
+                                &nbsp;Lat <input id="glmLat_{ newLocID }" name="{ newLocID }_lat" type="text" value="{$newLocation.fieldData.lat}" class="glm-form-text-input-veryshort">
+                                &nbsp;Lon <input id="glmLng_{ newLocID }" name="{ newLocID }_lon" type="text" value="{$newLocation.fieldData.lon}" class="glm-form-text-input-veryshort">
+                                &nbsp;&nbsp;<span data-id="{ newLocID }" class="button button-secondary latLonRecenter">Update pointer.</span><br>
+                                You may drag the map marker to the exact location desired. Also consider selecting "Satellite" view to better locate the marker.
                             </p>
                         </p>
                     </td>