Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
494d1f6
Create composer.json
fpolanzanGCD Aug 18, 2015
6c2526e
First commit of src
fpolanzanGCD Aug 18, 2015
3efafdd
Update composer.json
fpolanzanGCD Aug 19, 2015
039059d
Refactoring
fpolanzanGCD Aug 19, 2015
56961df
Smal change on passing ApiKey to the request
fpolanzanGCD Aug 19, 2015
eaf914f
Spacing out the address fields returned in a search
codoherty Sep 18, 2015
3e7f855
Merge pull request #2 from GCDTech/cod/PafReturnedResultsFormat
fpolanzanGCD Sep 18, 2015
ecc9e8e
For each address line, a text value of 'undefined' was being returned…
codoherty Sep 22, 2015
de5cadb
Merge pull request #3 from GCDTech/cod/DontSetValueAsUndefined
acuthbert Sep 22, 2015
6b8e457
Set default value
fpolanzanGCD Sep 28, 2015
3f19d68
Set the default value for country
fpolanzanGCD Sep 28, 2015
c34f5ce
method to return model of the address
fpolanzanGCD Sep 30, 2015
6b29e7e
spinner and readjusted field layout
PaulCWoods Oct 6, 2015
abd4a46
Show spinner during the call to PAF recognition service
fpolanzanGCD Oct 6, 2015
069c166
Update dependancies
fpolanzanGCD Oct 6, 2015
867684b
Removed view and default values properties since they were not used
fpolanzanGCD Oct 6, 2015
8712cc5
Hide spinner if there's an error on the PAF search
fpolanzanGCD Oct 6, 2015
9f0a675
Fix the call to PAF service
fpolanzanGCD Oct 6, 2015
5d53c42
Avoid to show undefined values in the results list
fpolanzanGCD Oct 6, 2015
5787818
Changed error message
fpolanzanGCD Oct 6, 2015
a3019a0
If the country is different from United Kingdom the manual address fi…
fpolanzanGCD Oct 22, 2015
5846500
on loading if the country is not GB, show address manual fields
fpolanzanGCD Oct 27, 2015
4a667aa
countries list changed
fpolanzanGCD Oct 27, 2015
7d19789
Changed getCountries method and the countries selection list values s…
fpolanzanGCD Oct 28, 2015
411a206
classes formatted in PSR2
fpolanzanGCD Oct 28, 2015
be4f34b
Handled exception on calling the PAF service
fpolanzanGCD Oct 28, 2015
5948cf2
Hide link to search if country is not United kingdom
fpolanzanGCD Oct 28, 2015
61c4e63
Show link to set address manually if country is united kingdom
fpolanzanGCD Oct 28, 2015
07fc9da
First version without jQuery code
fpolanzanGCD Oct 28, 2015
bad39eb
removed jQuery code
fpolanzanGCD Oct 28, 2015
5bbde15
Fix click events and search result items
fpolanzanGCD Oct 28, 2015
c3160fc
edited response message handling
fpolanzanGCD Oct 28, 2015
3e80940
Merge branch 'PW/PafChanges' into FP/JsCode
fpolanzanGCD Oct 28, 2015
2fe91ce
Set the address with the click result item
fpolanzanGCD Oct 28, 2015
6866216
Add style to search post code error
fpolanzanGCD Oct 28, 2015
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "GcdTech/module-uk-address-lookup",
"description": "A module that shows a form with the common address fields with a tool to search address according to post code",
"keywords": [],
"homepage": "http://www.rhubarbphp.com/",
"license": "Apache-2.0",
"autoload": {
"psr-4": {
"Gcd\\UkAddressLookup\\": "src/"
}
},
"require": {
"rhubarbphp/rhubarb": "*",
"rhubarbphp/module-leaf": "*"
},
"require-dev": {
"phpunit/phpunit": "3.*"
}
}
62 changes: 62 additions & 0 deletions src/AddressUkPafLookup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

namespace Gcd\UkAddressLookup;

