diff --git a/module/LogisticsBundle/Controller/FlesserkeArticleController.php b/module/LogisticsBundle/Controller/FlesserkeArticleController.php index 21d341cfa3..463474f1b3 100644 --- a/module/LogisticsBundle/Controller/FlesserkeArticleController.php +++ b/module/LogisticsBundle/Controller/FlesserkeArticleController.php @@ -142,6 +142,27 @@ public function editAction(): ViewModel ), ); } + public function deleteAction() + { + error_log("Delete action initiated"); + $this->initAjax(); + + $article = $this->getFlesserkeArticleEntity(); + if ($article === null) { + error_log("Article not found"); + return new ViewModel(); + } + + $this->getEntityManager()->remove($article); + $this->getEntityManager()->flush(); + error_log("Removed"); + + return new ViewModel( + array( + 'result' => (object) array('status' => 'success'), + ) + ); + } public function searchAction(): ViewModel { diff --git a/module/LogisticsBundle/Controller/InventoryArticleController.php b/module/LogisticsBundle/Controller/InventoryArticleController.php index d9d9d12371..a7f4882291 100644 --- a/module/LogisticsBundle/Controller/InventoryArticleController.php +++ b/module/LogisticsBundle/Controller/InventoryArticleController.php @@ -384,6 +384,52 @@ public function editArticlesAction(): ViewModel ); } + public function deleteAction(): ViewModel + { + $academic = $this->getAcademicEntity(); + if ($academic === null) { + $this->redirect()->toRoute( + 'logistics_inventory_article', + array( + 'action' => 'index', + ) + ); + return new ViewModel(); + } + + $article = $this->getInventoryArticleEntity(); + if ($article === null) { + $this->flashMessenger()->error( + 'Error', + 'No article was found!' + ); + $this->redirect()->toRoute( + 'logistics_inventory_article', + array( + 'action' => 'index', + ) + ); + return new ViewModel(); + } + + $this->getEntityManager()->remove($article); + $this->getEntityManager()->flush(); + + $this->flashMessenger()->success( + 'Success', + 'The article was successfully deleted!' + ); + + $this->redirect()->toRoute( + 'logistics_inventory_article', + array( + 'action' => 'index', + ) + ); + + return new ViewModel(); + } + public function searchArticlesAction(): ViewModel { $this->initAjax(); diff --git a/module/LogisticsBundle/Resources/config/install/acl.config.php b/module/LogisticsBundle/Resources/config/install/acl.config.php index 866114851e..e0c119996c 100644 --- a/module/LogisticsBundle/Resources/config/install/acl.config.php +++ b/module/LogisticsBundle/Resources/config/install/acl.config.php @@ -51,10 +51,10 @@ 'index', 'view', 'add', 'edit', 'cancel', 'remove', ), 'logistics_inventory_article' => array( - 'index', 'add', 'edit', 'search', 'addArticles', 'editArticles', 'searchArticles', + 'index', 'add', 'delete', 'edit', 'search', 'addArticles', 'editArticles', 'searchArticles', ), 'logistics_flesserke_article' => array( - 'index', 'add', 'edit', 'search', 'addArticles', 'editArticles', 'searchArticles', + 'index', 'add', 'delete', 'edit', 'search', 'addArticles', 'editArticles', 'searchArticles', ), ), ); diff --git a/module/LogisticsBundle/Resources/views/logistics/flesserke-article/delete.twig b/module/LogisticsBundle/Resources/views/logistics/flesserke-article/delete.twig new file mode 100644 index 0000000000..89e8fe679b --- /dev/null +++ b/module/LogisticsBundle/Resources/views/logistics/flesserke-article/delete.twig @@ -0,0 +1,3 @@ +{% autoescape false %} + {{ result|json_encode }} +{% endautoescape %} diff --git a/module/LogisticsBundle/Resources/views/logistics/flesserke-article/index.twig b/module/LogisticsBundle/Resources/views/logistics/flesserke-article/index.twig index 02f5b45050..7d7be1c464 100644 --- a/module/LogisticsBundle/Resources/views/logistics/flesserke-article/index.twig +++ b/module/LogisticsBundle/Resources/views/logistics/flesserke-article/index.twig @@ -119,6 +119,9 @@ {{ translate('Edit') }} + + {{ translate('Delete') }} + {% endif %} @@ -152,6 +155,27 @@ $(document).ready(function () { $('.category-collapse').click(collapse); + $('.delete-article').click(function (e) { + e.preventDefault(); + const url = $(this).attr('href'); + + if (confirm('{{ translate('Are you sure you want to delete this article?') }}')) { + $.ajax({ + url: url, + type: 'DELETE', + success: function (result) { + // Handle success (e.g., remove the article row from the table) + alert('{{ translate('Article deleted successfully.') }}'); + location.reload(); // Optionally reload the page or remove the row + }, + error: function (xhr, status, error) { + // Handle error + alert('{{ translate('An error occurred while deleting the article.') }}'); + } + }); + } + }); + $('a[rel=popover], span[rel=popover]').popover({'trigger': 'hover', 'html': true}); {% if hasAccess('logistics_flesserke_article', 'search') %} diff --git a/module/LogisticsBundle/Resources/views/logistics/inventory-article/index.twig b/module/LogisticsBundle/Resources/views/logistics/inventory-article/index.twig index 2f694de311..276a31943c 100644 --- a/module/LogisticsBundle/Resources/views/logistics/inventory-article/index.twig +++ b/module/LogisticsBundle/Resources/views/logistics/inventory-article/index.twig @@ -126,6 +126,9 @@ {{ translate('Edit') }} + + {{ translate('Delete') }} + {% endif %} @@ -161,6 +164,9 @@ {{ translate('Edit') }} + + {{ translate('Delete') }} + {% endif %} @@ -249,6 +255,7 @@ } }); {% endif %} + }); function openSearchRequest(e) {