Skip to content

Commit

Permalink
Update store locator JS
Browse files Browse the repository at this point in the history
closes dynamic#129
closes dynamic#120
  • Loading branch information
jsirish committed Feb 11, 2017
1 parent 7142d76 commit b3a43fd
Show file tree
Hide file tree
Showing 56 changed files with 5,027 additions and 38 deletions.
56 changes: 39 additions & 17 deletions code/pages/Locator.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ public function getCMSFields()
$fields->addFieldsToTab('Root.Settings', array(
HeaderField::create('DisplayOptions', 'Display Options', 3),
OptionsetField::create('Unit', 'Unit of measure', array('m' => 'Miles', 'km' => 'Kilometers')),
CheckboxField::create('AutoGeocode', 'Auto Geocode - Automatically filter map results based on user location')
->setDescription('Note: if any locations are set as featured, the auto geocode is automatically disabled.'),
CheckboxField::create('ModalWindow', 'Modal Window - Show Map results in a modal window'),
//CheckboxField::create('AutoGeocode', 'Auto Geocode - Automatically filter map results based on user location')
// ->setDescription('Note: if any locations are set as featured, the auto geocode is automatically disabled.'),
//CheckboxField::create('ModalWindow', 'Modal Window - Show Map results in a modal window'),
));

// Filter categories
Expand Down Expand Up @@ -199,6 +199,11 @@ class Locator_Controller extends Page_Controller
*/
private static $bootstrapify = true;

/**
* @var int
*/
private static $limit = 50;

/**
* @var DataList|ArrayList
*/
Expand All @@ -221,8 +226,10 @@ public function init()
Requirements::css('locator/css/map.css');
Requirements::javascript('framework/thirdparty/jquery/jquery.js');
Requirements::javascript('https://maps.google.com/maps/api/js?key=' . $key);
Requirements::javascript('locator/thirdparty/handlebars/handlebars-v1.3.0.js');
Requirements::javascript('locator/thirdparty/jquery-store-locator/js/jquery.storelocator.js');
//Requirements::javascript('locator/thirdparty/handlebars/handlebars-v1.3.0.js');
//Requirements::javascript('locator/thirdparty/jquery-store-locator/js/jquery.storelocator.js');
Requirements::javascript('locator/thirdparty/jquery-store-locator-plugin/assets/js/libs/handlebars.min.js');
Requirements::javascript('locator/thirdparty/jquery-store-locator-plugin/assets/js/plugins/storeLocator/jquery.storelocator.js');

$featuredInList = ($locations->filter('Featured', true)->count() > 0);
$defaultCoords = $this->getAddressSearchCoords() ? $this->getAddressSearchCoords() : '';
Expand All @@ -234,12 +241,13 @@ public function init()

// map config based on user input in Settings tab
// AutoGeocode or Full Map
$limit = Config::inst()->get('Locator_Controller', 'limit');
if ($this->data()->AutoGeocode) {
$load = $featuredInList || $defaultCoords != '' || $isChrome
? 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,'
? 'autoGeocode: false, fullMapStart: true, storeLimit: ' . $limit . ', maxDistance: true,'
: 'autoGeocode: true, fullMapStart: false,';
} else {
$load = 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,';
$load = 'autoGeocode: false, fullMapStart: true, storeLimit: ' . $limit . ', maxDistance: true,';
}

$listTemplatePath = Config::inst()->get('Locator_Controller', 'list_template_path');
Expand All @@ -248,7 +256,7 @@ public function init()
// in page or modal
$modal = ($this->data()->ModalWindow) ? 'modalWindow: true' : 'modalWindow: false';

$kilometer = ($this->data()->Unit == 'km') ? 'lengthUnit: "km"' : 'lengthUnit: "m"';
$kilometer = ($this->data()->Unit == 'km') ? "lengthUnit: 'km'" : "lengthUnit: 'm'";

// pass GET variables to xml action
$vars = $this->request->getVars();
Expand All @@ -259,6 +267,7 @@ public function init()
$url .= '?' . http_build_query($vars);
}
$link = $this->Link() . 'xml.xml' . $url;
$link = Controller::join_links($this->AbsoluteLink(), 'xml.xml', $url);

