API CHANGE: Removed 'add new' button from GridFieldToolbarHeader, instead opting to include two HTML fragments: toolbar-header-left and toolbar-header-right.

This commit is contained in:
Sam Minnee 2012-03-09 16:49:18 +13:00
parent 92a3535455
commit d795a55bdb
4 changed files with 17 additions and 53 deletions

View File

@ -17,7 +17,8 @@
.cms table.ss-gridfield-table tr.title { -moz-border-radius-topleft: 7px; -webkit-border-top-left-radius: 7px; -o-border-top-left-radius: 7px; -ms-border-top-left-radius: 7px; -khtml-border-top-left-radius: 7px; border-top-left-radius: 7px; -moz-border-radius-topright: 7px; -webkit-border-top-right-radius: 7px; -o-border-top-right-radius: 7px; -ms-border-top-right-radius: 7px; -khtml-border-top-right-radius: 7px; border-top-right-radius: 7px; }
.cms table.ss-gridfield-table tr.title th { position: relative; background: #7f9198; border-top: 1px solid rgba(0, 0, 0, 0.1); padding: 5px; min-height: 40px; background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #b1c0c5), color-stop(100%, #7f9198)); background-image: -webkit-linear-gradient(#b1c0c5, #7f9198); background-image: -moz-linear-gradient(#b1c0c5, #7f9198); background-image: -o-linear-gradient(#b1c0c5, #7f9198); background-image: -ms-linear-gradient(#b1c0c5, #7f9198); background-image: linear-gradient(#b1c0c5, #7f9198); -moz-border-radius-topleft: 7px; -webkit-border-top-left-radius: 7px; -o-border-top-left-radius: 7px; -ms-border-top-left-radius: 7px; -khtml-border-top-left-radius: 7px; border-top-left-radius: 7px; -moz-border-radius-topright: 7px; -webkit-border-top-right-radius: 7px; -o-border-top-right-radius: 7px; -ms-border-top-right-radius: 7px; -khtml-border-top-right-radius: 7px; border-top-right-radius: 7px; text-shadow: rgba(0, 0, 0, 0.3) 0px -1px 0; }
.cms table.ss-gridfield-table tr.title th h2 { padding: 0px; font-size: 16.8px; color: #fff; margin: 3px 8px 0; display: inline-block; }
.cms table.ss-gridfield-table tr.title th .new { font-size: 14.4px; float: right; }
.cms table.ss-gridfield-table tr.title th .right > * { float: right; font-size: 14.4px; }
.cms table.ss-gridfield-table tr.title th .left > * { float: left; font-size: 14.4px; }
.cms table.ss-gridfield-table tr.sortable-header { background: #bac8ce; }
.cms table.ss-gridfield-table tr.sortable-header th { padding: 0px; }
.cms table.ss-gridfield-table tr:hover { background: #FFFAD6 !important; }

View File

@ -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;
}
}

View File

@ -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;
}
}
}

View File

@ -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>