mirror of
https://github.com/symbiote/silverstripe-gridfieldextensions.git
synced 2024-10-22 17:05:39 +02:00
parent
8e37021317
commit
04c42273cf
@ -2,4 +2,8 @@
|
||||
name: gridfieldextensions
|
||||
---
|
||||
GridFieldAddNewMultiClass:
|
||||
showEmptyString: true
|
||||
showEmptyString: true
|
||||
|
||||
SilverStripe\Forms\GridField\GridFieldDetailForm_ItemRequest:
|
||||
extensions:
|
||||
- Symbiote\GridFieldExtensions\Extensions\GridFieldDetailForm_ItemRequest
|
||||
|
@ -201,3 +201,25 @@
|
||||
.ss-gridfield-configurable-paginator .pagination-page-number input {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.grid-field-inline-new--multi-class-list {
|
||||
display: none;
|
||||
background-color: #008a00;
|
||||
border-radius: 5px;
|
||||
bottom: 3em;
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
right: 3em;
|
||||
padding: 10px;
|
||||
position: fixed;
|
||||
|
||||
}
|
||||
.grid-field-inline-new--multi-class-list a {
|
||||
color: #FFF;
|
||||
display: block;
|
||||
margin: 5px -10px;
|
||||
padding: 0 10px;
|
||||
}
|
||||
.grid-field-inline-new--multi-class-list__visible {
|
||||
display: block;
|
||||
}
|
||||
|
@ -237,6 +237,24 @@
|
||||
}
|
||||
});
|
||||
|
||||
$(".action--new__multi-class").entwine({
|
||||
onmatch: function () {
|
||||
const hrefTemplate = this.data('hrefTemplate');
|
||||
const classes = this.data('classes');
|
||||
const liHtml = Object.keys(classes).map(className => {
|
||||
const link = hrefTemplate.replace('{class}', className);
|
||||
return `<li><a href="${link}">Add: <i>${classes[className]}</i></a></li>`;
|
||||
});
|
||||
|
||||
const listElement = $(`<ul class="grid-field-inline-new--multi-class-list">${liHtml.join('')}</ul>`);
|
||||
listElement.insertBefore(this);
|
||||
|
||||
this.on('click', function () {
|
||||
listElement.toggleClass('grid-field-inline-new--multi-class-list__visible');
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
$(".ss-gridfield-add-new-multi-class select").entwine({
|
||||
onadd: function() {
|
||||
this.update();
|
||||
|
75
src/Extensions/GridFieldDetailForm_ItemRequest.php
Normal file
75
src/Extensions/GridFieldDetailForm_ItemRequest.php
Normal file
@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace Symbiote\GridFieldExtensions\Extensions;
|
||||
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Core\Convert;
|
||||
use SilverStripe\Core\Extension;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
use SilverStripe\Forms\GridField\GridFieldDetailForm_ItemRequest As CoreGridFieldDetailForm_ItemRequest;
|
||||
use SilverStripe\Forms\LiteralField;
|
||||
use SilverStripe\View\ArrayData;
|
||||
use SilverStripe\View\HTML;
|
||||
use Symbiote\GridFieldExtensions\GridFieldAddNewMultiClass;
|
||||
use Symbiote\GridFieldExtensions\GridFieldExtensions;
|
||||
|
||||
/**
|
||||
* @property CoreGridFieldDetailForm_ItemRequest $owner
|
||||
*/
|
||||
class GridFieldDetailForm_ItemRequest extends Extension
|
||||
{
|
||||
/**
|
||||
* @param FieldList $actions
|
||||
*/
|
||||
public function updateFormActions(FieldList &$actions)
|
||||
{
|
||||
$grid = $this->owner->getGridField();
|
||||
$gridFieldConfig = $grid->getConfig();
|
||||
$addMultiClassComponent = $gridFieldConfig->getComponentByType(GridFieldAddNewMultiClass::class);
|
||||
if ($addMultiClassComponent) {
|
||||
$newRecordField = static::get_new_record_field_from_actions($actions);
|
||||
if ($newRecordField) {
|
||||
$newRecordField->getContainerFieldList()->removeByName('new-record');
|
||||
$newRecordField->getContainerFieldList()->push(
|
||||
LiteralField::create('new-record', $this->getHTMLFragment($addMultiClassComponent))
|
||||
);
|
||||
GridFieldExtensions::include_requirements();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
private function getHTMLFragment(GridFieldAddNewMultiClass $component)
|
||||
{
|
||||
$grid = $this->owner->getGridField();
|
||||
|
||||
$classes = $component->getClasses($grid);
|
||||
|
||||
if (!count($classes)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return HTML::createTag('a', [
|
||||
'data-href-template' => Controller::join_links($grid->Link(), 'add-multi-class', '{class}'),
|
||||
'title' => _t(__CLASS__ . '.NEW', 'Add new record'),
|
||||
'aria-label' => _t(__CLASS__ . '.NEW', 'Add new record'),
|
||||
'class' => 'btn btn-primary font-icon-plus-thin btn--circular action--new discard-confirmation action--new__multi-class',
|
||||
'data-classes' => Convert::array2json($classes),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FieldList $actions
|
||||
* @return LiteralField OR NULL
|
||||
*/
|
||||
private static function get_new_record_field_from_actions(FieldList &$actions)
|
||||
{
|
||||
$rightGroup = $actions->fieldByName('RightGroup');
|
||||
if (!$rightGroup) {
|
||||
return null;
|
||||
}
|
||||
return $rightGroup->getChildren()->fieldByName('new-record');
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user