API CHANGE Added two predefined GridFieldConfigs and removal of unsused accessors

- GridFieldConfig_ManyManyEditor for default relationship list managment
- GridFieldConfig_Base for basic list managment
This commit is contained in:
Stig Lindqvist 2012-01-24 12:36:25 +13:00
parent c396c2d2ae
commit ed889529b4
2 changed files with 64 additions and 50 deletions

View File

@ -35,7 +35,6 @@ class SecurityAdmin extends LeftAndMain implements PermissionProvider {
public function init() {
parent::init();
Requirements::javascript(SAPPHIRE_ADMIN_DIR . '/javascript/SecurityAdmin.js');
}
@ -107,12 +106,7 @@ class SecurityAdmin extends LeftAndMain implements PermissionProvider {
* @return FieldList
*/
function RootForm() {
$config = new GridFieldConfig();
$config->addComponent(new GridFieldRelationAdd('Name'));
$config->addComponent(new GridFieldDefaultColumns());
$config->addComponent(new GridFieldSortableHeader());
$config->addComponent(new GridFieldPaginator());
$config->addComponent(new GridFieldAction_Edit());
$config = new GridFieldConfig_Base(25);
$config->addComponent(new GridFieldPopupForms($this, 'RootForm'));
$memberList = new GridField('Members', 'All members', DataList::create('Member'), $config);
@ -134,7 +128,7 @@ class SecurityAdmin extends LeftAndMain implements PermissionProvider {
new LiteralField(
'GroupImportFormIframe',
sprintf(
'<iframe src="%s" id="GroupImportFormIframe" width="100%%" height="400px" border="0"></iframe>',
'<iframe src="%s" id="GroupImportFormIframe" width="100%" height="400px" border="0"></iframe>',
$this->Link('groupimport')
)
)

104
forms/gridfield/GridFieldConfig.php Normal file → Executable file
View File

@ -19,24 +19,6 @@ class GridFieldConfig {
*/
protected $components = null;
/**
*
* @var int
*/
protected $checkboxes = null;
/**
*
* @var array
*/
protected $affectors = array();
/**
*
* @var array
*/
protected $decorators = array();
/**
*
*/
@ -59,30 +41,68 @@ class GridFieldConfig {
}
return $this->components;
}
public function setCheckboxes($row=0){
$this->checkboxes = $row;
return $this;
}
class GridFieldConfig_Base extends GridFieldConfig {
/**
*
* @param int $itemsPerPage - How many items per page should show up per page
* @return GridFieldConfig_Base
*/
public static function create($itemsPerPage=25){
return new GridFieldConfig_Base($itemsPerPage=25);
}
public function getCheckboxes() {
return $this->checkboxes;
}
public function addAffector(GridState_Affector $affector) {
$this->affectors[] = $affector;
return $this;
}
public function getAffectors() {
return $this->affectors;
}
public function addDecorator($decorator) {
$this->decorators[] = $decorator;
}
public function getDecorators() {
return $this->decorators;
/**
*
* @param int $itemsPerPage - How many items per page should show up
*/
public function __construct($itemsPerPage=25) {
$this->addComponent(new GridFieldSortableHeader());
$this->addComponent(new GridFieldDefaultColumns());
$this->addComponent(new GridFieldAction_Edit());
$this->addComponent(new GridFieldPaginator($itemsPerPage));
}
}
/**
* This GridFieldConfig bundles a common set of componentes used for displaying
* a gridfield with:
*
* - Relation adding
* - Sortable header
* - Default columns
* - Edit links on every item
* - Action for removing relationship
* - Paginator
*
*/
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);
}
/**
*
* @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) {
$this->addComponent(new GridFieldRelationAdd($fieldToSearch, $autoSuggest));
$this->addComponent(new GridFieldSortableHeader());
$this->addComponent(new GridFieldDefaultColumns());
$this->addComponent(new GridFieldAction_Edit());
$this->addComponent(new GridFieldRelationDelete());
$this->addComponent(new GridFieldPaginator($itemsPerPage));
}
}