From b45d4adafb7eb6dbf9f80c3663e19fee1f280043 Mon Sep 17 00:00:00 2001 From: DariusIII Date: Thu, 24 May 2018 15:23:32 +0200 Subject: [PATCH] Fix deletion from cart when using multioperation --- Changelog | 1 + app/Http/Controllers/CartController.php | 6 +++--- public/assets/js/functions.js | 13 +++++++++---- routes/web.php | 1 + 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Changelog b/Changelog index 5e600e256..a8f39e5ef 100755 --- a/Changelog +++ b/Changelog @@ -1,4 +1,5 @@ 2018-05-24 DariusIII + * Fix: Fix deletion from cart when using multioperation * Chg: Update barryvdh/laravel-debugbar to version 3.1.5 * Chg: Comment out test message from functions.js * Chg: Allow nzb downloads for not logged in users (sab/nzbget are not logged in) diff --git a/app/Http/Controllers/CartController.php b/app/Http/Controllers/CartController.php index f1e1d7dd1..77de722ac 100644 --- a/app/Http/Controllers/CartController.php +++ b/app/Http/Controllers/CartController.php @@ -57,7 +57,7 @@ class CartController extends BasePageController } /** - * @param $id + * @param string|array $id * * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector * @throws \Exception @@ -67,12 +67,12 @@ class CartController extends BasePageController $this->setPrefs(); $ids = null; if (! empty($id)) { - $ids = (array) $id; + $ids = explode(',', $id); } elseif (\is_array($id)) { $ids = $id; } - if ($ids !== null && UsersRelease::delCartByGuid($ids, Auth::id())) { + if (!empty($ids) && UsersRelease::delCartByGuid($ids, $this->userdata->id)) { return redirect('/cart/index'); } diff --git a/public/assets/js/functions.js b/public/assets/js/functions.js index 8c9e46972..7e664320c 100755 --- a/public/assets/js/functions.js +++ b/public/assets/js/functions.js @@ -679,6 +679,13 @@ jQuery(function($){ if ($(row).val()!="on") ids.push($(row).val()); }); + $.ajaxSetup({ + headers: { + 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') + } + }); + + //alert(SERVERROOT + "/cart/delete/" + ids); if (ids) { PNotify.prototype.options.styling = "fontawesome"; @@ -698,9 +705,7 @@ jQuery(function($){ history: false } })).get().on('pnotify.confirm', function() { - $.post( SERVERROOT + "/cart/delete/", { 'delete': ids }, function(resp){ - location.reload(true); - }); + $.post( SERVERROOT + "/cart/delete/" + ids) }).on('pnotify.cancel', function() { alert('Cancelled'); }); @@ -711,7 +716,7 @@ jQuery(function($){ $("table.data INPUT[type='checkbox']:checked").each( function(i, row) { var guid = $(row).val(); var nzburl = SERVERROOT + "sendtoqueue/" + guid; - $.post( nzburl, function(resp){ + $.post( nzburl, function(){ PNotify.prototype.options.styling = "fontawesome"; PNotify.desktop.permission(); (new PNotify({ diff --git a/routes/web.php b/routes/web.php index 1e162336d..a204cfb07 100644 --- a/routes/web.php +++ b/routes/web.php @@ -46,6 +46,7 @@ Route::post('Books/{id?}', 'BooksController@index'); Route::prefix('cart')->group(function () { Route::get('index', 'CartController@index'); + Route::post('index', 'CartController@index'); Route::get('add', 'CartController@store'); Route::post('add', 'CartController@store'); Route::get('delete/{id}', 'CartController@destroy');