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() { public function init() {
parent::init(); parent::init();
Requirements::javascript(SAPPHIRE_ADMIN_DIR . '/javascript/SecurityAdmin.js'); Requirements::javascript(SAPPHIRE_ADMIN_DIR . '/javascript/SecurityAdmin.js');
} }
@ -107,12 +106,7 @@ class SecurityAdmin extends LeftAndMain implements PermissionProvider {
* @return FieldList * @return FieldList
*/ */
function RootForm() { function RootForm() {
$config = new GridFieldConfig(); $config = new GridFieldConfig_Base(25);
$config->addComponent(new GridFieldRelationAdd('Name'));
$config->addComponent(new GridFieldDefaultColumns());
$config->addComponent(new GridFieldSortableHeader());
$config->addComponent(new GridFieldPaginator());
$config->addComponent(new GridFieldAction_Edit());
$config->addComponent(new GridFieldPopupForms($this, 'RootForm')); $config->addComponent(new GridFieldPopupForms($this, 'RootForm'));
$memberList = new GridField('Members', 'All members', DataList::create('Member'), $config); $memberList = new GridField('Members', 'All members', DataList::create('Member'), $config);
@ -134,7 +128,7 @@ class SecurityAdmin extends LeftAndMain implements PermissionProvider {
new LiteralField( new LiteralField(
'GroupImportFormIframe', 'GroupImportFormIframe',
sprintf( 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') $this->Link('groupimport')
) )
) )

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

@ -19,24 +19,6 @@ class GridFieldConfig {
*/ */
protected $components = null; 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; return $this->components;
} }
}
public function setCheckboxes($row=0){
$this->checkboxes = $row; class GridFieldConfig_Base extends GridFieldConfig {
return $this;
/**
*
* @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; *
} * @param int $itemsPerPage - How many items per page should show up
*/
public function addAffector(GridState_Affector $affector) { public function __construct($itemsPerPage=25) {
$this->affectors[] = $affector; $this->addComponent(new GridFieldSortableHeader());
return $this; $this->addComponent(new GridFieldDefaultColumns());
} $this->addComponent(new GridFieldAction_Edit());
$this->addComponent(new GridFieldPaginator($itemsPerPage));
public function getAffectors() { }
return $this->affectors; }
}
/**
public function addDecorator($decorator) { * This GridFieldConfig bundles a common set of componentes used for displaying
$this->decorators[] = $decorator; * a gridfield with:
} *
* - Relation adding
public function getDecorators() { * - Sortable header
return $this->decorators; * - 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));
} }
} }