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 Dec 30, 2022
1 parent 1b0ff6a commit a275b7a
Show file tree
Hide file tree
Showing 3 changed files with 32 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 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();
Expand Down
18 changes: 18 additions & 0 deletions src/DataGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,11 @@ class DataGrid extends Control
*/
private $componentFullName;

/**
* @var string|null
*/
protected $groupActionsConfirmDialog;


public function __construct(?IContainer $parent = null, ?string $name = null)
{
Expand Down Expand Up @@ -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;
}

}
10 changes: 9 additions & 1 deletion src/GroupAction/GroupActionCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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']);
}
Expand Down

0 comments on commit a275b7a

Please sign in to comment.