Now have some location data working.
authorChuck Scott <cscott@gaslightmedia.com>
Fri, 11 Mar 2016 20:51:31 +0000 (15:51 -0500)
committerChuck Scott <cscott@gaslightmedia.com>
Fri, 11 Mar 2016 20:51:31 +0000 (15:51 -0500)
classes/data/dataLocations.php
models/admin/events/list.php
views/admin/events/edit.html
views/admin/events/editLocation.html
views/admin/events/editSchedule.html

index 5c094d1..0ae6985 100644 (file)
@@ -134,7 +134,6 @@ class GlmDataEventsLocations extends GlmDataAbstract
             'name' => array (
                 'field' => 'name',
                 'type' => 'text',
-                'required' => true,
                 'use' => 'a'
             ),
 
@@ -154,6 +153,7 @@ class GlmDataEventsLocations extends GlmDataAbstract
                     'p_field' => 'name',
                     'p_orderby' => 'name',
                     'p_blank' => true,
+                    'force_list' => true,
                 'use' => 'a'
             ),
 
@@ -163,6 +163,7 @@ class GlmDataEventsLocations extends GlmDataAbstract
                 'type' => 'list',
                 'list' => $this->config['states'],
                 'default' => 'MI',
+                'force_list' => true,
                 'use' => 'a'
             ),
 
@@ -179,6 +180,7 @@ class GlmDataEventsLocations extends GlmDataAbstract
                 'type' => 'list',
                 'list' => $this->config['countries'],
                 'default' => 'US',
+                'force_list' => true,
                 'use' => 'a'
             ),
 
@@ -206,7 +208,7 @@ class GlmDataEventsLocations extends GlmDataAbstract
                     'p_field' => 'name',
                     'p_orderby' => 'name',
                     'p_blank' => true,
-                //  'force_list' => true,
+                    'force_list' => true,
                 'use' => 'a'
             ),
 
index dcf2b5f..f1a77c3 100644 (file)
@@ -240,7 +240,28 @@ class GlmMembersAdmin_events_list extends GlmDataEvents
                     }
                 }
 
