Skip to content
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
10 changes: 10 additions & 0 deletions assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class App {
this.#createAutoCompleteFields();
this.#createBatchActions();
this.#createModalWindowsForDeleteActions();
this.#createModalWindowsForConfirmationActions();
this.#createPopovers();
this.#createTooltips();

Expand Down Expand Up @@ -396,6 +397,15 @@ class App {
});
}

#createModalWindowsForConfirmationActions() {
const modalTitles = document.querySelectorAll('.action-confirmation-title');
modalTitles.forEach((modalTitle) => {
const titleContentWithPlaceholders = modalTitle.textContent;
const actionName = modalTitle.getAttribute('data-action-title');
modalTitle.textContent = titleContentWithPlaceholders.replace('%action_name%', actionName);
});
}

#createPopovers() {
document.querySelectorAll('[data-bs-toggle="popover"]').forEach((popoverElement) => {
new bootstrap.Popover(popoverElement);
Expand Down
7 changes: 7 additions & 0 deletions src/Config/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ public function setIcon(?string $icon): self
return $this;
}

public function setConfirmationModal(string $modalText): self
{
$this->dto->setConfirmationModal($modalText);

return $this;
}

/**
* Use this to override the default CSS classes applied to actions and use instead your own CSS classes.
* See also addCssClass() to add your own custom classes without removing the default ones.
Expand Down
16 changes: 16 additions & 0 deletions src/Dto/ActionDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ final class ActionDto
private ButtonType $butonType = ButtonType::Submit;
private ButtonVariant $variant = ButtonVariant::Default;
private ButtonStyle $style = ButtonStyle::Solid;
private ?string $modalText = null;

public function getType(): string
{
Expand Down Expand Up @@ -357,6 +358,21 @@ public function usesTextStyle(): bool
return ButtonStyle::Text === $this->style;
}

public function hasConfirmationModal(): bool
{
return isset($this->modalText);
}

public function setConfirmationModal(string $modalText): void
{
$this->modalText = $modalText;
}

public function getModalText(): ?string
{
return $this->modalText;
}

/**
* @internal
*/
Expand Down
7 changes: 7 additions & 0 deletions src/Factory/ActionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,13 @@ private function processAction(string $pageName, ActionDto $actionDto, ?EntityDt
}
}

if ($actionDto->hasConfirmationModal()) {
$actionDto->addHtmlAttributes([
'data-bs-toggle' => 'modal',
'data-bs-target' => '#modal-confirmation-'.$actionDto->getName(),
]);
}

