Skip to content

Commit

Permalink
feat: Added Custom forms bulk delete actions
Browse files Browse the repository at this point in the history
  • Loading branch information
ambroisemaupate committed Sep 14, 2023
1 parent 6652e67 commit 25dd271
Show file tree
Hide file tree
Showing 9 changed files with 163 additions and 108 deletions.
5 changes: 5 additions & 0 deletions lib/RoadizRozierBundle/config/routing/custom-forms.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,8 @@ customFormsDuplicatePage:
requirements: { id : "[0-9]+" }
defaults:
_controller: Themes\Rozier\Controllers\CustomForms\CustomFormsUtilsController::duplicateAction
customFormsBulkDeletePage:
methods: [GET, POST]
path: /bulk-delete
defaults:
_controller: Themes\Rozier\Controllers\CustomForms\CustomFormsController::bulkDeleteAction
42 changes: 7 additions & 35 deletions lib/Rozier/src/Controllers/CustomForms/CustomFormsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,98 +8,70 @@
use RZ\Roadiz\CoreBundle\Entity\CustomForm;
use RZ\Roadiz\RozierBundle\Form\CustomFormType;
use Symfony\Component\HttpFoundation\Request;
use Themes\Rozier\Controllers\AbstractAdminController;
use Themes\Rozier\Controllers\AbstractAdminWithBulkController;

class CustomFormsController extends AbstractAdminController
class CustomFormsController extends AbstractAdminWithBulkController
{
/**
* @inheritDoc
*/
protected function supports(PersistableInterface $item): bool
{
return $item instanceof CustomForm;
}

/**
* @inheritDoc
*/
protected function getNamespace(): string
{
return 'custom-form';
}

/**
* @inheritDoc
*/
protected function createEmptyItem(Request $request): PersistableInterface
{
return new CustomForm();
}

/**
* @inheritDoc
*/
protected function getTemplateFolder(): string
{
return '@RoadizRozier/custom-forms';
}

/**
* @inheritDoc
*/
protected function getRequiredRole(): string
{
return 'ROLE_ACCESS_CUSTOMFORMS';
}

/**
* @inheritDoc
*/
protected function getEntityClass(): string
{
return CustomForm::class;
}

/**
* @inheritDoc
*/
protected function getFormType(): string
{
return CustomFormType::class;
}

/**
* @inheritDoc
*/
protected function getDefaultOrder(Request $request): array
{
return ['createdAt' => 'DESC'];
}

/**
* @inheritDoc
*/
protected function getDefaultRouteName(): string
{
return 'customFormsHomePage';
}

/**
* @inheritDoc
*/
protected function getEditRouteName(): string
{
return 'customFormsEditPage';
}

/**
* @inheritDoc
*/
protected function getEntityName(PersistableInterface $item): string
{
if ($item instanceof CustomForm) {
return $item->getName();
}
throw new \InvalidArgumentException('Item should be instance of ' . $this->getEntityClass());
}

protected function getBulkDeleteRouteName(): ?string
{
return 'customFormsBulkDeletePage';
}
}
4 changes: 4 additions & 0 deletions lib/Rozier/src/Resources/translations/messages.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,10 @@
<trans-unit id="are_you_sure.bulk_delete.redirections" xml:space="preserve"><source>are_you_sure.bulk_delete.redirections</source></trans-unit>
<trans-unit id="redirections.bulk_delete.title" xml:space="preserve"><source>redirections.bulk_delete.title</source></trans-unit>

<trans-unit id="no_custom_forms" xml:space="preserve"><source>no_custom_forms</source></trans-unit>
<trans-unit id="are_you_sure.bulk_delete.custom_forms" xml:space="preserve"><source>are_you_sure.bulk_delete.custom_forms</source></trans-unit>
<trans-unit id="custom_forms.bulk_delete.title" xml:space="preserve"><source>custom_forms.bulk_delete.title</source></trans-unit>

