Skip to content

Commit

Permalink
Merge branch 'Logi-flesserke-delete-button'
Browse files Browse the repository at this point in the history
  • Loading branch information
d1ff1cult0 committed Sep 30, 2024
2 parents 2b5e406 + 2e799dd commit a5b4ae7
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 2 deletions.
19 changes: 19 additions & 0 deletions module/LogisticsBundle/Controller/FlesserkeArticleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,25 @@ public function editAction(): ViewModel
);
}

public function deleteAction()
{
$this->initAjax();

$article = $this->getFlesserkeArticleEntity();
if ($article === null) {
return new ViewModel();
}

$this->getEntityManager()->remove($article);
$this->getEntityManager()->flush();

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

public function searchAction(): ViewModel
{
$this->initAjax();
Expand Down
19 changes: 19 additions & 0 deletions module/LogisticsBundle/Controller/InventoryArticleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,25 @@ public function editArticlesAction(): ViewModel
);
}

public function deleteAction()
{
$this->initAjax();

$article = $this->getInventoryArticleEntity();
if ($article === null) {
return new ViewModel();
}

$this->getEntityManager()->remove($article);
$this->getEntityManager()->flush();

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

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,25 @@
$(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) {
alert('{{ translate('Article deleted successfully.') }}');
location.reload();
},
error: function (xhr, status, 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
@@ -0,0 +1,3 @@
{% autoescape false %}
{{ result|json_encode }}
{% endautoescape %}
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-article">
{{ translate('Delete') }}
</a>
</td>
{% endif %}
</tr>
Expand Down Expand Up @@ -197,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'),
Expand Down Expand Up @@ -249,6 +274,7 @@
}
});
{% endif %}
});
function openSearchRequest(e) {
Expand Down

0 comments on commit a5b4ae7

Please sign in to comment.