Skip to content

Commit

Permalink
Added delete button for /logistics/flesserke
Browse files Browse the repository at this point in the history
  • Loading branch information
d1ff1cult0 committed Sep 30, 2024
1 parent ff3f992 commit 2ae947c
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 2 deletions.
21 changes: 21 additions & 0 deletions module/LogisticsBundle/Controller/FlesserkeArticleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,27 @@ public function editAction(): ViewModel
),
);
}

Check failure on line 144 in module/LogisticsBundle/Controller/FlesserkeArticleController.php

View workflow job for this annotation

GitHub Actions / Lint

Expected 1 blank line after function; 0 found
public function deleteAction()
{
error_log("Delete action initiated");

Check failure on line 147 in module/LogisticsBundle/Controller/FlesserkeArticleController.php

View workflow job for this annotation

GitHub Actions / Lint

String "Delete action initiated" does not require double quotes; use single quotes instead
$this->initAjax();

$article = $this->getFlesserkeArticleEntity();
if ($article === null) {
error_log("Article not found");

Check failure on line 152 in module/LogisticsBundle/Controller/FlesserkeArticleController.php

View workflow job for this annotation

GitHub Actions / Lint

String "Article not found" does not require double quotes; use single quotes instead
return new ViewModel();
}

$this->getEntityManager()->remove($article);
$this->getEntityManager()->flush();
error_log("Removed");

Check failure on line 158 in module/LogisticsBundle/Controller/FlesserkeArticleController.php

View workflow job for this annotation

GitHub Actions / Lint

String "Removed" does not require double quotes; use single quotes instead

return new ViewModel(
array(
'result' => (object) array('status' => 'success'),
)
);
}

public function searchAction(): ViewModel
{
Expand Down
46 changes: 46 additions & 0 deletions module/LogisticsBundle/Controller/InventoryArticleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
),
),
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% autoescape false %}
{{ result|json_encode }}
{% endautoescape %}
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@
<a href="{{ url('logistics_flesserke_article', {"action" : 'edit', "article" : article.getId()}) }}" class="btn btn-warning btn-xs">
{{ translate('Edit') }}
</a>
<a href="{{ url('logistics_flesserke_article', {"action" : 'delete', "article" : article.getId()}) }}" class="btn btn-warning btn-xs delete-article">
{{ translate('Delete') }}
</a>
</td>
{% endif %}
</tr>
Expand Down Expand Up @@ -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') %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@
<a href="{{ url('logistics_inventory_article', {"action" : 'edit', "article" : article.getId()}) }}" class="btn btn-warning btn-xs">
{{ translate('Edit') }}
</a>
<a href="{{ url('logistics_inventory_article', {"action" : 'delete', "article" : article.getId()}) }}" class="btn btn-warning btn-xs">
{{ translate('Delete') }}
</a>
</td>
{% endif %}
</tr>
Expand Down Expand Up @@ -161,6 +164,9 @@
<a href="{{ url('logistics_inventory_article', {"action" : 'edit', "article" : article.getId()}) }}" class="btn btn-warning btn-xs">
{{ translate('Edit') }}
</a>
<a href="{{ url('logistics_inventory_article', {"action" : 'delete', "article" : article.getId()}) }}" class="btn btn-warning btn-xs delete">
{{ translate('Delete') }}
</a>
</td>
{% endif %}
</tr>
Expand Down Expand Up @@ -249,6 +255,7 @@
}
});
{% endif %}
});
function openSearchRequest(e) {
Expand Down

0 comments on commit 2ae947c

Please sign in to comment.