<trans-unit xml:space="preserve" id="reset.marker"><source>reset.marker</source></trans-unit>
<trans-unit xml:space="preserve" id="geotag.type_an_address.then_type_enter"><source>geotag.type_an_address.then_type_enter</source></trans-unit>
<trans-unit xml:space="preserve" id="geographic.coordinates.type"><source>geographic.coordinates.type</source></trans-unit>
Expand Down
2 changes: 1 addition & 1 deletion lib/Rozier/src/Resources/views/admin/base.html.twig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends "@RoadizRozier/layout.html.twig" %}

{% block content %}
<section class="content-global">
<section class="bulk-layout content-global">
<header class="content-header">
<h1 class="content-title">{%- block content_title -%}{%- endblock -%}</h1>
{%- block content_count_filters -%}
Expand Down
39 changes: 39 additions & 0 deletions lib/Rozier/src/Resources/views/custom-forms/bulk_base.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{% extends '@RoadizRozier/admin/base.html.twig' %}

{% block title %}{{ block('bulk_title') }} | {{ parent() }}{% endblock %}
{% block content_title %}{% block bulk_title %}{% endblock %}{% endblock %}

{% block content_count_filters %}
{% include '@RoadizRozier/widgets/countFiltersBar.html.twig' %}
{% endblock %}

{% block content_header_nav %}
<a class="content-header-nav-back uk-navbar-content"
href="{{ path('customFormsHomePage') }}"
title="{% trans %}back_to.customForms{% endtrans %}"
data-uk-tooltip="{animation:true}"><i class="uk-icon-rz-back-parent"></i></a>
{% endblock %}

{% block content_body %}
<article class="content content-no-action-menu">
<div class="content-table-cont">
<table class="items content-table uk-table">
<thead>
<tr>
{% include '@RoadizRozier/custom-forms/customform_row_header.html.twig' with { no_sort: true } %}
</tr>
</thead>
<tbody>
{% for item in items %}
<tr>
{% include '@RoadizRozier/custom-forms/customform_row.html.twig' %}
</tr>
{% else %}
<tr><td colspan="5">{% trans %}no_custom_forms{% endtrans %}</td></tr>
{% endfor %}
</tbody>
</table>
</div>
{% block bulk_form %}{% endblock %}
</article>
{% endblock %}
20 changes: 20 additions & 0 deletions lib/Rozier/src/Resources/views/custom-forms/bulk_delete.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{% extends '@RoadizRozier/custom-forms/bulk_base.html.twig' %}
{% block bulk_title %}{% trans %}custom_forms.bulk_delete.title{% endtrans %}{% endblock %}
{% block bulk_form %}
{% if form %}
<article class="content content-delete content-no-action-menu">
{% form_theme form '@RoadizRozier/forms.html.twig' %}
{{ form_start(form, {
'attr': {
'class': 'uk-form uk-form-stacked'
}
}) }}{{ form_widget(form) }}
<fieldset data-uk-margin>
<legend class="uk-alert uk-alert-danger"><i class="uk-icon uk-icon-warning"></i> {% trans %}are_you_sure.bulk_delete.custom_forms{% endtrans %}</legend>
<a href="{{ path('customFormsHomePage') }}" class="uk-button"><i class="uk-icon-rz-back-parent"></i> {% trans %}cancel{% endtrans %}</a>
<button class="uk-button uk-button-danger" type="submit"><i class="uk-icon-rz-trash-mini-o"></i> {% trans %}delete{% endtrans %}</button>
</fieldset>
{{ form_end(form) }}
</article>
{% endif %}
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<td class="name">
<a href="{{ path('customFormsEditPage', { id: item.getId }) }}"><span class="color" style="background-color:{{ item.getColor }};"></span>{{ item.displayName }}</a>
</td>
<td class="mobile-hidden">{{ item.createdAt|format_datetime('medium', 'short', locale=app.request.locale) }}</td>
<td class="mobile-hidden">{{ item.closeDate|format_datetime('medium', 'short', locale=app.request.locale) }}</td>
<td class="mobile-hidden"><div class="uk-badge uk-badge-table">{% transchoice item.getFields|length %}{0} no.customFormField|{1} 1.customFormField|]1,Inf] %count%.customFormFields{% endtranschoice %}</div></td>
<td class="table-actions-row table-actions-row-6">
{% apply spaceless %}
{% if hasBulkActions %}
<div class="bulk-selection">
<input class="checkbox" type="checkbox" name="bulk-selection[]" value="{{ item.id }}" />
</div>
{% endif %}
<a class="uk-button uk-button-content uk-button-small"
href="{{ path('customFormsEditPage', { id: item.getId }) }}"
title="{% trans %}edit{% endtrans %}"
data-uk-tooltip="{animation:true}"><i class="uk-icon-rz-pencil"></i></a>

