From e165fd3ef3649b407495a0446a75086ec4ca802a Mon Sep 17 00:00:00 2001 From: Jacek Pyziak Date: Wed, 17 Dec 2025 23:04:07 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20Dodaj=20funkcjonalno=C5=9B=C4=87=20usuw?= =?UTF-8?q?ania=20produkt=C3=B3w=20oraz=20aktualizacj=C4=99=20interfejsu?= =?UTF-8?q?=20u=C5=BCytkownika?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/ftp-kr.sync.cache.json | 6 +-- autoload/controls/class.Products.php | 13 +++++- autoload/factory/class.Products.php | 6 +++ templates/products/main_view.php | 62 +++++++++++++++++++++++++++- 4 files changed, 82 insertions(+), 5 deletions(-) diff --git a/.vscode/ftp-kr.sync.cache.json b/.vscode/ftp-kr.sync.cache.json index 540a36a..46b4757 100644 --- a/.vscode/ftp-kr.sync.cache.json +++ b/.vscode/ftp-kr.sync.cache.json @@ -167,9 +167,9 @@ }, "product_history.php": { "type": "-", - "size": 10080, - "lmtime": 1755699713875, - "modified": true + "size": 10103, + "lmtime": 1764629661097, + "modified": false } }, "site": { diff --git a/autoload/controls/class.Products.php b/autoload/controls/class.Products.php index 2e5fc6a..3ca467e 100644 --- a/autoload/controls/class.Products.php +++ b/autoload/controls/class.Products.php @@ -176,7 +176,8 @@ class Products $roasCellHtml, '', '', - '' + '', + 'Usuń' ]; } @@ -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' ); diff --git a/autoload/factory/class.Products.php b/autoload/factory/class.Products.php index 79ed6b8..267ecaa 100644 --- a/autoload/factory/class.Products.php +++ b/autoload/factory/class.Products.php @@ -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; diff --git a/templates/products/main_view.php b/templates/products/main_view.php index 6404017..3a14a5c 100644 --- a/templates/products/main_view.php +++ b/templates/products/main_view.php @@ -46,6 +46,7 @@ Min. ROAS CL3 CL4 + Akcje @@ -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 );