Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group actions - confirm dialog #1058

Open
wants to merge 4 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions assets/plugins/features/confirm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ export class ConfirmPlugin implements DatagridPlugin {
const message = el.getAttribute(ConfirmAttribute)!;
if (!message) return;

if (el.getAttribute('data-group-action') === null) {
return;
}

if (!this.confirm(message)) {
e.stopPropagation();
e.preventDefault();
Expand Down
15 changes: 14 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 UnexpectedValueException;

class GroupActionCollection
Expand All @@ -19,6 +20,8 @@ class GroupActionCollection
/** @var array<GroupAction> */
protected array $groupActions = [];

protected ?string $groupActionsConfirmDialog = null;

public function __construct(protected Datagrid $datagrid)
{
}
Expand Down Expand Up @@ -129,12 +132,17 @@ public function addToFormContainer(Container $container): void
strtolower($this->datagrid->getFullName()) . 'group_action_submit'
);

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

if ($this->groupActionsConfirmDialog !== null) {
$submit->setHtmlAttribute('data-' . Action::$dataConfirmAttributeName, $this->groupActionsConfirmDialog);
$submit->setHtmlAttribute('data-group-action', 'true');
}
} else {
unset($container['group_action']);
}
Expand Down Expand Up @@ -258,6 +266,11 @@ public function getGroupAction(string $title): GroupAction
throw new DatagridGroupActionException(sprintf('Group action %s does not exist.', $title));
}

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

private function getFormSubmitter(NetteForm $form): ?SubmitButton
{
$container = $form['group_action'];
Expand Down