<a class="uk-button uk-button-content uk-button-small"
href="{{ path('customFormFieldsListPage', { customFormId: item.getId }) }}"
title="{% trans %}manage.customFormFields{% endtrans %}"
data-uk-tooltip="{animation:true}"><i class="uk-icon-rz-custom-form-fields"></i></a>

<a class="uk-button uk-button-content uk-button-small"
href="{{ path('customFormAnswersHomePage', { customFormId: item.getId }) }}"
title="{% trans %}customForm.answers{% endtrans %}"
data-uk-tooltip="{animation:true}"><i class="uk-icon-rz-custom-form-answers"></i></a>

<a class="uk-button uk-button-content uk-button-small"
href="{{ path('customFormSendAction', { customFormId: item.getId }) }}"
title="{% trans %}customForm.show{% endtrans %}"
data-uk-tooltip="{animation:true}" target="_blank"><i class="uk-icon-rz-visibility"></i></a>

<a class="uk-button uk-button-content uk-button-small rz-no-ajax-link"
href="{{ path('customFormsDuplicatePage', { id: item.getId }) }}"
title="{% trans %}customForm.duplicate{% endtrans %}"
data-uk-tooltip="{animation:true}"><i class="uk-icon-rz-duplicate"></i></a>

<a class="uk-button uk-button-content uk-button-small uk-button-success rz-no-ajax-link"
href="{{ path('customFormsExportPage', { id: item.getId }) }}"
title="{% trans %}export{% endtrans %}"
data-uk-tooltip="{animation:true}">
<i class="uk-icon-rz-download"></i>
</a>

<a class="uk-button uk-button-content uk-button-small uk-button-danger uk-button-table-delete"
href="{{ path('customFormsDeletePage', { id: item.getId }) }}"
title="{% trans %}delete{% endtrans %}"
data-uk-tooltip="{animation:true}">
<i class="uk-icon-rz-trash-o"></i>
</a>
{% endapply %}
</td>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<th>
{% trans %}customForm.displayName{% endtrans %}
{% include '@RoadizRozier/includes/column_ordering.html.twig' with {
'field': 'displayName',
'filters': filters,
} only %}
</th>
<th class="mobile-hidden">
{% trans %}createdAt{% endtrans %}
{% include '@RoadizRozier/includes/column_ordering.html.twig' with {
'field': 'createdAt',
'filters': filters,
} only %}
</th>
<th class="mobile-hidden">
{% trans %}customForm.closeDate{% endtrans %}
{% include '@RoadizRozier/includes/column_ordering.html.twig' with {
'field': 'closeDate',
'filters': filters,
} only %}
</th>
<th class="mobile-hidden"></th>
<th class="table-actions-row table-actions-row-6">
{% if hasBulkActions %}
<div class="bulk-selection">
<input class="checkbox" type="checkbox" name="bulk-selection-all" />
</div>
{% endif %}
{% trans %}actions{% endtrans %}
</th>
76 changes: 4 additions & 72 deletions lib/Rozier/src/Resources/views/custom-forms/list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

{%- block content_filters -%}
{% include '@RoadizRozier/widgets/filtersBar.html.twig' %}
{% include '@RoadizRozier/admin/bulk_actions.html.twig' %}
{%- endblock -%}