-                // Look for recurrence data
+                // Look for location data
+                if (isset($_REQUEST['locID'])) {
+
+                    // For each location
+                    foreach ($_REQUEST['locID'] as $locID) {
+
+                        // Check if it's a new Location
+                        if ($locID[0] == 'n') {
+
+                            // Add the new location
+                            $x = $Locations->insertEntry(true, $locID.'_');
+
+                        // Otherwise it's an existing location
+                        } else {
+                           $Locations->updateEntry($locID, 'id', true, $locID.'_');
+                        }
+
+                    }
+
+                }
+
+                        // Look for recurrence data
                 if (isset($_REQUEST['recurID'])) {
 
                     // For each recurrence
@@ -325,6 +346,15 @@ class GlmMembersAdmin_events_list extends GlmDataEvents
         // If we have an event ID
         if ($this->eventID) {
 
+            // Get locations for this event
+            $locations = $Locations->getList("T.event = ".$this->eventID);
+
+            // Check if we have locations
+            if ($locations) {
+                $haveLocations = true;
+                $numbLocations = count($locations);
+            }
+
             // Get recurrences for this event
             $recurrences = $Recurrences->getList("T.event = ".$this->eventID);
 
index 84bce9d..95ce313 100644 (file)
             // New location ID's start at 0 (have "n" for "new" appended to them in the template)
             var newLocID = 0;
 
+
+            // When adding a new location is requested
+            $("#addLocation").click( function() {
+                addNewLocationForm();
+                $('#no-location-msg').remove();
+            });
+
             function addNewLocationForm() {
 
                 // Tick the new recurrence ID counter and build new HTML from the addRecurrenceTemplate
 
                 // Otherwise, we'll say we now have our first location
                 } else {
-                    numbLoctions++;
+                    numbLocations++;
                 }
 
                 locTemp = locTemp + $('#addLocationTemplate').html();
                 // Append the new location form to the container
                 $('#locationTable').append(locTemp);
 
-                initLocation();
+                initLocation('n' + newLocID);
 
             }
 
-            // When adding a new location is requested
-            $("#addLocation").click( function() {
-                addNewLocationForm();
-                $('#no-location-msg').remove();
-            });
+            /*
+             * Things that need to be renewed each time a location is added
+             */
+            function initLocation(locID) {
+
+                // Setup dialog box for adding a new city
+                $("#newCityDialog").dialog({
+                    autoOpen: false,
+                    minWidth: 400,
+                    dialogClass: "glm-dialog-no-close"
+                });
+                $('#newCityCancel').click( function() {
+                    $("#newCityDialog").dialog("close");
+                });
+
+                // Ad a new city button action - pop-up dialog
+                $('#newCityButton').click( function() {
+                    $("#newCityDialog").dialog("open");
+                });
+
+                initMap(locID);
+
 
-            function addNewRecurrenceForm() {
-// ***** NEED TO SEE WHAT NEEDS TO GO HERE ****
             }
 
             /*
                 }
             });
 
+            /*
+             * New City Dialog
+             */
+
+            // Setup dialog box for adding a new city
+            $("#newCityDialog").dialog({
+                autoOpen: false,
+                minWidth: 400,
+                dialogClass: "glm-dialog-no-close"
+            });
+            $('#newCityCancel').click( function() {
+                $("#newCityDialog").dialog("close");
+            });
+
+            // Ad a new city button action - pop-up dialog
+            $('#newCityButton').click( function() {
+                $("#newCityDialog").dialog("open");
+            });
+
+            // Submit new city
+            var newCityAdded = false;
+            $('#newCitySubmit').click( function() {
+
+                // Get new city name
+                var newCityName = $('#newCityName').val();
+
+                // If no name is supplied, notify used it's required
+                if (newCityName == '') {
+                    $('#newCityNameTD').addClass('glm-form-bad-input');
+                    $('#newCityNameRequired').text('A city name is required!');
+                    return false;
+                }
+
+                // Add new city name to the hidden field that will pass the new name to PHP.
+                $('#cityName').val(newCityName);
+
+                // Add new city name to picklist and for storing - Only one permitted per submission
+                if (newCityAdded) {
+
+                    // New city already added, so just update the name and select that one
+                    $('#city').val(-1);
+                    $('#city option:selected').text(newCityName);
+
+                } else {
+
+                    // Add the new city name to the city picklist
+                    $('#city').append('<option value="-1">' + newCityName + '</option>');
+                    $('#city').val(-1);
+                    $('#newCityNameTD').append('<input type="hidden" name="newCity" value="' + newCityName + '">');
+                    newCityAdded = true;
+
+                }
+
+                // Clear new city name from form
+                $('#newCityName').val('');
+
+                $("#newCityDialog").dialog("close");
+
+            });
+
+            /*
+             * Map operations
+             */
+
+           //show error if location can't be found
+           function showError() {
+               alert("Location can't be found");
+           }
+
+            /*
+             * Google Maps
+             *  API reference: https://developers.google.com/maps/documentation/javascript/reference
+             */
+            var map = new Object();
+            var geocoder = new Object();
+            var location = new Object();
+            var marker = new Object();
+
+            function initMap(locID) {
+
+                // Set default - Need to make this configurable
+                var startLat = $('#glmLat_' + locID).val();
+                var startLon = $('#glmLng_' + locID).val();
+
+                location[locID] = new google.maps.LatLng(startLat, startLon);
+
+                map[locID] = new google.maps.Map(document.getElementById('locationMap_' + locID), {
+                    zoom: 15,
+                    disableDefaultUI: false,
+                    mapTypeId: google.maps.MapTypeId.MAP,
+                });
+
+                geocoder[locID] = new google.maps.Geocoder();
+                marker[locID] = new google.maps.Marker({
+                    map: map[locID],
+                    position: location[locID],
+                    draggable: enableDraggable,
+                    animation: google.maps.Animation.DROP,
+                    title: "This is your location"
+                });
+                map[locID].setCenter(location[locID]);
+
+                // Listen for an end of drag event for the map marker
+                google.maps.event.addListener(marker[locID],'dragend',function(event) {
+
+                    // Get the end postion
+                    glmLat = this.position.lat();
+                    glmLng = this.position.lng();
+
+                    // Assign it to the hidden fields for submission
+                    $('#glmLat_' + locID).val(glmLat);
+                    $('#glmLng_' + locID).val(glmLng);
+
+                    // Also display it to the user
+                    $('#mapPosition_' + locID).html('Lat ' + glmLat.toFixed(4) + ', Lon ' + glmLng.toFixed(4));
+                });
+
+                // When estimate location button is clicked, geocode using address
+                $('#glm-estimate-location_' + locID).on('click', function() {
+                    glmGeocode(locID);
+                });
+
+            }
+            
+            function glmGeocode(locID) {
+
+                // Get all address parts
+                var geoAddr1 = $('#address_' + locID ).val().trim();
+                var geoAddr2 = '';  // $('#addr2').val().trim();
+                var geoCity = $('#city_' + locID).find('option:selected').text().trim();
+                var geoState = $('#state_' + locID).find('option:selected').text().trim();
+                var geoZIP = $('#zip_' + locID).val().trim();
+                var geoCountry = $('country_' + locID).find('option:selected').text().trim();
+
+                // Assemble address string for
+                var geoAddress = geoAddr1 + ', ' + geoAddr2 + ', ' + geoCity + ', ' + geoState + ' ' + geoZIP + ', ' + geoCountry;
 
+                // Send to Google Geocoder
+                geocoder[locID].geocode( { 'address': geoAddress }, function(results, status) {
+
+                    // If we have a geocode solution
+                    if (status == google.maps.GeocoderStatus.OK) {
+
+                        // Center the map and locate the marger to the new location
+                        map[locID].setCenter(results[0].geometry.location);
+                        marker[locID].setPosition( results[0].geometry.location );
+
+                        // Assign the new position to the hidden fields for submission
+                        glmLat = results[0].geometry.location.lat();
+                        glmLng = results[0].geometry.location.lng();
+                        $('#glmLat_' + locID).val(glmLat);
+                        $('#glmLng_' + locID).val(glmLng);
+
+                        // Also display it to the user
+                        $('#mapPosition_' + locID).html('Lat ' + glmLat.toFixed(4) + ', Lon ' + glmLng.toFixed(4));
+
+                        // Otherwise tell the user.
+                    } else {
+                        alert('Not able to estimate position from the current address.');
+                    }
+                });
+
+                
+            }
+            
         });
     </script>
 
index e5da32b..9d18ce0 100644 (file)
@@ -1,6 +1,9 @@
 
 <!-- Location -->
 
+    <script src="http://maps.googleapis.com/maps/api/js?{if $settings.google_maps_api_key != ''}&key={$settings.google_maps_api_key}{/if}"></script>
+    <script type="text/javascript">var enableDraggable = true;</script>
+
 <table id="glm-table-location" class="glm-admin-table glm-hidden glm-event-table">
     <tr>
         <td id="placeLocationDeletesHere" colspan="2">
                 <!-- Location forms go here. -->
 {if $locations}
     {foreach $locations as $loc}
-
-                <tr>
-                    <th>Location Name:</th>
+                <tr><td colspan="2"><hr></td></tr>
+                <tr id="location_{$loc.id}" class="location_{$r.id} location-form">
                     <td>
-                        <input type="text" name="{$loc.id}_name" value="{$loc.fieldData.name}" class="glm-form-text-input-medium">
+                        <input type="hidden" name="locID[{$r.id}]" value="{$loc.id}">
+                        <input type="hidden" name="{$loc.id}_event" value="{$event.id}"> <!-- required to have event id with prefix -->
+                        <table width="100%">
+                            <tr>
+                                <th>Location Name:</th>
+                                <td>
+                                    <input type="text" name="{$loc.id}_name" value="{$loc.name}" class="glm-form-text-input-medium">
+                                </td>
+                            </tr>
+                            <tr>
+                                <th>Address:</th>
+                                <td>
+                                    <input type="text" name="{$loc.id}_address" value="{$loc.address}" class="glm-form-text-input-medium">
+                                </td>
+                            </tr>
+                            <tr>
+                                <th>City</th>
+                                <td class="glm-item-container">
+                                    <!--  Add new city dialog -->
+                                    <div id="newCityButton" class="button button-secondary glm-right">Add a new City</div>
+                                    <div id="newCityDialog" class="glm-dialog-box" title="Enter a New City">
+                                        <table class="glm-admin-table">
+                                            <tr>
+                                                <th class="glm-required">City Name:</th>
+                                                <td id="newCityNameTD">
+                                                    <input id="newCityName" type="text" name="newCityName" class="glm-form-text-input">
+                                                    <div id="newCityNameRequired"></div>
+                                                </td>
+                                            </tr>
+                                        </table>
+                                        <p><span class="glm-required">*</span> Required</p>
+                                        <a id="newCityCancel" class="button button-primary glm-right">Cancel</a>
+                                        <input id="newCitySubmit" type="submit" value="Add new City">
+                                    </div>
+                                    <!-- City Selection -->
+                                    <input id="cityName" type="hidden" name="newCityName" value=""><!-- this field is only used if adding a new city to pass the new name -->
+                                    <select id="city_{$loc.id}" name="{$loc.id}_city">
+                                        <option value="0"></option>
+                        {foreach from=$loc.city.list item=v}
+                                        <option value="{$v.value}"{if $v.default} selected="selected"{/if}>
+                                            {$v.name}
+                                        </option>
+                        {/foreach}
+                                    </select>
+                                </td>
+                            </tr>
+                            <tr>
+                                <th>State:</th>
+                                <td>
+                                    <select id="state_{$loc.id}" name="{$loc.id}_state">
+                        {foreach from=$loc.state.list item=v}
+                                        <option value="{$v.value}"{if $v.default} selected="selected"{/if}>
+                                            {$v.name}
+                                        </option>
+                        {/foreach}
+                                    </select>
+                                </td>
+                            </tr>
+                            <tr>
+                                <th>ZIP / Postal Code:</th>
+                                <td>
+                                    <input type="text" name="{$loc.id}_zip" value="{$newLocation.zip}" class="glm-form-text-input-medium">
+                                </td>
+                            </tr>
+                            <tr>
+                                <th>Country:</th>
+                                <td>
+                                    <select id="country_{$loc.id}" name="{$loc.id}_country">
+                        {foreach from=$loc.country.list item=v}
+                                        <option value="{$v.value}"{if $v.default} selected="selected"{/if}>
+                                            {$v.name} {$v.value}
+                                        </option>
+                        {/foreach}
+                                    </select>
+                                </td>
+                            </tr>
+                            <tr>
+                                <th>Region:</th>
+                                <td>
+                                    <select name="{$loc.id}_region">
+                                        <option value="0"></option>
+                        {foreach from=$loc.region.list item=v}
+                                        <option value="{$v.value}"{if $v.default} selected="selected"{/if}>{$v.name}</option>
+                        {/foreach}
+                                    </select>
+                                </td>
+                            </tr>
+                            <tr>
+                                <th>Phone:</th>
+                                <td>
+                                    <input type="text" name="{$loc.id}_phone" value="{$loc.phone}" class="glm-form-text-input-medium">
+                                </td>
+                            </tr>
+                            <tr>
+                                <th>Web Address:</th>
+                                <td>
+                                    <input type="text" name="{$loc.id}_url" value="{$loc.url}" class="glm-form-text-input-medium">
+                                </td>
+                            </tr>
+                            <tr>
+                                <th>Email Address:</th>
+                                <td>
+                                    <input type="text" name="{$loc.id}_email" value="{$loc.email}" class="glm-form-text-input-medium">
+                                </td>
+                            </tr>
+                            <tr>
+                                <th>Contact Name:</th>
+                                <td>
+                                    First: <input type="text" name="{$loc.ID}_contact_fname" value="{$loc.contact_fname}" class="glm-form-text-input-small">
+                                    Last:  <input type="text" name="{$loc.ID}_contact_lname" value="{$loc.contact_lname}" class="glm-form-text-input-small">
+                                </td>
+                            </tr>
+                            <tr>
+                                <th>Contact Phone:</th>
+                                <td>
+                                    <input type="text" name="{$loc.ID}_contact_phone" value="{$loc.contact_phone}" class="glm-form-text-input-medium">
+                                </td>
+                            </tr>
+                            <tr>
+                                <th>Contact Email:</th>
+                                <td>
+                                    <input type="text" name="{$loc.ID}_contact_email" value="{$loc.contact_email}" class="glm-form-text-input-medium">
+                                </td>
+                            </tr>
+
+                        </table>
                     </td>
