MINOR Removed GridFieldRelationAdd->useAutoSuggestion flag, as the field doesn't work without it (no current ID is being set via JS) (SSF-53)

This commit is contained in:
Ingo Schommer 2012-03-01 14:43:42 +01:00
parent 88039ffb81
commit 9c95a9ae29
3 changed files with 26 additions and 31 deletions

View File

@ -51,7 +51,7 @@ If we wanted to make a simpler grid without pagination or filtering, we could do
A `GridFieldConfig` is made up of a new of `GridFieldComponent` objects. `GridFieldComponent` is a family of interfaces.
## Build-in components
## Built-in components
SilverStripe Framework comes with the following components that you can use out of the box.
@ -117,6 +117,18 @@ It's common for a component to implement several of these interfaces in order to
* `GridField_ActionProvider`, to define the sortasc and sortdesc actions that add sort column and direction to the state.
* `GridField_DataManipulator`, to alter the sorting of the data list based on the sort column and direction values in the state.
### GridFieldRelationAdd
A GridFieldRelationAdd is responsible for adding objects to another object's `has_many` and `many_many` relation,
as defined by the `[api:RelationList]` passed to the GridField constructor.
Objects can be searched through an input field (partially matching one or more fields).
Selecting from the results will add the object to the relation.
:::php
$group = DataObject::get_one('Group');
$config = GridFieldConfig::create()->addComponent(new GridFieldRelationAdd(array('FirstName', 'Surname', 'Email'));
$gridField = new GridField('Members', 'Members', $group->Members(), $config);
## Component interfaces
### GridField_HTMLProvider

View File

@ -121,23 +121,21 @@ class GridFieldConfig_ManyManyEditor extends GridFieldConfig {
/**
*
* @param string $fieldToSearch - Which field on the object should be searched for
* @param bool $autoSuggest - Show a jquery.ui.autosuggest dropdown field
* @param int $itemsPerPage - How many items per page should show up
* @return GridFieldConfig_ManyManyEditor
*/
public static function create($fieldToSearch, $autoSuggest=true, $itemsPerPage=25){
return new GridFieldConfig_ManyManyEditor($fieldToSearch, $autoSuggest=true, $itemsPerPage=25);
public static function create($fieldToSearch, $itemsPerPage=15){
return new GridFieldConfig_ManyManyEditor($fieldToSearch, $itemsPerPage=15);
}
/**
*
* @param string $fieldToSearch - Which field on the object should be searched for
* @param bool $autoSuggest - Show a jquery.ui.autosuggest dropdown field
* @param int $itemsPerPage - How many items per page should show up
*/
public function __construct($fieldToSearch, $autoSuggest=true, $itemsPerPage=25) {
public function __construct($fieldToSearch, $itemsPerPage=15) {
$this->addComponent(new GridFieldFilter());
$this->addComponent(new GridFieldRelationAdd($fieldToSearch, $autoSuggest));
$this->addComponent(new GridFieldRelationAdd($fieldToSearch));
$this->addComponent(new GridFieldSortableHeader());
$this->addComponent(new GridFieldDefaultColumns());
$this->addComponent(new GridFieldAction_Edit());

View File

@ -1,14 +1,9 @@
<?php
/**
* A GridFieldRelationAdd is responsible for adding objects to another objects
* has_many and many_many relation. It will not attach duplicate objects.
*
* It augments a GridField with fields above the gridfield to search and add
* objects to whatever the SS_List passed into the gridfield.
*
* If the object is set to use autosuggestion it will include jQuery UI
* autosuggestion field that searches for current objects that isn't already
* attached to the list.
* A GridFieldRelationAdd is responsible for adding objects to another object's has_many and many_many relation,
* as defined by the RelationList passed to the GridField constructor.
* Objects can be searched through an input field (partially matching one or more fields).
* Selecting from the results will add the object to the relation.
*/
class GridFieldRelationAdd implements GridField_HTMLProvider, GridField_ActionProvider, GridField_DataManipulator, GridField_URLHandler {
@ -26,21 +21,13 @@ class GridFieldRelationAdd implements GridField_HTMLProvider, GridField_ActionPr
*/
protected $fieldToSearch = '';
/**
* Use the jQuery.ui.autosuggestion plugin
*
* @var bool
*/
protected $useAutoSuggestion = true;
/**
*
* @param string $fieldToSearch which field on the object in the list should be search
* @param bool $autoSuggestion - if you would like to use the javascript autosuggest feature
*/
public function __construct($fieldToSearch, $autoSuggestion=true) {
$this->fieldToSearch = $fieldToSearch;
$this->useAutoSuggestion = $autoSuggestion;
}
/**
@ -52,13 +39,11 @@ class GridFieldRelationAdd implements GridField_HTMLProvider, GridField_ActionPr
$searchState = $gridField->State->GridFieldSearchRelation;
if($this->useAutoSuggestion){
Requirements::css(THIRDPARTY_DIR . '/jquery-ui-themes/smoothness/jquery-ui.css');
Requirements::add_i18n_javascript(SAPPHIRE_DIR . '/javascript/lang');
Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-ui/jquery-ui.js');
Requirements::javascript(SAPPHIRE_DIR . "/javascript/GridFieldSearch.js");
}
$forTemplate = new ArrayData(array());
$forTemplate->Fields = new ArrayList();