Skip to content

Commit

Permalink
Merge pull request #38 from wilr/master
Browse files Browse the repository at this point in the history
Upgrade to 4.0 (Fixes #31)
  • Loading branch information
Damian Mooyman authored Feb 13, 2018
2 parents 57ad821 + 2c9aedf commit ed3ff17
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 26 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
composer.lock
vendor
framework
2 changes: 2 additions & 0 deletions .upgrade.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mappings:
AutoCompleteField: TractorCow\AutoComplete\AutoCompleteField
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ usage

A field can be created as follows...
```php
AutoCompleteField::create('MyTextField','My Text Field','',null,null,'LookupDataObject','LookupFieldName')
\TractorCow\AutoCompleteField\AutoCompleteField::create('MyTextField','My Text Field','',null,null,'LookupDataObject','LookupFieldName')
```
where it will accept values from the following dataobject field...

Expand Down
3 changes: 0 additions & 3 deletions _config.php

This file was deleted.

Empty file added _config/.gitkeep
Empty file.
20 changes: 14 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "tractorcow/silverstripe-autocomplete",
"description": "Autocomplete text field for Silverstripe",
"type": "silverstripe-module",
"type": "silverstripe-vendormodule",
"keywords": [
"silverstripe",
"autocomplete"
Expand All @@ -18,12 +18,20 @@
"issues": "http://github.com/tractorcow/silverstripe-autocomplete/issues"
},
"require": {
"silverstripe/framework": "~3.1"
"silverstripe/framework": "^4@dev"
},
"extra": {
"installer-name": "autocomplete",
"branch-alias": {
"dev-master": "3.5.x-dev"
}
}
"dev-master": "4.x-dev"
},
"expose": [
"css",
"javascript"
]
},
"autoload": {
"psr-4": {
"TractorCow\\AutoComplete\\": "src/"
}
}
}
35 changes: 19 additions & 16 deletions code/AutoCompleteField.php → src/AutoCompleteField.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
<?php

namespace TractorCow\AutoComplete;

use SilverStripe\Forms\TextField;
use SilverStripe\View\Requirements;
use SilverStripe\ORM\DataList;
use SilverStripe\Control\HTTPRequest;

/**
* Autocompleting text field, using jQuery.
*
* @package forms
* @subpackage fields-formattedinput
*/
class AutoCompleteField extends TextField
{
/**
* @var array
*/
private static $allowed_actions = array(
private static $allowed_actions = [
'Suggest'
);
];

/**
* Name of the class this field searches.
Expand All @@ -27,7 +32,7 @@ class AutoCompleteField extends TextField
*
* @var string
*/
private $sourceFields = array();
private $sourceFields = [];


/**
Expand Down Expand Up @@ -115,19 +120,17 @@ class AutoCompleteField extends TextField
* @param string $name The name of the field.
* @param null|string $title The title to use in the form.
* @param string $value The initial value of this field.
* @param null|int $maxLength Maximum number of characters.
* @param null|string $form
* @param null|string $sourceClass The suggestion source class.
* @param mixed $sourceFields The suggestion source fields.
*/
public function __construct($name, $title = null, $value = '', $maxLength = null, $form = null, $sourceClass = null, $sourceFields = null)
public function __construct($name, $title = null, $value = '', $sourceClass = null, $sourceFields = null)
{
// set source
$this->sourceClass = $sourceClass;
$this->sourceFields = is_array($sourceFields) ? $sourceFields : array($sourceFields);

// construct the TextField
parent::__construct($name, $title, $value, $maxLength, $form);
parent::__construct($name, $title, $value);
}

/**
Expand Down Expand Up @@ -170,18 +173,18 @@ public function Type()
public function Field($properties = array())
{
// jQuery Autocomplete Requirements
Requirements::css(THIRDPARTY_DIR . '/jquery-ui-themes/smoothness/jquery-ui.css');
Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
Requirements::javascript(THIRDPARTY_DIR . '/jquery-ui/jquery-ui.js');
// Requirements::css('silverstripe/admin:thirdparty/jquery-ui-themes/smoothness/jquery-ui.css');
Requirements::javascript('silverstripe/admin:thirdparty/jquery/jquery.js');
Requirements::javascript('silverstripe/admin:thirdparty/jquery-ui/jquery-ui.js');

// Entwine requirements
Requirements::javascript(THIRDPARTY_DIR . '/jquery-entwine/dist/jquery.entwine-dist.js');
Requirements::javascript('silverstripe/admin:thirdparty/jquery-entwine/dist/jquery.entwine-dist.js');

// init script for this field
Requirements::javascript(AUTOCOMPLETEFIELD_DIR . '/javascript/AutocompleteField.js');
Requirements::javascript('tractorcow/silverstripe-autocomplete:javascript/AutocompleteField.js');

// styles for this field
Requirements::css(AUTOCOMPLETEFIELD_DIR . '/css/AutocompleteField.css');
Requirements::css('tractorcow/silverstripe-autocomplete:css/AutocompleteField.css');

return parent::Field($properties);
}
Expand Down Expand Up @@ -538,7 +541,7 @@ protected function determineSourceClass()
*
* @return string A JSON list of items for Autocomplete.
*/
public function Suggest(SS_HTTPRequest $request)
public function Suggest(HTTPRequest $request)
{
// Find class to search within
$sourceClass = $this->determineSourceClass();
Expand Down
File renamed without changes.

0 comments on commit ed3ff17

Please sign in to comment.