Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 85f6cfd93e7929cb86ef6db27f6cc8cc13a90e5f
Author: Jason Irish <[email protected]>
Date:   Sat Nov 16 17:09:21 2013 -0600

    clean up

commit 1c4aca7b7f578a064b4d7922a7ec533ac3cf5258
Author: Jason Irish <[email protected]>
Date:   Sat Nov 16 17:00:46 2013 -0600

    template and css clean up

    removed datasource option. Locator clean up, added Category GridField.

commit fabbb6268c603974478a3d3afca809989b628e78
Author: Jason Irish <[email protected]>
Date:   Sat Nov 16 15:55:25 2013 -0600

    create LocationSearch in Locator_Controller

    model cleanup. added categoryID setting to store locator js
  • Loading branch information
jsirish committed Nov 16, 2013
1 parent 15fb3c0 commit ebd504b
Show file tree
Hide file tree
Showing 11 changed files with 178 additions and 431 deletions.
Empty file removed .gitmodules
Empty file.
40 changes: 28 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,49 @@
## Overview
Overview
=================================

The Locator module displays a searchable map of locations. You can choose whether to show all locations on load, or enable auto geocoding to filter the initial list based on the visitor's location. Uses the jQuery Store Locator plugin for map display.

## Installation ##
Composer Installation
=================================

* cd ~/Sites/yourSilverStripeProject/
* git clone [email protected]:dynamic/SilverStripe-Locator-Module.git locator
* Run `/dev/build`
`"require": { "dynamic/silverstripe-locator": "dev-master }`

## Requirements ##
Add `locator` to your `.gitignore`

* SilverStripe 3.0+
Git Installation
=================================

`git clone [email protected]:dynamic/SilverStripe-Locator-Module.git locator`

`git clone [email protected]:ajshort/silverstripe-addressable.git addressable`

`rm -rf .git` (optional, to remove existing git repo)

Requirements
=================================

* SilverStripe 3.0.x
* Addressable Module by ajshort for Location geocoding - https://github.com/ajshort/silverstripe-addressable

## Use ##
Use
=================================

Create a Locator page in the CMS. Locations are managed under the Locations tab in the CMS via Model Admin. Simply enter the name and address of each location, and they will appear on the map.

## Maintainer Contact ##
Maintainer Contact
=================================

* Dynamic (<[email protected]>)

## Links ##
Links
=================================

