Skip to content
116 changes: 63 additions & 53 deletions assets/addresslocationfield.publish.css
Original file line number Diff line number Diff line change
@@ -1,83 +1,93 @@
div.field-addresslocation {
clear: both;
padding-bottom: 1em;
border-bottom: 1px solid #ddc;
}
div.field-addresslocation:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
div.field-addresslocation p {
border-bottom: 1px solid #ddc;
padding-bottom: 0.3em;
margin-bottom: 1em;
margin-top: 1.5em;
color: #2f77eb;
margin: 0 0 1.5rem;
}

div.field-addresslocation label {
float: left;
margin-bottom: 0.5em;
width: 47%;
margin-right: 3%;
}
div.field-addresslocation label.street {
width: 97%;
box-sizing: border-box;
margin: 0 0 3rem;
padding-right: 3rem;
width: 50%;
}
div.field-addresslocation label.street,
div.field-addresslocation label.region,
div.field-addresslocation label.latitude,
div.field-addresslocation label.country {
}
div.field-addresslocation label.country {

@media (max-width: 767px) {
div.field-addresslocation label {
width: 100%;
}
}
div.field-addresslocation label.city,
div.field-addresslocation label.postal-code,
div.field-addresslocation label.longitude {

div.field-addresslocation label.street {
width: 100%;
}

div.field-addresslocation label.latitude input,
div.field-addresslocation label.longitude input {
color: #7F7F7F;
}

div.field-addresslocation label input {
clear: both;
}
div.field-addresslocation label.locate {

div.field-addresslocation div.locate {
display: flex;
flex-direction: row;
align-items: flex-start;
justify-content: flex-start;
margin: 0 0 2em;
width: 100%;
margin-top: 1em;
}
div.field-addresslocation label.locate a.mapswitch {

div.field-addresslocation div.locate a.mapswitch {
float: right;
text-decoration: none;
}
div.field-addresslocation label.locate input {
float: left;
width: 47%;
clear: none;
margin-right: 3%;

div.field-addresslocation div.locate input {
color: #fff;
font-size: 1.1rem;
text-transform: uppercase;
line-height: 1.6rem;
margin: 0 1rem 0 0;
padding: 1rem 1.5rem;
border-radius: 5px;
border: none;
background: #2f77eb;
width: auto;
cursor: pointer;
}

div.field-addresslocation div.main {
width: 60%;
float: left;
div.field-addresslocation div.locate input:not(:disabled):hover {
background: #121212;
}
div.field-addresslocation div.main.map {
float: right;
height: 220px;
width: 40%;

div.field-addresslocation div.locate input:disabled {
opacity: 0.5;
pointer-events: none;
}

div.field-addresslocation div.sidebar {
width: 100%;
float:left;
div.field-addresslocation div.main-wrapper {
border-radius: 5px;
-webkit-border-radius: 5px;
margin: 0 0 3rem;
padding: 1.5rem;
border: 1px solid #d3dce2;
}

div.field-addresslocation div.address {
display: flex;
flex-direction: row;
align-items: flex-start;
justify-content: flex-start;
flex-wrap: wrap;
width: calc(100% + 3rem);
}
div.field-addresslocation div.sidebar.map {

div.field-addresslocation div.map {
width: 100%;
margin-top: 15px;
height: 200px;
float: left;
}

div.field-addresslocation div.gm-style-cc {
display: none;
}
18 changes: 8 additions & 10 deletions assets/addresslocationfield.publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@
map.setCenter(latlng);
//map.setZoom(16);
SetMarker(latlng);
helpers.toggleFieldState(field.find('label.locate input[name="locate"]'), true);
helpers.toggleFieldState(field.find('div.locate input[name="locate"]'), true);
}
else{
helpers.toggleFieldState(field.find('label.locate input[name="clear"]'), true);
helpers.toggleFieldState(field.find('div.locate input[name="clear"]'), true);
}

field.find('label.locate input[name="clear"]').click(function(ev){
field.find('div.locate input[name="clear"]').click(function(ev){

ev.preventDefault();

Expand All @@ -57,16 +57,15 @@
map.setCenter(new google.maps.LatLng(0,0));
map.setZoom(1);

field.find('label.locate input[name="locate"]').removeAttr('disabled');
field.find('div.locate input[name="locate"]').removeAttr('disabled');

});

if(field.find('div.address').hasClass('sidebar')){

var a = $('<a class="mapswitch" href="#">[-] Hide Map</a>').appendTo('label.locate')
var a = $('<a class="mapswitch" href="#">[-] Hide Map</a>').appendTo('div.locate')

field.delegate('label.locate a.mapswitch', 'click', function(ev){
console.log('clicked');
field.delegate('div.locate a.mapswitch', 'click', function(ev){
ev.preventDefault();
var map = field.find('div.map');
if(map.hasClass('open')){
Expand All @@ -81,7 +80,7 @@
}


field.find('label.locate input[name="locate"]').click(function(ev){
field.find('div.locate input[name="locate"]').click(function(ev){

//Reassign field to stop mime warning/error
var field = $('div.field-addresslocation');
Expand Down Expand Up @@ -116,7 +115,7 @@
});

field.on('focus', 'input[type=text]', function(ev){
var $btn = field.find('label.locate input[name="locate"]')
var $btn = field.find('div.locate input[name="locate"]')
if ($btn.attr('disabled')) {
helpers.toggleFieldState($btn);
}
Expand All @@ -125,7 +124,6 @@
}
function GeocodeAddress(address, success, fail){
geocoder.geocode({"address":address}, function(results, status){
console.log(status, results);
if(status == google.maps.GeocoderStatus.OK){
success(results[0]);
}else{
Expand Down
82 changes: 53 additions & 29 deletions extension.driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,30 @@ public function addCustomPreferenceFieldsets($context) {

public function uninstall()
{
Symphony::Database()->query("DROP TABLE `tbl_fields_addresslocation`");
return Symphony::Database()
->drop('tbl_fields_addresslocation')
->ifExists()
->execute()
->success();
}

public function update($previousVersion = false){
$addresslocation_entry_tables = Symphony::Database()->fetchCol("field_id", "SELECT `field_id` FROM `tbl_fields_addresslocation`");
$addresslocation_entry_tables = Symphony::Database()
->select(['field_id'])
->from('tbl_fields_addresslocation')
->execute()
->column('field_id');

if(version_compare($previousVersion, '1.2.1', '<')){
if(is_array($addresslocation_entry_tables) && !empty($addresslocation_entry_tables))
{
foreach($addresslocation_entry_tables as $field)
{
Symphony::Database()->query(sprintf(
"ALTER TABLE `tbl_entries_data_%d` ADD `result_data` blob",
$field
));
Symphony::Database()
->alter("tbl_entries_data_$field")
->add(['result_data' => 'blob'])
->execute()
->success();
}
}
}
Expand All @@ -51,23 +60,28 @@ public function update($previousVersion = false){
{
foreach($addresslocation_entry_tables as $field)
{
Symphony::Database()->query(sprintf(
"ALTER TABLE `tbl_entries_data_%d` ADD `neighborhood` varchar(255), ADD `neighborhood_handle` varchar(255)",
$field
));
Symphony::Database()
->alter("tbl_entries_data_$field")
->add([
'neighborhood' => 'varchar(255)',
'neighborhood_handle' => 'varchar(255)',
])
->execute()
->success();
}
}
}

if(version_compare($previousVersion, '1.2.3', '<')){
if(is_array($addresslocation_entry_tables) && !empty($addresslocation_entry_tables))
{
foreach($addresslocation_entry_tables as $field)
{
Symphony::Database()->query(sprintf(
"ALTER TABLE `tbl_entries_data_%d` MODIFY COLUMN `result_data` blob",
$field
));
Symphony::Dabatase()
->alter("tbl_entries_data_$field")
->modify(['result_data' => 'blob'])
->execute()
->success();
}
}
}
Expand All @@ -77,24 +91,34 @@ public function update($previousVersion = false){

public function install()
{
return Symphony::Database()->query("CREATE TABLE `tbl_fields_addresslocation` (
`id` int(11) unsigned NOT NULL auto_increment,
`field_id` int(11) unsigned NOT NULL,
`street_label` varchar(80) NOT NULL,
`city_label` varchar(80) NOT NULL,
`region_label` varchar(80) NOT NULL,
`postal_code_label` varchar(80) NOT NULL,
`country_label` varchar(80) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `field_id` (`field_id`)
) TYPE=MyISAM");
return Symphony::Database()
->create('tbl_fields_addresslocation')
->ifNotExists()
->fields([
'id' => [
'type' => 'int(11)',
'auto' => true,
],
'field_id' => 'int(11)',
'street_label' => 'varchar(80)',
'city_label' => 'varchar(80)',
'region_label' => 'varchar(80)',
'postal_code_label' => 'varchar(80)',
'country_label' => 'varchar(80)',
])
->keys([
'id' => 'primary',
'field_id' => 'unique',
])
->execute()
->success();
}

/*
Modified from:
http://www.kevinbradwick.co.uk/developer/php/free-to-script-to-calculate-the-radius-of-a-coordinate-using-latitude-and-longitude
*/
public function geoRadius($lat, $lng, $rad, $kilometers=false)
public function geoRadius($lat, $lng, $rad, $kilometers = false)
{
$radius = ($kilometers) ? ($rad * 0.621371192) : $rad;

Expand All @@ -106,7 +130,7 @@ public function geoRadius($lat, $lng, $rad, $kilometers=false)
(float)$latMAX = $lat + $usrRLAT;

// Longitude calculation
(float)$mpdLON = 69.1703234283616 * cos($lat * (pi/180));
(float)$mpdLON = 69.1703234283616 * cos($lat * (pi()/180));
(float)$dpmLON = 1 / $mpdLON; // degrees per mile longintude
$usrRLON = $dpmLON * $radius;

Expand Down Expand Up @@ -145,4 +169,4 @@ public function geoDistance($lat1, $lon1, $lat2, $lon2, $unit)

}

?>
?>
8 changes: 6 additions & 2 deletions extension.meta.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<extension id="addresslocationfield" status="released" xmlns="http://getsymphony.com/schemas/extension/1.0">
<name>Address Location Field</name>
<name>Field: Address Location</name>
<description>Geocode an address, then refine the latlng returned for precision.</description>
<repo type="github">https://github.com/designermonkey/addresslocationfield</repo>
<url type="discuss">http://getsymphony.com/discuss/thread/70238/</url>
Expand All @@ -14,6 +14,10 @@
</author>
</authors>
<releases>
<release version="2.0.0" date="TBA" min="4.0.0" max="4.x.x" php-min="5.6.x" php-max="7.1.x">
- Update for Symphony 4.x
- Code refactoring for Database and EQFA
</release>
<release version="1.4.0" date="2018-12-10" min="2.3" max="2.7.x">
- Add preferences UI (#22)
</release>
Expand All @@ -37,4 +41,4 @@
</release>
<release version="1" date="2011-05-31" min="2.2" max="2.2.5" />
</releases>
</extension>
</extension>
Loading