{%- block content_body -%}
Expand All @@ -21,82 +22,13 @@
<table class="custom-forms content-table uk-table">
<thead>
<tr>
<th>
{% trans %}customForm.displayName{% endtrans %}
{% include '@RoadizRozier/includes/column_ordering.html.twig' with {
'field': 'displayName',
'filters': filters,
} only %}
</th>
<th class="mobile-hidden">
{% trans %}createdAt{% endtrans %}
{% include '@RoadizRozier/includes/column_ordering.html.twig' with {
'field': 'createdAt',
'filters': filters,
} only %}
</th>
<th class="mobile-hidden">
{% trans %}customForm.closeDate{% endtrans %}
{% include '@RoadizRozier/includes/column_ordering.html.twig' with {
'field': 'closeDate',
'filters': filters,
} only %}
</th>
<th class="mobile-hidden"></th>
<th class="table-actions-row table-actions-row-6">{% trans %}actions{% endtrans %}</th>
{% include '@RoadizRozier/custom-forms/customform_row_header.html.twig' %}
</tr>
</thead>
<tbody>
{% for type in items %}
{% for item in items %}
<tr>
<td class="name">
<a href="{{ path('customFormsEditPage', { id: type.getId }) }}"><span class="color" style="background-color:{{ type.getColor }};"></span>{{ type.displayName }}</a>
</td>
<td class="mobile-hidden">{{ type.createdAt|format_datetime('medium', 'short', locale=app.request.locale) }}</td>
<td class="mobile-hidden">{{ type.closeDate|format_datetime('medium', 'short', locale=app.request.locale) }}</td>
<td class="mobile-hidden"><div class="uk-badge uk-badge-table">{% transchoice type.getFields|length %}{0} no.customFormField|{1} 1.customFormField|]1,Inf] %count%.customFormFields{% endtranschoice %}</div></td>
<td class="table-actions-row table-actions-row-6">
{% apply spaceless %}
<a class="uk-button uk-button-content uk-button-small"
href="{{ path('customFormsEditPage', { id: type.getId }) }}"
title="{% trans %}edit{% endtrans %}"
data-uk-tooltip="{animation:true}"><i class="uk-icon-rz-pencil"></i></a>

<a class="uk-button uk-button-content uk-button-small"
href="{{ path('customFormFieldsListPage', { customFormId: type.getId }) }}"
title="{% trans %}manage.customFormFields{% endtrans %}"
data-uk-tooltip="{animation:true}"><i class="uk-icon-rz-custom-form-fields"></i></a>

<a class="uk-button uk-button-content uk-button-small"
href="{{ path('customFormAnswersHomePage', { customFormId: type.getId }) }}"
title="{% trans %}customForm.answers{% endtrans %}"
data-uk-tooltip="{animation:true}"><i class="uk-icon-rz-custom-form-answers"></i></a>

<a class="uk-button uk-button-content uk-button-small"
href="{{ path('customFormSendAction', { customFormId: type.getId }) }}"
title="{% trans %}customForm.show{% endtrans %}"
data-uk-tooltip="{animation:true}" target="_blank"><i class="uk-icon-rz-visibility"></i></a>

<a class="uk-button uk-button-content uk-button-small rz-no-ajax-link"
href="{{ path('customFormsDuplicatePage', { id: type.getId }) }}"
title="{% trans %}customForm.duplicate{% endtrans %}"
data-uk-tooltip="{animation:true}"><i class="uk-icon-rz-duplicate"></i></a>

<a class="uk-button uk-button-content uk-button-small uk-button-success rz-no-ajax-link"
href="{{ path('customFormsExportPage', { id: type.getId }) }}"
title="{% trans %}export{% endtrans %}"
data-uk-tooltip="{animation:true}">
<i class="uk-icon-rz-download"></i>
</a>

<a class="uk-button uk-button-content uk-button-small uk-button-danger uk-button-table-delete"
href="{{ path('customFormsDeletePage', { id: type.getId }) }}"
title="{% trans %}delete{% endtrans %}"
data-uk-tooltip="{animation:true}">
<i class="uk-icon-rz-trash-o"></i>
</a>
{% endapply %}
</td>
{% include '@RoadizRozier/custom-forms/customform_row.html.twig' %}
</tr>
{% endfor %}
</tbody>
Expand Down

0 comments on commit 25dd271

Please sign in to comment.