From: Chuck Scott Date: Fri, 11 Mar 2016 20:51:31 +0000 (-0500) Subject: Now have some location data working. X-Git-Tag: v1.0.0^2~168 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=d774a60ec6d64611ef5ffa62b9cb7387133c8548;p=WP-Plugins%2Fglm-member-db-events.git Now have some location data working. --- diff --git a/classes/data/dataLocations.php b/classes/data/dataLocations.php index 5c094d1..0ae6985 100644 --- a/classes/data/dataLocations.php +++ b/classes/data/dataLocations.php @@ -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' ), diff --git a/models/admin/events/list.php b/models/admin/events/list.php index dcf2b5f..f1a77c3 100644 --- a/models/admin/events/list.php +++ b/models/admin/events/list.php @@ -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); diff --git a/views/admin/events/edit.html b/views/admin/events/edit.html index 84bce9d..95ce313 100644 --- a/views/admin/events/edit.html +++ b/views/admin/events/edit.html @@ -182,6 +182,13 @@ // 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 @@ -194,7 +201,7 @@ // Otherwise, we'll say we now have our first location } else { - numbLoctions++; + numbLocations++; } locTemp = locTemp + $('#addLocationTemplate').html(); @@ -203,18 +210,33 @@ // 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 **** } /* @@ -516,7 +538,171 @@ } }); + /* + * 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(''); + $('#city').val(-1); + $('#newCityNameTD').append(''); + 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.'); + } + }); + + + } + }); diff --git a/views/admin/events/editLocation.html b/views/admin/events/editLocation.html index e5da32b..9d18ce0 100644 --- a/views/admin/events/editLocation.html +++ b/views/admin/events/editLocation.html @@ -1,6 +1,9 @@ + + + - + + - - - - - + {/foreach} {/if}
@@ -13,37 +16,170 @@ {if $locations} {foreach $locations as $loc} - -
Location Name:

- + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Location Name: + +
Address: + +
City + +
Add a new City
+
+ + + + + +
City Name: + +
+
+

* Required

+ Cancel + +
+ + + +
State: + +
ZIP / Postal Code: + +
Country: + +
Region: + +
Phone: + +
Web Address: + +
Email Address: + +
Contact Name: + First: + Last: +
Contact Phone: + +
Contact Email: + +
Address: - + + + + + +
Location: + + +
Map Location Using Above Address
+

+

(map loads here)
+ Lat {$newLocation.lat}, Lon {$newLocation.lon} +

+
- - + - + + diff --git a/views/admin/events/editSchedule.html b/views/admin/events/editSchedule.html index de25a08..0530222 100644 --- a/views/admin/events/editSchedule.html +++ b/views/admin/events/editSchedule.html @@ -20,7 +20,7 @@
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Location Name: @@ -53,12 +189,134 @@
Address: - + +
City + +
Add a new City
+
+ + + + + +
City Name: + +
+
+

* Required

+ Cancel + +
+ + + +
State: + +
ZIP / Postal Code: + +
Country: + +
Region: + +
Phone: + +
Web Address: + +
Email Address: + +
Contact Name: + First: + Last: +
Contact Phone: + +
Contact Email: + +
+
+ + + + - - -
Location: + + +
Map Location Using Address
+

+

(map loads here)
+ Lat {$newLocation.fieldData.lat}, Lon {$newLocation.fieldData.lon} +

- +
First occurrence of event
First occurrence for this schedule
All Day Event: