From 2ae947c4e4d093898aa10c9e270a7fe4e8828ef6 Mon Sep 17 00:00:00 2001 From: d1ff1cult0 Date: Mon, 30 Sep 2024 14:17:11 +0200 Subject: [PATCH 1/4] Added delete button for /logistics/flesserke --- .../Controller/FlesserkeArticleController.php | 21 +++++++++ .../Controller/InventoryArticleController.php | 46 +++++++++++++++++++ .../Resources/config/install/acl.config.php | 4 +- .../logistics/flesserke-article/delete.twig | 3 ++ .../logistics/flesserke-article/index.twig | 24 ++++++++++ .../logistics/inventory-article/index.twig | 7 +++ 6 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 module/LogisticsBundle/Resources/views/logistics/flesserke-article/delete.twig 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) { From a940e87acbddc58516921399f023e0b8f75a5119 Mon Sep 17 00:00:00 2001 From: d1ff1cult0 Date: Mon, 30 Sep 2024 14:21:55 +0200 Subject: [PATCH 2/4] Added delete button for /logistics/inventory --- .../Resources/views/logistics/inventory-article/delete.twig | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 module/LogisticsBundle/Resources/views/logistics/inventory-article/delete.twig diff --git a/module/LogisticsBundle/Resources/views/logistics/inventory-article/delete.twig b/module/LogisticsBundle/Resources/views/logistics/inventory-article/delete.twig new file mode 100644 index 0000000000..e69de29bb2 From a582182ffbfd26debe22a813544be09560f2195c Mon Sep 17 00:00:00 2001 From: d1ff1cult0 Date: Mon, 30 Sep 2024 14:26:40 +0200 Subject: [PATCH 3/4] Added delete button for /logistics/inventory --- .../Controller/FlesserkeArticleController.php | 4 +-- .../Controller/InventoryArticleController.php | 35 +++---------------- .../logistics/flesserke-article/index.twig | 4 +-- .../logistics/inventory-article/delete.twig | 3 ++ .../logistics/inventory-article/index.twig | 21 ++++++++++- 5 files changed, 29 insertions(+), 38 deletions(-) diff --git a/module/LogisticsBundle/Controller/FlesserkeArticleController.php b/module/LogisticsBundle/Controller/FlesserkeArticleController.php index 463474f1b3..e4e42ff681 100644 --- a/module/LogisticsBundle/Controller/FlesserkeArticleController.php +++ b/module/LogisticsBundle/Controller/FlesserkeArticleController.php @@ -142,20 +142,18 @@ 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( diff --git a/module/LogisticsBundle/Controller/InventoryArticleController.php b/module/LogisticsBundle/Controller/InventoryArticleController.php index a7f4882291..064474f7e7 100644 --- a/module/LogisticsBundle/Controller/InventoryArticleController.php +++ b/module/LogisticsBundle/Controller/InventoryArticleController.php @@ -384,50 +384,23 @@ public function editArticlesAction(): ViewModel ); } - public function deleteAction(): ViewModel + public function deleteAction() { - $academic = $this->getAcademicEntity(); - if ($academic === null) { - $this->redirect()->toRoute( - 'logistics_inventory_article', - array( - 'action' => 'index', - ) - ); - return new ViewModel(); - } + $this->initAjax(); $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', + return new ViewModel( array( - 'action' => 'index', + 'result' => (object) array('status' => 'success'), ) ); - - return new ViewModel(); } public function searchArticlesAction(): ViewModel diff --git a/module/LogisticsBundle/Resources/views/logistics/flesserke-article/index.twig b/module/LogisticsBundle/Resources/views/logistics/flesserke-article/index.twig index 7d7be1c464..a03e966868 100644 --- a/module/LogisticsBundle/Resources/views/logistics/flesserke-article/index.twig +++ b/module/LogisticsBundle/Resources/views/logistics/flesserke-article/index.twig @@ -164,12 +164,10 @@ 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 + location.reload(); }, error: function (xhr, status, error) { - // Handle error alert('{{ translate('An error occurred while deleting the article.') }}'); } }); diff --git a/module/LogisticsBundle/Resources/views/logistics/inventory-article/delete.twig b/module/LogisticsBundle/Resources/views/logistics/inventory-article/delete.twig index e69de29bb2..9737a77083 100644 --- a/module/LogisticsBundle/Resources/views/logistics/inventory-article/delete.twig +++ b/module/LogisticsBundle/Resources/views/logistics/inventory-article/delete.twig @@ -0,0 +1,3 @@ +{% autoescape false %} + {{ result|json_encode }} +{% endautoescape %} \ No newline at end of file diff --git a/module/LogisticsBundle/Resources/views/logistics/inventory-article/index.twig b/module/LogisticsBundle/Resources/views/logistics/inventory-article/index.twig index 276a31943c..d98e987b40 100644 --- a/module/LogisticsBundle/Resources/views/logistics/inventory-article/index.twig +++ b/module/LogisticsBundle/Resources/views/logistics/inventory-article/index.twig @@ -164,7 +164,7 @@ {{ translate('Edit') }} - + {{ translate('Delete') }} @@ -203,6 +203,25 @@ $('a[rel=popover], span[rel=popover]').popover({'trigger': 'hover', 'html': true}); + $('.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) { + alert('{{ translate('Article deleted successfully.') }}'); + location.reload(); + }, + error: function (xhr, status, error) { + alert('{{ translate('An error occurred while deleting the article.') }}'); + } + }); + } + }); + {% if hasAccess('logistics_inventory_article', 'search') %} $.searchDatabase({ defaultPage: $('#default_page'), From 2e799dd50cd6ce4bbc64716f3634d444dad00ab2 Mon Sep 17 00:00:00 2001 From: d1ff1cult0 Date: Mon, 30 Sep 2024 14:32:43 +0200 Subject: [PATCH 4/4] Added empty line --- .../LogisticsBundle/Controller/FlesserkeArticleController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/LogisticsBundle/Controller/FlesserkeArticleController.php b/module/LogisticsBundle/Controller/FlesserkeArticleController.php index e4e42ff681..ebf91924a3 100644 --- a/module/LogisticsBundle/Controller/FlesserkeArticleController.php +++ b/module/LogisticsBundle/Controller/FlesserkeArticleController.php @@ -142,7 +142,7 @@ public function editAction(): ViewModel ), ); } - + public function deleteAction() { $this->initAjax();