Skip to content

Commit

Permalink
group actions confirm dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
nidjo17 committed Jan 27, 2023
1 parent 988715f commit 8c7d326
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
5 changes: 5 additions & 0 deletions assets/datagrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ var datagridFilterMultiSelect, datagridGroupActionMultiSelect, datagridShiftGrou
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };

$(document).on('click', '[data-datagrid-confirm]:not(.ajax)', function(e) {
var data = $(e.target).data();

if (data['groupAction'] === true) {
return;
}
if (!confirm($(e.target).closest('a').attr('data-datagrid-confirm'))) {
e.stopPropagation();
return e.preventDefault();
Expand Down
13 changes: 13 additions & 0 deletions src/DataGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ class DataGrid extends Control

protected bool $showSelectedRowsCount = true;

protected ?string $groupActionsConfirmDialog;

private ?string $customPaginatorTemplate = null;

private ?string $componentFullName = null;
Expand Down Expand Up @@ -2854,6 +2856,17 @@ public function setCustomPaginatorTemplate(string $templateFile): void
$this->customPaginatorTemplate = $templateFile;
}


public function setGroupActionsConfirmDialog(string $confirmDialog): void
{
$this->groupActionsConfirmDialog = $confirmDialog;
}

public function getGroupActionsConfirmDialog(): ?string
{
return $this->groupActionsConfirmDialog;
}

protected function createSorting(array $sort, ?callable $sortCallback = null): Sorting
{
foreach ($sort as $key => $order) {
Expand Down
9 changes: 8 additions & 1 deletion src/GroupAction/GroupActionCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Nette\Forms\Controls\SelectBox;
use Nette\Forms\Controls\SubmitButton;
use Nette\Forms\Form as NetteForm;
use Ublaboo\DataGrid\Column\Action;
use Ublaboo\DataGrid\DataGrid;
use Ublaboo\DataGrid\Exception\DataGridGroupActionException;
use UnexpectedValueException;
Expand Down Expand Up @@ -129,12 +130,18 @@ public function addToFormContainer(Container $container): void
strtolower($this->datagrid->getFullName()) . 'group_action_submit'
);

$container->addSubmit('submit', 'ublaboo_datagrid.execute')
$submit = $container->addSubmit('submit', 'ublaboo_datagrid.execute')
->setValidationScope([$container])
->setHtmlAttribute(
'id',
strtolower($this->datagrid->getFullName()) . 'group_action_submit'
);

$confirmationDialog = $this->datagrid->getGroupActionsConfirmDialog();
if ($confirmationDialog !== null && $confirmationDialog !== '') {
$submit->setHtmlAttribute('data-' . Action::$dataConfirmAttributeName, $confirmationDialog);
$submit->setHtmlAttribute('data-group-action', 'true');
}
} else {
unset($container['group_action']);
}
Expand Down

0 comments on commit 8c7d326

Please sign in to comment.