use Rhubarb\Leaf\Presenters\Controls\CompositeControlPresenter;

class AddressUkPafLookup extends CompositeControlPresenter
{
const pafServerUrl = "http://paf.gcdtech.com/paf-data.php?simple=1&api=2&output=json";

public function __construct($name = "")
{
parent::__construct($name);
}

protected function initialiseModel()
{
parent::initialiseModel();

$this->model->Country = "GB";
}

protected function createView()
{
return new AddressUkPafLookupView();
}

protected function configureView()
{
parent::configureView();

$this->view->AttachEventHandler("SearchPressed", function ($houseNumber, $postCodeSearch) {
if ( ! isset( $postCodeSearch )) {
return json_decode([]);
}
$searchParams = [];
$searchParams['postcode'] = urlencode($postCodeSearch);

$pafSettings = new PafSettings();
$searchParams['apikey'] = $pafSettings->ApiKey;

if (isset( $houseNumber )) {
$searchParams['num'] = urlencode($houseNumber);
}
$requestUrl = self::pafServerUrl . '&' . http_build_query($searchParams, '&');

try {
$response = file_get_contents($requestUrl);
return json_decode($response);

} catch (\Exception $e) {
return null;
}
});
}

protected function extractBoundData()
{
return $this->model;
}

}
91 changes: 91 additions & 0 deletions src/AddressUkPafLookupView.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php

namespace Gcd\UkAddressLookup;

use Rhubarb\Leaf\Presenters\Controls\Buttons\Button;
use Rhubarb\Leaf\Presenters\Controls\ControlView;
use Rhubarb\Leaf\Presenters\Controls\Selection\DropDown\DropDown;
use Rhubarb\Leaf\Presenters\Controls\Text\TextBox\TextBox;

class AddressUkPafLookupView extends ControlView
{
protected $htmlType = "address";

public function __construct($htmlType = "address")
{
$this->htmlType = $htmlType;

$this->requiresContainer = true;
$this->requiresStateInputs = true;
}

public function getDeploymentPackage()
{
$package = parent::getDeploymentPackage();
$package->resourcesToDeploy[] = __DIR__ . "/AddressUkPafLookupViewBridge.js";

return $package;
}

protected function getClientSideViewBridgeName()
{
return "AddressUkPafLookupViewBridge";
}

public function createPresenters()
{
$this->AddPresenters(
$country = new DropDown("Country"),
$houseNumber = new TextBox("HouseNumber", 10),
$postCodeSearch = new TextBox("PostCodeSearch", 15),
$search = new Button("Search", "Search", function () {
}),
new TextBox("Line1", 50),
new TextBox("Line2", 30),
new TextBox("Town", 30),
new TextBox("County", 20),
new TextBox("PostCode", 10)
);

$countriesList = [];
foreach (Country::getCountriesList() as $key => $value) {
$countriesList[] = [$key, $value];
}
$country->SetSelectionItems([["", "Please select..."], $countriesList]);
$postCodeSearch->setPlaceholderText("Postcode");
$houseNumber->setPlaceholderText("No.");
}

public function printViewContent()
{
$this->printFieldset("", ["Country"]);
?>
<div id="search-fields">
<div id="search-results">
<span id="search-results-msg"></span>
<ul id="search-results-items" class="search-results-items"></ul>
</div>
<?php
$this->printFieldset("", [
"Find Address" => "{HouseNumber}{PostCodeSearch}{Search}<span id='spinner' class='spinner'></span>"
]);
?>
<span id="search-error"></span>
</div>

<p id="manual-address-par" class="_help">Don't know the postcode? <a id="manual-address-link" href='#'>enter their address manually</a>.</p>
<p id="search-address-par" class="_help"><b><a id="search-address-link" href='#'>Search again</a></b></p>
<div id="manual-fields">
<?php
$this->printFieldset("", [
"Address Line 1" => "Line1",
"Address Line 2" => "Line2",
"Town",
"County",
"PostCode"
]);
?>
</div>
<?php
}
}
Loading