Skip to content

Commit

Permalink
API CHANGE: Removed 'add new' button from GridFieldToolbarHeader, ins…
Browse files Browse the repository at this point in the history
…tead opting to include two HTML fragments: toolbar-header-left and toolbar-header-right.
  • Loading branch information
Sam Minnee committed Mar 9, 2012
1 parent 92a3535 commit d795a55
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 53 deletions.
3 changes: 2 additions & 1 deletion css/GridField.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 4 additions & 49 deletions forms/gridfield/GridFieldToolbarHeader.php
Expand Up @@ -2,62 +2,17 @@
/**
* Adding this class to a {@link GridFieldConfig} of a {@link GridField} adds a header title to that field.
* The header serves double duty of displaying the name of the data the GridField is showing and
* providing an "add new" button to create new object instances.
*
* The reason for making "add new" part of the title component is to make it easier for the user to tell
* which "add new" button belongs to which datagrid, in the case where multiple datagrids are on a single
* page. It is also a more efficient use of screen space.
*
* The default DataGrid includes the add button. You can hide the button by setting a boolean using the
* setNewEnabled() method
* providing a space for actions on this grid.
*
* This header provides two new HTML fragment spaces: 'toolbar-header-left' and 'toolbar-header-right'.
*
* @package sapphire
* @subpackage gridfield
*/
class GridFieldToolbarHeader implements GridField_HTMLProvider {

/**
*
* @var bool
*/
protected $newEnabled = true;

/**
*
* @var type
*/
protected $gridField = null;

public function getHTMLFragments( $gridField) {
$this->gridField = $gridField;
return array(
'header' => $gridField->customise(array(
'NewLink' => Controller::join_links($gridField->Link('item'), 'new'),
'NewEnabled' => $this->getNewEnabled()
))->renderWith('GridFieldToolbarHeader')
'header' => $gridField->renderWith('GridFieldToolbarHeader')
);
}

/**
* Returns whether or not the "add new" button will appear when rendering this DataGrid title
* @return bool
*/
public function getNewEnabled() {
if($this->gridField) {
$model = singleton($this->gridField->getModelClass());
if(!$model->canCreate()) {
return false;
}
}

return $this->newEnabled;
}

/**
* Enable or disable the "add new" button to add new DataGrid object instances
* @param $enabled
*/
public function setNewEnabled($enabled) {
$this->newEnabled = $enabled;
}
}
8 changes: 6 additions & 2 deletions scss/GridField.scss
Expand Up @@ -139,9 +139,13 @@ $gf_grid_x: 16px;
margin:$gf_grid_y/4 $gf_grid_x/2 0;
display:inline-block;
}
.new{
font-size: $gf_grid_y*1.2;
.right > * {
float: right;
font-size: $gf_grid_y*1.2;
}
.left > * {
float: left;
font-size: $gf_grid_y*1.2;
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion templates/Includes/GridFieldToolbarHeader.ss
@@ -1,3 +1,7 @@
<tr class="title">
<th colspan="$ColumnCount"><h2>$Title</h2><% if NewEnabled %> <a href="$NewLink" class="action ss-ui-action-constructive ss-ui-button ui-button ui-widget ui-state-default ui-corner-all new new-link" data-icon="add"><% _t('GridField.AddNew', 'Add New') %></a><% end_if %></th>
<th colspan="$ColumnCount">
<% if Title %><h2>$Title</h2><% end_if %>
<div class="left">\$DefineFragment(toolbar-header-left)</div>
<div class="right">\$DefineFragment(toolbar-header-right)</div>
</th>
</tr>

0 comments on commit d795a55

Please sign in to comment.