if (Action::DELETE === $actionDto->getName()) {
$actionDto->addHtmlAttributes([
'formaction' => $this->adminUrlGenerator->setController($adminContext->getCrud()->getControllerFqcn())->setAction(Action::DELETE)->setEntityId($entityDto->getPrimaryKeyValue())->generateUrl(),
Expand Down
4 changes: 2 additions & 2 deletions templates/crud/action.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
htmlElement="{{ action.htmlElement }}"
type="{{ action.buttonType.value }}"
icon="{{ action.icon }}"
href="{{ action.htmlElement.isLink ? action.linkUrl : null }}"
action="{{ action.htmlElement.isForm ? action.linkUrl : null }}"
href="{{ action.hasConfirmationModal == false and action.htmlElement.isLink ? action.linkUrl : null }}"
action="{{ action.hasConfirmationModal == false and action.htmlElement.isForm ? action.linkUrl : null }}"
method="{{ action.htmlElement.isForm ? 'POST' : null }}"
>
{%- if outerScope.action.label is not empty -%}<span class="action-label">{{ outerScope.action.label|trans|raw }}</span>{%- endif -%}
Expand Down
2 changes: 1 addition & 1 deletion templates/crud/action_group.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
label="{{ item.label }}" icon="{{ item.icon }}" class="{{ item.cssClass }} dropdown-item-variant-{{ item.variant.value }}"
htmlAttributes="{{ item.htmlAttributes }}"
renderAsForm="{{ item.isRenderedAsForm }}"
url="{{ item.linkUrl }}" renderLabelRaw="true"
url="{{ item.hasConfirmationModal == false ? item.linkUrl : null }}" renderLabelRaw="true"
showBlankIcons="{{ group.hasAnyActionWithIcon }}"
/>
{% endif %}
Expand Down
12 changes: 12 additions & 0 deletions templates/crud/detail.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@
{% block delete_form %}
{{ include('@EasyAdmin/crud/includes/_delete_form.html.twig', {entity_id: entity.primaryKeyValue}, with_context: false) }}
{% endblock delete_form %}

{% for action in entity.actions %}
{% if action.isActionGroup %}
{% for item in action.items %}
{% if item.hasConfirmationModal %}
{{ include('@EasyAdmin/crud/includes/_confirm_action_modal.html.twig', {action: item}, with_context: false) }}
{% endif %}
{% endfor %}
{% elseif action.hasConfirmationModal %}
{{ include('@EasyAdmin/crud/includes/_confirm_action_modal.html.twig', {action: action}, with_context: false) }}
{% endif %}
{% endfor %}
{% endblock %}

{% macro render_field_contents(entity, field) %}
Expand Down
12 changes: 12 additions & 0 deletions templates/crud/edit.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,16 @@
{% block delete_form %}
{{ include('@EasyAdmin/crud/includes/_delete_form.html.twig', {entity_id: entity.primaryKeyValue}, with_context: false) }}
{% endblock delete_form %}

{% for action in entity.actions %}
{% if action.isActionGroup %}
{% for item in action.items %}
{% if item.hasConfirmationModal %}
{{ include('@EasyAdmin/crud/includes/_confirm_action_modal.html.twig', {action: item}, with_context: false) }}
{% endif %}
{% endfor %}
{% elseif action.hasConfirmationModal %}
{{ include('@EasyAdmin/crud/includes/_confirm_action_modal.html.twig', {action: action}, with_context: false) }}
{% endif %}
{% endfor %}
{% endblock %}
24 changes: 24 additions & 0 deletions templates/crud/includes/_confirm_action_modal.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<div id="modal-confirmation-{{ action.name }}" class="modal fade" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<h4 class="action-confirmation-title" data-action-title="{{ action.label ?? action.name }}">{{ 'confirmation_modal.title'|trans(domain: 'EasyAdminBundle') }}</h4>
<p>{{ action.modalText }}</p>
</div>
<div class="modal-footer">
<twig:ea:Button type="button" data-bs-dismiss="modal">
{{ 'action.cancel'|trans([], 'EasyAdminBundle') }}
</twig:ea:Button>
<twig:ea:Button
variant="danger"
htmlElement="{{ action.htmlElement }}"
type="{{ action.buttonType.value }}"
icon="{{ action.icon }}"
href="{{ action.linkUrl }}"
>
{{ 'confirmation_modal.action'|trans(domain: 'EasyAdminBundle') }}
</twig:ea:Button>
</div>
</div>
</div>
</div>
8 changes: 8 additions & 0 deletions templates/crud/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,16 @@
{% for action in entity.actions %}
{% if action.isActionGroup %}
{{ include(action.templatePath, {group: action, entity: entity}, with_context: false) }}
{% for item in action.items %}
{% if item.hasConfirmationModal %}
{{ include('@EasyAdmin/crud/includes/_confirm_action_modal.html.twig', {action: item}, with_context: false) }}
{% endif %}
{% endfor %}
{% else %}
{{ include(action.templatePath, {action: action, entity: entity, isIncludedInDropdown: ea.crud.showEntityActionsAsDropdown}, with_context: false) }}
{% if action.hasConfirmationModal %}
{{ include('@EasyAdmin/crud/includes/_confirm_action_modal.html.twig', {action: action}, with_context: false) }}
{% endif %}
{% endif %}
{% endfor %}
{% endif %}
Expand Down
5 changes: 5 additions & 0 deletions translations/EasyAdminBundle.ar.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@
'action' => 'استمرار',
],

'confirmation_modal' => [
'title' => 'سوف تقوم بتطبيق الأجراء "%action_name%"',
'action' => 'استمرار',
],

'delete_modal' => [
'title' => 'هل تريد حذف هذا العنصر؟',
'content' => 'هذا الإجراء غير قابل للإلغاء.',
Expand Down
5 changes: 5 additions & 0 deletions translations/EasyAdminBundle.bg.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@
'action' => 'Извърши',
],

'confirmation_modal' => [
'title' => 'Ще приложите действието "%action_name%".',
'action' => 'Извърши',
],

'delete_modal' => [
'title' => 'Наистина ли желаете да изтриете записа?',
'content' => 'Това действие е необратимо.',
Expand Down
5 changes: 5 additions & 0 deletions translations/EasyAdminBundle.ca.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@
'action' => 'Continuar',
],

'confirmation_modal' => [
'title' => 'Du vil anvende "%action_name%" handlingen.',
'action' => 'Continuar',
],

'delete_modal' => [
'title' => 'Realment vols esborrar aquest element?',
'content' => 'Aquesta acció no es pot desfer.',
Expand Down
5 changes: 5 additions & 0 deletions translations/EasyAdminBundle.cs.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@
'action' => 'Pokračovat',
],

'confirmation_modal' => [
'title' => 'Chcete použít akci "%action_name%".',
'action' => 'Pokračovat',
],

'delete_modal' => [
'title' => 'Opravdu chcete smazat tuto položku?',
'content' => 'Tuto akci není možné vrátit zpět.',
Expand Down
5 changes: 5 additions & 0 deletions translations/EasyAdminBundle.da.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@
'action' => 'Udfør handling',
],

'confirmation_modal' => [
'title' => 'Du vil anvende "%action_name%" handlingen.',
'action' => 'Udfør handling',
],

'delete_modal' => [
'title' => 'Er du sikker på du vil slette dette element?',
'content' => 'Denne operation kan ikke fortrydes.',
Expand Down
5 changes: 5 additions & 0 deletions translations/EasyAdminBundle.de.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@
'action' => 'Fortfahren',
],

'confirmation_modal' => [
'title' => 'Sie möchten die Aktion „%action_name%“ verwenden.',
'action' => 'Fortfahren',
],

'delete_modal' => [
'title' => 'Soll das Element wirklich gelöscht werden?',
'content' => 'Diese Aktion kann nicht rückgängig gemacht werden.',
Expand Down
5 changes: 5 additions & 0 deletions translations/EasyAdminBundle.el.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@
'action' => 'Συνεχίστε.',
],

'confirmation_modal' => [
'title' => 'Θα εφαρμόσετε την ενέργεια "%action_name%".',
'action' => 'Συνεχίστε.',
],

'delete_modal' => [
'title' => 'Θέλετε σίγουρα να διαγράψετε αυτό το αντικείμενο;',
'content' => 'Αυτή η ενέργεια δεν αναιρείται.',
Expand Down
5 changes: 5 additions & 0 deletions translations/EasyAdminBundle.en.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@
'action' => 'Proceed',
],

'confirmation_modal' => [
'title' => 'You are going to apply the "%action_name%" action.',
'action' => 'Proceed',
],

'delete_modal' => [
'title' => 'Do you really want to delete this item?',
'content' => 'There is no undo for this operation.',
Expand Down
5 changes: 5 additions & 0 deletions translations/EasyAdminBundle.es.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@
'action' => 'Continuar',
],

'confirmation_modal' => [
'title' => 'Desea utilizar la acción "%action_name%".',
'action' => 'Continuar',
],

'delete_modal' => [
'title' => '¿Realmente quieres borrar este elemento?',
'content' => 'Esta acción no se puede deshacer.',
Expand Down
5 changes: 5 additions & 0 deletions translations/EasyAdminBundle.eu.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@
'action' => 'Aurrera',
],

'confirmation_modal' => [
'title' => '"%action_name%" ekintza erabili nahi duzu.',
'action' => 'Aurrera',
],

'delete_modal' => [
'title' => 'Ziur zaude elementu hau ezabatu nahi duzula?',
'content' => 'Ekintza hau ezin da desegin.',
Expand Down
5 changes: 5 additions & 0 deletions translations/EasyAdminBundle.fa.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@
'action' => 'ادامه دهید',
],

'confirmation_modal' => [
'title' => 'شما قصد دارید اکشن "%action_name%" را اعمال کنید.',
'action' => 'ادامه دهید',
],

'delete_modal' => [
'title' => 'واقعا می‌خواهید این آیتم را حذف کنید؟',
'content' => 'این عملیات غیرقابل بازگشت است.',
Expand Down
5 changes: 5 additions & 0 deletions translations/EasyAdminBundle.fi.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@
// 'action' => '',
],

'confirmation_modal' => [
// 'title' => '',
// 'action' => '',
],

'delete_modal' => [
'title' => 'Oletko varma että haluat poistaa tämän?',
'content' => 'Toimintoa ei voi peruuttaa.',
Expand Down
5 changes: 5 additions & 0 deletions translations/EasyAdminBundle.fr.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@
'action' => 'Procéder',
],

'confirmation_modal' => [
'title' => 'Vous allez appliquer l\'action "%action_name%".',
'action' => 'Procéder',
],

'delete_modal' => [
'title' => 'Voulez-vous supprimer cet élément ?',
'content' => 'Cette action est irréversible.',
Expand Down
5 changes: 5 additions & 0 deletions translations/EasyAdminBundle.gl.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@
// 'action' => '',
],

'confirmation_modal' => [
// 'title' => '',
// 'action' => '',
],

'delete_modal' => [
'title' => '¿Queres realmente borrar este elemento?',
'content' => 'Esta acción non se pode desfacer.',
Expand Down
5 changes: 5 additions & 0 deletions translations/EasyAdminBundle.he.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@
'action' => 'המשך',
],

'confirmation_modal' => [
// 'title' => '',
// 'action' => '',
],

'delete_modal' => [
'title' => 'האם הנך בטוח שברצונך למחוק פריט זה?',
'content' => 'לא ניתן לבטל פעולה זו לאחר ביצועה.',
Expand Down
5 changes: 5 additions & 0 deletions translations/EasyAdminBundle.hr.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@
// 'action' => '',
],

'confirmation_modal' => [
// 'title' => '',
// 'action' => '',
],

'delete_modal' => [
'title' => 'Jeste li sigurni da želite izbrisati ovu stavku?',
'content' => 'Izbrisana stavka se ne može povratiti',
Expand Down
5 changes: 5 additions & 0 deletions translations/EasyAdminBundle.hu.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@
'action' => 'Folytatás',
],

'confirmation_modal' => [
// 'title' => '',
'action' => 'Folytatás',
],

'delete_modal' => [
'title' => 'Biztos benne, hogy törli ezt az elemet?',
'content' => 'Ez a művelet visszavonhatatlan.',
Expand Down
5 changes: 5 additions & 0 deletions translations/EasyAdminBundle.hy.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@
'action' => 'Շարունակել',
],

'confirmation_modal' => [
// 'title' => '',
'action' => 'Շարունակել',
],

'delete_modal' => [
'title' => 'Խնդրում ենք հաստատել, Դուք իրոք ցանկանում եք հեռացնել',
'content' => 'Այս գործողությունը չի կարող չեղարկվել։',
Expand Down
Loading