Permalink
Browse files

API CHANGE Added two predefined GridFieldConfigs and removal of unsus…

…ed accessors

- GridFieldConfig_ManyManyEditor for default relationship list managment
- GridFieldConfig_Base for basic list managment
  • Loading branch information...
1 parent c396c2d commit ed889529b48590f3fe04b217f9abb7c0a6eda98b @stojg stojg committed Jan 23, 2012
Showing with 62 additions and 48 deletions.
  1. +2 −8 admin/code/SecurityAdmin.php
  2. +60 −40 forms/gridfield/GridFieldConfig.php
@@ -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 @@ function getEditForm($id = null) {
* @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 @@ function RootForm() {
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')
)
)
View
@@ -20,24 +20,6 @@ public static function create(){
protected $components = null;
/**
- *
- * @var int
- */
- protected $checkboxes = null;
-
- /**
- *
- * @var array
- */
- protected $affectors = array();
-
- /**
- *
- * @var array
- */
- protected $decorators = array();
-
- /**
*
*/
public function __construct() {
@@ -59,30 +41,68 @@ public function getComponents() {
}
return $this->components;
}
-
- public function setCheckboxes($row=0){
- $this->checkboxes = $row;
- return $this;
- }
-
- public function getCheckboxes() {
- return $this->checkboxes;
- }
-
- public function addAffector(GridState_Affector $affector) {
- $this->affectors[] = $affector;
- 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 getAffectors() {
- return $this->affectors;
+
+ /**
+ *
+ * @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));
}
-
- public function addDecorator($decorator) {
- $this->decorators[] = $decorator;
+}
+
+/**
+ * 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);
}
-
- public function getDecorators() {
- return $this->decorators;
+
+ /**
+ *
+ * @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));
}
}

0 comments on commit ed88952

Please sign in to comment.