-                </tr>
-                <tr>
-                    <th>Address:</th>
                     <td>
-                        <input type="text" name="{$loc.id}_address" value="{$loc.fieldData.address}" class="glm-form-text-input-medium">
+                        <table width="100%">
+                            <tr>
+                                <th>Location:</th>
+                                <td>
+                                    <input id="glmLat_{$loc.id}" name="lat" type="hidden" value="{$memberInfo.lat}">
+                                    <input id="glmLng_{$loc.id}" name="lon" type="hidden" value="{$memberInfo.lon}">
+                                    <div id="glm-estimate-location_{$loc.id}" class="button button-secondary">Map Location Using Above Address</div>
+                                    <p>
+                                        <div id="locationMap_{$loc.id}" class="glm-map-edit-small">(map loads here)</div>
+                                        <span id="mapPosition_{$loc.id}">Lat {$newLocation.lat}, Lon {$newLocation.lon}</span>
+                                    </p>
+                                </td>
+                            </tr>
+                        </table>
                     </td>
                 </tr>
-                
-    
+
     {/foreach}
 {/if}
             </table>
         </td>
     </tr>
-
 </table>
-        
+
 <!-- Add/Edit Location Template -->
-    
+
 <table id="addLocationTemplate" class="glm-hidden">
     <tr class="location_{ newLocID }">
         <td>
             <input type="hidden" name="locID[{ newLocID }]" value="{ newLocID }">
             <input type="hidden" name="{ newLocID }_event" value="{$event.fieldData.id}"> <!-- required to have event id with prefix -->
             <table width="100%">
