Skip to content

Commit

Permalink
Adding GeoCoder field.
Browse files Browse the repository at this point in the history
  • Loading branch information
Stikki committed May 12, 2014
1 parent e22ffaa commit c701014
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lang/en_US.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@
$lang['fielddef_FileUpload'] = 'File Upload';
// ColorPicker
$lang['fielddef_ColorPicker'] = 'Color Picker';
// GeoCoder
$lang['fielddef_GeoCoder'] = 'Geocoder';

/* Instructions */
$lang['fielddef_allow_help'] = 'Specify a comma seprated list of file extensions that are allowed. For example: pdf,gif,jpeg,jpg (keep lowercase)';
Expand Down
1 change: 0 additions & 1 deletion lib/fielddefs/ColorPicker/input.ColorPicker.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
});
}
})
});
</script>

Expand Down
15 changes: 15 additions & 0 deletions lib/fielddefs/GeoCoder/admin.GeoCoder.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<div class="pageoverflow">
<p class="pagetext">{$fielddef->ModLang('address_field')}:</p>
<p class="pageinput">
{$themeObject->DisplayImage('icons/system/info.gif')}<em> {$fielddef->ModLang('fielddef_address_field_help')}</em><br />
{html_options name="{$actionid}custom_input[address_field]" options=$fielddef->Siblings() selected=$fielddef->GetOptionValue('address_field')}
</p>
</div>

<div class="pageoverflow">
<p class="pagetext">{$fielddef->ModLang('size')}:</p>
<p class="pageinput">
{$themeObject->DisplayImage('icons/system/info.gif')}<em> {$fielddef->ModLang('fielddef_size_help')}</em><br />
<input type="text" name="{$actionid}custom_input[size]" value="{$fielddef->GetOptionValue('size', 20)}" />
</p>
</div>
46 changes: 46 additions & 0 deletions lib/fielddefs/GeoCoder/input.GeoCoder.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<div class="pageoverflow">
<p class="pagetext">{$fielddef->GetName()}{if $fielddef->IsRequired()}*{/if}:</p>
<div class="pageinput">
{if $fielddef->GetDesc()}({$fielddef->GetDesc()})<br />{/if}
{$fld_value = $fielddef->GetValue("array")}
<input type="text" name="{$actionid}customfield[{$fielddef->GetId()}][]" id="{$actionid}customfield_{$fielddef->GetId()}_lat" value="{$fld_value[0]}" size="{$fielddef->GetOptionValue('size')}" /><br />
<input type="text" name="{$actionid}customfield[{$fielddef->GetId()}][]" id="{$actionid}customfield_{$fielddef->GetId()}_lon" value="{$fld_value[1]}" size="{$fielddef->GetOptionValue('size')}" /><br />
<button id="{$actionid}customfield_{$fielddef->GetId()}_lookup">Lookup</button>
</div>

<script type="text/javascript">
jQuery(document).ready(function($) {
$("#{$actionid}customfield_{$fielddef->GetId()}_lookup").on("click", function(e) {
$.ajaxSetup({ cache: true });
$.getScript('https://www.google.com/jsapi', function() {
google.load('maps', '3', {
other_params: 'sensor=false',
callback: function () {
// Init GeoCoder
var geocoder = new google.maps.Geocoder();
// Marker setup
geocoder.geocode({ 'address' : '{$fielddef->Address()}' }, function(results, status) {
if(status === google.maps.GeocoderStatus.OK) {
$("#{$actionid}customfield_{$fielddef->GetId()}_lat").val(results[0].geometry.location.d);
$("#{$actionid}customfield_{$fielddef->GetId()}_lon").val(results[0].geometry.location.e);
console.log(results[0].geometry.location);
}
});
}
});
});
e.preventDefault();
});
});
</script>

</div>
69 changes: 69 additions & 0 deletions lib/fielddefs/GeoCoder/listit2fd.GeoCoder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php
#-------------------------------------------------------------------------
#
# Author: Ben Malen, <[email protected]>
# Co-Maintainer: Simon Radford, <[email protected]>
# Web: www.conceptfactory.com.au
#
#-------------------------------------------------------------------------
#
# Maintainer since 2011: Jonathan Schmid, <[email protected]>
# Web: www.jonathanschmid.de
#
#-------------------------------------------------------------------------
#
# Some wackos started destroying stuff since 2012:
#
# Tapio Löytty, <[email protected]>
# Web: www.orange-media.fi
#
# Goran Ilic, <[email protected]>
# Web: www.ich-mach-das.at
#
#-------------------------------------------------------------------------
#
# ListIt is a CMS Made Simple module that enables the web developer to create
# multiple lists throughout a site. It can be duplicated and given friendly
# names for easier client maintenance.
#
#-------------------------------------------------------------------------

class listit2fd_GeoCoder extends ListIt2FielddefBase
{
public function __construct(&$db_info, $caller_object)
{
parent::__construct($db_info, $caller_object);

$this->SetFriendlyType($this->ModLang('fielddef_'.$this->GetType()));
}

public function Siblings()
{
$caller = $this->GetModuleInstance(true);
$all_fields = $caller->GetFieldDefs();

$output = array();
foreach($all_fields as $field) {

if($field->GetId() == $this->GetId())
continue;

$output[$field->GetId()] = $field->GetName();
}

return $output;
}

public function Address()
{
foreach($this->GetParentArray() as $field) {

if($field->GetId() == $this->GetOptionValue('address_field'))
return $field->GetValue(self::TYPE_STRING);
}

return null;
}

} // end of class
?>

0 comments on commit c701014

Please sign in to comment.