From d795a55bdb7d83a1f857515cdce69bacb80c67ea Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Fri, 9 Mar 2012 16:49:18 +1300 Subject: [PATCH] API CHANGE: Removed 'add new' button from GridFieldToolbarHeader, instead opting to include two HTML fragments: toolbar-header-left and toolbar-header-right. --- css/GridField.css | 3 +- forms/gridfield/GridFieldToolbarHeader.php | 53 ++------------------ scss/GridField.scss | 8 ++- templates/Includes/GridFieldToolbarHeader.ss | 6 ++- 4 files changed, 17 insertions(+), 53 deletions(-) diff --git a/css/GridField.css b/css/GridField.css index 16b55b33b..5fbbdd8b8 100644 --- a/css/GridField.css +++ b/css/GridField.css @@ -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; } diff --git a/forms/gridfield/GridFieldToolbarHeader.php b/forms/gridfield/GridFieldToolbarHeader.php index e8b140e28..e9830ff67 100644 --- a/forms/gridfield/GridFieldToolbarHeader.php +++ b/forms/gridfield/GridFieldToolbarHeader.php @@ -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; - } } diff --git a/scss/GridField.scss b/scss/GridField.scss index 685a8de4d..cd5aa8b73 100644 --- a/scss/GridField.scss +++ b/scss/GridField.scss @@ -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; } } } diff --git a/templates/Includes/GridFieldToolbarHeader.ss b/templates/Includes/GridFieldToolbarHeader.ss index 81f6b4817..31548aa26 100644 --- a/templates/Includes/GridFieldToolbarHeader.ss +++ b/templates/Includes/GridFieldToolbarHeader.ss @@ -1,3 +1,7 @@ -

$Title

<% if NewEnabled %> <% _t('GridField.AddNew', 'Add New') %><% end_if %> + + <% if Title %>

$Title

<% end_if %> +
\$DefineFragment(toolbar-header-left)
+
\$DefineFragment(toolbar-header-right)
+ \ No newline at end of file