diff --git a/assets/datagrid.js b/assets/datagrid.js index d29bab0d..4cc7d037 100644 --- a/assets/datagrid.js +++ b/assets/datagrid.js @@ -116,6 +116,11 @@ var datagridFitlerMultiSelect, 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(); diff --git a/src/DataGrid.php b/src/DataGrid.php index eead1cd2..33baa8a8 100644 --- a/src/DataGrid.php +++ b/src/DataGrid.php @@ -439,6 +439,11 @@ class DataGrid extends Control */ private $componentFullName; + /** + * @var string|null + */ + protected $groupActionsConfirmDialog; + public function __construct(?IContainer $parent = null, ?string $name = null) { @@ -3330,4 +3335,17 @@ private function getPresenterInstance(): Presenter return $this->getPresenter(); } + public function setGroupActionsConfirmDialog(string $confirmDialog): void + { + $this->groupActionsConfirmDialog = $confirmDialog; + } + + /** + * @return ?string + */ + public function getGroupActionsConfirmDialog(): ?string + { + return $this->groupActionsConfirmDialog; + } + } diff --git a/src/GroupAction/GroupActionCollection.php b/src/GroupAction/GroupActionCollection.php index 488ef61e..6ca356fb 100644 --- a/src/GroupAction/GroupActionCollection.php +++ b/src/GroupAction/GroupActionCollection.php @@ -9,6 +9,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; @@ -140,12 +141,19 @@ 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]) ->setAttribute( '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']); }