feat: Dodaj funkcjonalność usuwania produktów oraz aktualizację interfejsu użytkownika

This commit is contained in:
2025-12-17 23:04:07 +01:00
parent 7c8df8585a
commit e165fd3ef3
4 changed files with 82 additions and 5 deletions

View File

@@ -167,9 +167,9 @@
},
"product_history.php": {
"type": "-",
"size": 10080,
"lmtime": 1755699713875,
"modified": true
"size": 10103,
"lmtime": 1764629661097,
"modified": false
}
},
"site": {

View File

@@ -176,7 +176,8 @@ class Products
$roasCellHtml,
'<input type="text" class="form-control min_roas" product_id="' . $row['product_id'] . '" value="' . $row['min_roas'] . '" style="width: 100px;">',
'',
'<input type="text" class="form-control custom_label_4" product_id="' . $row['product_id'] . '" value="' . $custom_label_4 . '" style="' . $custom_label_4_color . '">'
'<input type="text" class="form-control custom_label_4" product_id="' . $row['product_id'] . '" value="' . $custom_label_4 . '" style="' . $custom_label_4_color . '">',
'<a href="#" class="text-danger delete-product" product_id="' . $row['product_id'] . '">Usuń</a>'
];
}
@@ -184,6 +185,16 @@ class Products
exit;
}
static public function delete_product() {
$product_id = \S::get( 'product_id' );
if ( \factory\Products::delete_product( $product_id ) )
echo json_encode( [ 'status' => 'ok' ] );
else
echo json_encode( [ 'status' => 'error' ] );
exit;
}
static public function save_min_roas()
{
$product_id = \S::get( 'product_id' );

View File

@@ -2,6 +2,12 @@
namespace factory;
class Products
{
static public function delete_product( $product_id ) {
global $mdb;
$mdb -> delete( 'products', [ 'id' => $product_id ] );
return true;
}
static public function get_product_comments( $product_id )
{
global $mdb;

View File

@@ -46,6 +46,7 @@
<th scope="col">Min. ROAS</th>
<th scope="col">CL3</th>
<th scope="col">CL4</th>
<th scope="col">Akcje</th>
</tr>
</thead>
<tbody>
@@ -143,11 +144,70 @@
{ width: 'auto', name: 'roas' },
{ width: '100px', name: 'min_roas' },
{ width: 'auto', name: 'cl3', orderable: false },
{ width: '200px', orderable: false }],
{ width: '200px', orderable: false },
{ width: '100px', orderable: false }],
order: [ [ 5, 'desc' ] ]
});
});
$( 'body' ).on( 'click', '.delete-product', function(e)
{
e.preventDefault();
var product_id = $( this ).attr( 'product_id' );
var row = $( this ).closest('tr');
$.confirm({
title: 'Potwierdzenie',
content: 'Czy na pewno chcesz usunąć ten produkt?',
buttons: {
confirm: {
text: 'Usuń',
keys: ['enter'],
action: function () {
$.ajax({
url: '/products/delete_product/',
type: 'POST',
data: {
product_id: product_id
},
success: function( response ) {
data = JSON.parse(response);
if ( data.status == 'ok' )
{
// change to alert with auto close after 2 seconds
$.alert({
title: 'Sukces',
content: 'Produkt został usunięty.',
autoClose: 'ok|2000',
buttons: {
ok: function () {
}
}
});
// usuń wiersz z tabeli
var table = $('#products').DataTable();
table.row(row).remove().draw();
}
else
{
$.alert('Błąd: ' + response);
}
},
error: function() {
$.alert('Wystąpił błąd podczas usuwania produktu. Spróbuj ponownie.');
}
});
}
},
cancel: {
text: 'Anuluj',
action: function () {
}
}
}
});
});
$( 'body' ).on( 'change', '.min_roas', function()
{
var input = $( this );