+                <tr>
                 <tr>
                     <th>Location Name:</th>
                     <td>
                 <tr>
                     <th>Address:</th>
                     <td>
-                        <input type="text" name="{ newLocID }_address" value="{$newLocation.fieldData.address}" class="glm-form-text-input-medium">
+                        <input id="address_{ newLocID }" type="text" name="{ newLocID }_address" value="{$newLocation.fieldData.address}" class="glm-form-text-input-medium">
+                    </td>
+                </tr>
+                <tr>
+                    <th>City</th>
+                    <td class="glm-item-container">
+                        <!--  Add new city dialog -->
+                        <div id="newCityButton" class="button button-secondary glm-right">Add a new City</div>
+                        <div id="newCityDialog" class="glm-dialog-box" title="Enter a New City">
+                            <table class="glm-admin-table">
+                                <tr>
+                                    <th class="glm-required">City Name:</th>
+                                    <td id="newCityNameTD">
+                                        <input id="newCityName" type="text" name="newCityName" class="glm-form-text-input">
+                                        <div id="newCityNameRequired"></div>
+                                    </td>
+                                </tr>
+                            </table>
+                            <p><span class="glm-required">*</span> Required</p>
+                            <a id="newCityCancel" class="button button-primary glm-right">Cancel</a>
+                            <input id="newCitySubmit" type="submit" value="Add new City">
+                        </div>
+                        <!-- City Selection -->
+                        <input id="cityName" type="hidden" name="newCityName" value=""><!-- this field is only used if adding a new city to pass the new name -->
+                        <select id="city_{ newLocID }" 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>
+            {/foreach}
+                        </select>
+                    </td>
+                </tr>
+                <tr>
+                    <th>State:</th>
+                    <td>
+                        <select  id="state_{ newLocID }" name="{ newLocID }_state">
+            {foreach from=$newLocation.fieldData.state.list item=v}
+                            <option value="{$v.value}"{if $v.default} selected="selected"{/if}>
+                                {$v.name}
+                            </option>
+            {/foreach}
+                        </select>
+                    </td>
+                </tr>
+                <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">
+                    </td>
+                </tr>
+                <tr>
+                    <th>Country:</th>
+                    <td>
+                        <select id="country_{ 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}
+                            </option>
+            {/foreach}
+                        </select>
+                    </td>
+                </tr>
+                <tr>
+                    <th>Region:</th>
+                    <td>
+                        <select name="{ newLocID }_region">
+                            <option value="0"></option>
+            {foreach from=$newLocation.fieldData.region.list item=v}
+                            <option value="{$v.value}"{if $v.default} selected="selected"{/if}>{$v.name}</option>
+            {/foreach}
+                        </select>
+                    </td>
+                </tr>
+                <tr>
+                    <th>Phone:</th>
+                    <td>
+                        <input type="text" name="{ newLocID }_phone" value="{$newLocation.fieldData.phone}" class="glm-form-text-input-medium">
+                    </td>
+                </tr>
+                <tr>
+                    <th>Web Address:</th>
+                    <td>
+                        <input type="text" name="{ newLocID }_url" value="{$newLocation.fieldData.url}" class="glm-form-text-input-medium">
+                    </td>
+                </tr>
+                <tr>
+                    <th>Email Address:</th>
+                    <td>
+                        <input type="text" name="{ newLocID }_email" value="{$newLocation.fieldData.email}" class="glm-form-text-input-medium">
+                    </td>
+                </tr>
+                <tr>
+                    <th>Contact Name:</th>
+                    <td>
+                        First: <input type="text" name="{ newLocID }_contact_fname" value="{$newLocation.fieldData.contact_fname}" class="glm-form-text-input-small">
+                        Last:  <input type="text" name="{ newLocID }_contact_lname" value="{$newLocation.fieldData.contact_lname}" class="glm-form-text-input-small">
+                    </td>
+                </tr>
+                <tr>
+                    <th>Contact Phone:</th>
+                    <td>
+                        <input type="text" name="{ newLocID }_contact_phone" value="{$newLocation.fieldData.contact_phone}" class="glm-form-text-input-medium">
+                    </td>
+                </tr>
+                <tr>
+                    <th>Contact Email:</th>
+                    <td>
+                        <input type="text" name="{ newLocID }_contact_email" value="{$newLocation.fieldData.contact_email}" class="glm-form-text-input-medium">
+                    </td>
+                </tr>
+            </table>
+        </td>
+        <td>
+            <table width="100%">
+                <tr>
+                    <th>Location:</th>
+                    <td>
+                        <input id="glmLat_{ newLocID }" name="lat" type="hidden" value="{$newLocation.fieldData.lat}">
+                        <input id="glmLng_{ newLocID }" name="lon" type="hidden" value="{$newLocation.fieldData.lon}">
+                        <div id="glm-estimate-location_{ newLocID }" class="button button-secondary">Map Location Using Address</div>
+                        <p>
+                            <div id="locationMap_{ newLocID }" class="glm-map-edit">(map loads here)</div>
+                            <span id="mapPosition_{ newLocID }">Lat {$newLocation.fieldData.lat}, Lon {$newLocation.fieldData.lon}</span>
+                        </p>
                     </td>
                 </tr>
-            
-            
-            
             </table>
         </td>
     </tr>
index de25a08..0530222 100644 (file)
@@ -20,7 +20,7 @@
                         <input type="hidden" name="{$r.id}_event" value="{$event.fieldData.id}"> <!-- required to have event id with prefix -->
                         <input id="{$r.id}_recurUpdated" type="hidden" name="recurUpdated[{$r.id}]" value="0">
                         <table width="100%">
-                            <tr><th></th><th>First occurrence of event</th></tr>
+                            <tr><th></th><th>First occurrence for this schedule</th></tr>
                             <tr>
                                 <th>All Day Event:</th>
                                 <td>