* [SilverStripe Addressable](https://github.com/ajshort/silverstripe-addressable) by Andrew Short
* [jQuery Store Locator Plugin] (http://www.bjornblog.com/web/jquery-store-locator-plugin)
* [jQuery Store Locator Plugin](http://www.bjornblog.com/web/jquery-store-locator-plugin)
* [SilverStripe CMS](http://www.silverstripe.org/)

## License ##
License
=================================

Copyright (c) 2013, Dynamic Inc
All rights reserved.
Expand Down
23 changes: 14 additions & 9 deletions code/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ class Location extends DataObject {
'Title' => 'Varchar(255)',
'Website' => 'Varchar(255)',
'Phone' => 'Varchar(40)',
//'Fax' => 'Varchar(40)',
'EmailAddress' => 'Varchar(255)',
//'ShowInLocator' => 'Boolean',
'ShowInLocator' => 'Boolean',
);

static $has_one = array(
Expand Down Expand Up @@ -58,17 +57,23 @@ public function getCMSFields() {

$fields = parent::getCMSFields();

$fields->addFieldsToTab('Root.Main', array(
TextField::create('Title'),
// remove Main tab
$fields->removeByName('Main');

$fields->addFieldsToTab('Root.Info', array(
HeaderField::create('InfoHeader', 'Contact Information'),
TextField::create('Website'),
TextField::create('Phone'),
TextField::create('Fax'),
TextField::create('EmailAddress')//,
//CheckboxField::create('ShowInLocator', 'Show in Map results')
TextField::create('EmailAddress'),
TextField::create('Phone')
));

$fields->removeByName('ShowInLocator');
if (LocationCategory::get()->Count() > 0) {
$fields->insertAfter(DropDownField::create('CategoryID', 'Category', LocationCategory::get()->map('ID', 'Title'))->setEmptyString('-- select --'), 'Phone');
}

$fields->insertAfter(TextField::create('Title'), 'AddressHeader');
$fields->insertAfter(CheckboxField::create('ShowInLocator', 'Show on Map'), 'Country');

return $fields;
}

Expand Down
106 changes: 56 additions & 50 deletions code/Locator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,14 @@
class Locator extends Page {

static $db = array(
'FilterByCategory' => 'Boolean',
'AutoGeocode' => 'Boolean',
'ModalWindow' => 'Boolean'
);

static $defaults = array(
'FilterByCategory' => true,
'AutoGeocode' => true
);

// variable holder for custom data source url
public static $datasource = null;

// get custom data source url
public static function get_datasource() {
return self::$datasource;
}

// allow custom data source url to be set via _config.php
static public function set_datasource($datasource) {
self::$datasource = $datasource;
}

public static $singular_name = "Locator";
public static $plural_name = "Locators";
static $description = 'Find locations on a map';
Expand All @@ -34,36 +19,24 @@ public function getCMSFields() {
$fields = parent::getCMSFields();

// Locations Grid Field
if (!self::get_datasource()) {
$config = GridFieldConfig_RecordEditor::create();
//$config->addComponent(new GridFieldBulkEditingTools());
$fields->addFieldToTab("Root.Locations", GridField::create("Locations", "Locations", Location::get(), $config));
}
$config = GridFieldConfig_RecordEditor::create();
$fields->addFieldToTab("Root.Locations", GridField::create("Locations", "Locations", Location::get(), $config));

// Location categories
$gridField = new GridField('Categories', 'Categories', LocationCategory::get(), GridFieldConfig_RecordEditor::create());
$fields->addFieldToTab('Root.Categories', $gridField);

// Settings
$fields->addFieldsToTab('Root.Settings', array(
HeaderField::create('DisplayOptions', 'Display Options', 3),
CheckboxField::create('AutoGeocode', 'Auto Geocode - Automatically filter map results based on user location'),
CheckboxField::create('FilterByCategory', 'Filter by Category - allow user to filter map results by category'),
//CheckboxField::create('FilterByCategory', 'Filter by Category - allow user to filter map results by category'),
CheckboxField::create('ModalWindow', 'Modal Window - Show Map results in a modal window'),
HeaderField::create('DataOptions', 'Data Options', 3),
//HeaderField::create('DataOptions', 'Data Options', 3),
));

return $fields;
}

public function getAllCategories() {
return LocationCategory::get();
}

public function getDataLocation() {
if (self::get_datasource()) {
$dataLocation = self::get_datasource();
} else {
$dataLocation = getDataLocation();
}
return $dataLocation;
}

}

Expand Down Expand Up @@ -113,30 +86,63 @@ public function init() {
" . $modal . ",
slideMap: false,
zoomLevel: 0,
distanceAlert: 120
distanceAlert: 120,
formID: 'Form_LocationSearch',
inputID: 'Form_LocationSearch_address',
categoryID: 'Form_LocationSearch_category'
});
});
");

}

// Return all locations, render in XML file

/**
* Find all locations for map.
*
* By default, will return a XML feed of all locations marked "show in locator".
*
* If Locator::set_datasource('http:www.example.com') is set in _config.php, Locator will look
* for a JSON feed and return the results.
*
* @access public
* @return XML file
*/
public function xml() {
if (self::get_datasource()) {

$service = new RestfulService(self::get_datasource());

return $service->request()->getBody();

} else {

// grab all locations with coordinates
$Locations = Location::get()->exclude('Lat', 0);
$Locations = Location::get()->filter(array('ShowInLocator' => true))->exclude('Lat', 0);

return $this->customise(array(
'Locations' => $Locations
))->renderWith('LocationXML');
}
return $this->customise(array(
'Locations' => $Locations
))->renderWith('LocationXML');

}


/**
* LocationSearch function.
*
* Search form for locations, updates map and results list via AJAX
*
* @access public
* @return Form
*/
public function LocationSearch() {
$fields = FieldList::create(
$address = TextField::create('address', '')
);
$address->setAttribute('placeholder', 'address or zip code');

if (LocationCategory::get()->Count() > 0) {
$fields->push(DropdownField::create('category', '', LocationCategory::get()->map('Title', 'Title'))->setEmptyString('Select Category'));
}

$actions = FieldList::create(
FormAction::create('', 'Search')
);

return Form::create($this, 'LocationSearch', $fields, $actions);

}

}
Loading

2 comments on commit ebd504b

@muskie9
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jirish did we remove these for a reason...

public function getAllCategories() { return LocationCategory::get(); }

To use the categories this function currently needs to be re-applied to the Locator page via an extension at this point. We'll probably want to work it back in as a part of the module.

@jsirish
Copy link
Member Author

@jsirish jsirish commented on ebd504b Oct 30, 2014 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.