mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Use new plus icon (#8619)
* Use new plus icon and refactor * MINOR: Add ability to customise the visibility of the `Previous`, `Next` and `Add` buttons at a `GridField` level * - Merge `showPrevious` and `showNext` to `showPagination` for grid fields - Update documentation - Improve performance for next/previous buttons by not fetching all list records - Refactoring * Refactor to fail gracefully on GridFieldPaginator * Fix merge
This commit is contained in:
parent
661d2567fa
commit
1d9e40ba26
@ -202,7 +202,7 @@ class GridFieldDetailForm implements GridField_URLHandler
|
||||
protected function getDefaultShowPagination()
|
||||
{
|
||||
$formActionsConfig = GridFieldDetailForm_ItemRequest::config()->get('formActions');
|
||||
return isset($formActionsConfig['showPagination']) ? (boolean) $formActionsConfig['showPagination'] : false;
|
||||
return isset($formActionsConfig['showPagination']) ? (bool) $formActionsConfig['showPagination'] : false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -214,7 +214,7 @@ class GridFieldDetailForm implements GridField_URLHandler
|
||||
return $this->getDefaultShowPagination();
|
||||
}
|
||||
|
||||
return (boolean) $this->showPagination;
|
||||
return (bool) $this->showPagination;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -233,7 +233,7 @@ class GridFieldDetailForm implements GridField_URLHandler
|
||||
protected function getDefaultShowAdd()
|
||||
{
|
||||
$formActionsConfig = GridFieldDetailForm_ItemRequest::config()->get('formActions');
|
||||
return isset($formActionsConfig['showAdd']) ? (boolean) $formActionsConfig['showAdd'] : false;
|
||||
return isset($formActionsConfig['showAdd']) ? (bool) $formActionsConfig['showAdd'] : false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -245,7 +245,7 @@ class GridFieldDetailForm implements GridField_URLHandler
|
||||
return $this->getDefaultShowAdd();
|
||||
}
|
||||
|
||||
return (boolean) $this->showAdd;
|
||||
return (bool) $this->showAdd;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -313,9 +313,8 @@ class GridFieldDetailForm implements GridField_URLHandler
|
||||
return $this->itemRequestClass;
|
||||
} elseif (ClassInfo::exists(static::class . '_ItemRequest')) {
|
||||
return static::class . '_ItemRequest';
|
||||
} else {
|
||||
return GridFieldDetailForm_ItemRequest::class;
|
||||
}
|
||||
return GridFieldDetailForm_ItemRequest::class;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -272,55 +272,30 @@ class GridFieldDetailForm_ItemRequest extends RequestHandler
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the set of form field actions for this DataObject
|
||||
*
|
||||
* @return FieldList
|
||||
* @return CompositeField Returns the right aligned toolbar group field along with its FormAction's
|
||||
*/
|
||||
protected function getFormActions()
|
||||
private function getRightGroupField()
|
||||
{
|
||||
$canEdit = $this->record->canEdit();
|
||||
$canDelete = $this->record->canDelete();
|
||||
$actions = new FieldList();
|
||||
|
||||
if ($this->record->ID !== 0) {
|
||||
if ($canEdit) {
|
||||
$actions->push(FormAction::create('doSave', _t('SilverStripe\\Forms\\GridField\\GridFieldDetailForm.Save', 'Save'))
|
||||
->setUseButtonTag(true)
|
||||
->addExtraClass('btn-primary font-icon-save'));
|
||||
}
|
||||
|
||||
if ($canDelete) {
|
||||
$actions->push(FormAction::create('doDelete', _t('SilverStripe\\Forms\\GridField\\GridFieldDetailForm.Delete', 'Delete'))
|
||||
->setUseButtonTag(true)
|
||||
->addExtraClass('btn-outline-danger btn-hide-outline font-icon-trash-bin action--delete'));
|
||||
}
|
||||
|
||||
$gridStateStr = $this->getRequest()->requestVar('gridState');
|
||||
|
||||
$this->gridField->getState(false)->setValue($gridStateStr);
|
||||
$actions->push(HiddenField::create('gridState', null, $gridStateStr));
|
||||
|
||||
$rightGroup = CompositeField::create()->setName('RightGroup');
|
||||
$rightGroup->addExtraClass('right');
|
||||
$rightGroup->addExtraClass('ml-auto');
|
||||
$rightGroup->setFieldHolderTemplate(get_class($rightGroup) . '_holder_buttongroup');
|
||||
|
||||
$previousAndNextGroup = CompositeField::create()->setName('PreviousAndNextGroup');
|
||||
$previousAndNextGroup->addExtraClass('rounded');
|
||||
$previousAndNextGroup->addExtraClass('circular-group mr-2');
|
||||
$previousAndNextGroup->setFieldHolderTemplate(get_class($previousAndNextGroup) . '_holder_buttongroup');
|
||||
|
||||
|
||||
$component = $this->gridField->getConfig()->getComponentByType(GridFieldDetailForm::class);
|
||||
|
||||
$gridState = $this->getRequest()->requestVar('gridState');
|
||||
if ($component->getShowPagination()) {
|
||||
$previousAndNextGroup->push(FormAction::create('doPrevious')
|
||||
->setUseButtonTag(true)
|
||||
->setAttribute('data-grid-state', $gridStateStr)
|
||||
->setAttribute('data-grid-state', $gridState)
|
||||
->setDisabled(!$this->getPreviousRecordID())
|
||||
->addExtraClass('btn btn-secondary font-icon-left-open action--previous discard-confirmation'));
|
||||
|
||||
$previousAndNextGroup->push(FormAction::create('doNext')
|
||||
->setUseButtonTag(true)
|
||||
->setAttribute('data-grid-state', $gridStateStr)
|
||||
->setAttribute('data-grid-state', $gridState)
|
||||
->setDisabled(!$this->getNextRecordID())
|
||||
->addExtraClass('btn btn-secondary font-icon-right-open action--next discard-confirmation'));
|
||||
}
|
||||
@ -331,13 +306,44 @@ class GridFieldDetailForm_ItemRequest extends RequestHandler
|
||||
$rightGroup->push(FormAction::create('doNew')
|
||||
->setUseButtonTag(true)
|
||||
->setAttribute('data-grid-state', $this->getRequest()->getVar('gridState'))
|
||||
->addExtraClass('btn btn-primary font-icon-plus rounded action--new discard-confirmation'));
|
||||
->addExtraClass('btn btn-primary font-icon-plus-thin circular action--new discard-confirmation'));
|
||||
}
|
||||
|
||||
return $rightGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the set of form field actions for this DataObject
|
||||
*
|
||||
* @return FieldList
|
||||
*/
|
||||
protected function getFormActions()
|
||||
{
|
||||
$actions = new FieldList();
|
||||
|
||||
if ($this->record->ID !== 0) { // existing record
|
||||
if ($this->record->canEdit()) {
|
||||
$actions->push(FormAction::create('doSave', _t('SilverStripe\\Forms\\GridField\\GridFieldDetailForm.Save', 'Save'))
|
||||
->setUseButtonTag(true)
|
||||
->addExtraClass('btn-primary font-icon-save'));
|
||||
}
|
||||
|
||||
if ($this->record->canDelete()) {
|
||||
$actions->push(FormAction::create('doDelete', _t('SilverStripe\\Forms\\GridField\\GridFieldDetailForm.Delete', 'Delete'))
|
||||
->setUseButtonTag(true)
|
||||
->addExtraClass('btn-outline-danger btn-hide-outline font-icon-trash-bin action--delete'));
|
||||
}
|
||||
|
||||
$gridState = $this->getRequest()->requestVar('gridState');
|
||||
$this->gridField->getState(false)->setValue($gridState);
|
||||
$actions->push(HiddenField::create('gridState', null, $gridState));
|
||||
|
||||
$actions->push($this->getRightGroupField());
|
||||
} else { // adding new record
|
||||
//Change the Save label to 'Create'
|
||||
$actions->push(FormAction::create('doSave', _t('SilverStripe\\Forms\\GridField\\GridFieldDetailForm.Create', 'Create'))
|
||||
->setUseButtonTag(true)
|
||||
->addExtraClass('btn-primary font-icon-plus'));
|
||||
->addExtraClass('btn-primary font-icon-plus-thin'));
|
||||
|
||||
// Add a Cancel link which is a button-like link and link back to one level up.
|
||||
$crumbs = $this->Breadcrumbs();
|
||||
@ -530,8 +536,8 @@ class GridFieldDetailForm_ItemRequest extends RequestHandler
|
||||
return false;
|
||||
}
|
||||
|
||||
$currentPage = $data->getData('GridFieldPaginator')->getData('currentPage');
|
||||
$itemsPerPage = $data->getData('GridFieldPaginator')->getData('itemsPerPage');
|
||||
$currentPage = $paginator->getData('currentPage');
|
||||
$itemsPerPage = $paginator->getData('itemsPerPage');
|
||||
|
||||
$limit = $itemsPerPage + 2;
|
||||
$limitOffset = max(0, $itemsPerPage * ($currentPage-1) -1);
|
||||
|
Loading…
Reference in New Issue
Block a user