// init map
Requirements::customScript("
Expand All @@ -269,17 +278,25 @@ public function init()
listTemplatePath: '" . $listTemplatePath . "',
infowindowTemplatePath: '" . $infowindowTemplatePath . "',
originMarker: true,
" . $modal . ',
' . $featured . ",
//" . $modal . ",
" . $featured . ",
slideMap: false,
zoomLevel: 0,
noForm: true,
distanceAlert: -1,
" . $kilometer . ',
' . $defaultCoords . '
" . $kilometer . ",
" . $defaultCoords . "
mapID: 'map',
locationList: 'loc-list',
mapSettings: {
zoom: 12,
mapTypeId: google.maps.MapTypeId.ROADMAP,
disableDoubleClickZoom: true,
scrollwheel: false,
navigationControl: false,
draggable: false
}
});
});
');
");
}
}

Expand All @@ -290,7 +307,8 @@ public function init()
*/
public function index(SS_HTTPRequest $request)
{
$locations = $this->getLocations();
$limit = Config::inst()->get('Locator_Controller', 'limit');
$locations = $this->getLocations()->limit($limit);

return $this->customise(array(
'Locations' => $locations,
Expand All @@ -305,7 +323,11 @@ public function index(SS_HTTPRequest $request)
*/
public function xml(SS_HTTPRequest $request)
{
$locations = $this->getLocations();
if ($this->request->getVar('Address') != '') {
$limit = Config::inst()->get('Locator_Controller', 'limit');
$locations = $this->getLocations()->limit($limit);
}
$locations = ArrayList::create();

return $this->customise(array(
'Locations' => $locations,
Expand Down
28 changes: 14 additions & 14 deletions css/map.css
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@
/* ===
Results List
=== */
#loc-list
.loc-list
{
float: left;
height: 530px;
width: 25%;
overflow: auto;
}

#loc-list ul
.loc-list ul
{
display: block;
clear: left;
Expand All @@ -86,7 +86,7 @@
width: 100%;
}

#loc-list .list-label
.loc-list .list-label
{
float: left;
margin: 10px 0 0 6px;
Expand All @@ -98,26 +98,26 @@
font-weight: bold;
}

#loc-list .list-details
.loc-list .list-details
{
float: left;
margin-left: 6px;
width: 165px;
}

#loc-list .list-content
.loc-list .list-content
{
padding: 10px;
}

#loc-list .loc-dist
.loc-list .loc-dist
{
font-weight: bold;
font-style: italic;
color: #8e8e8e;
}

#loc-list li
.loc-list li
{
display: block;
clear: left;
Expand All @@ -128,10 +128,10 @@
border: 1px solid #fff; /* Adding this to prevent moving li elements when adding the list-focus class*/
}

#loc-list li:first-child {margin-top: 0px;}
.loc-list li:first-child {margin-top: 0px;}


#loc-list .list-focus
.loc-list .list-focus
{
border: 1px solid rgba(82,168,236,0.9);
-moz-box-shadow: 0 0 8px rgba(82,168,236,0.7);
Expand Down Expand Up @@ -215,7 +215,7 @@

@media only screen and (max-width: 960px) {

#loc-list {
.loc-list {

}

Expand All @@ -231,15 +231,15 @@

@media only screen and (min-width: 641px) and (max-width: 959px) {

#loc-list .list-label{
.loc-list .list-label{
margin-left: 0px;
}

#loc-list .list-content {
.loc-list .list-content {
padding: 10px 0px;
}

#loc-list .list-details {
.loc-list .list-details {
width: 140px;
}

Expand All @@ -248,7 +248,7 @@

@media only screen and (max-width: 640px) {

#loc-list {
.loc-list {
width: 100%;
height: auto;
}
Expand Down
11 changes: 4 additions & 7 deletions templates/Layout/Locator.ss
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
<div class="content-container unit size3of4 lastUnit">
<h1>$Title</h1>
<% if $Content %><div class="typography">$Content</div><% end_if %>
<div class="form-container">
$LocationSearch
</div>
<% if $Locations %>
<p>$Locations.Count locations</p>
<div id="form-container">
$LocationSearch
</div>

<div id="map-container">
<div id="map"></div>
<div id="loc-list">
<div class="loc-list">
<ul id="list">
<li><img src="locator/images/ajax-loader.gif" class="loading"></li>
</ul>
</div>
</div>
Expand Down
Loading

0 comments on commit b3a43fd

Please sign in to comment.