From e4d26bb8fd882202adf7a81ff13bb7c21451b277 Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Sat, 6 Jul 2019 17:31:17 +0200 Subject: [PATCH] Make it possible to switch shopping list items between shopping lists (closes #284) --- changelog/50_2.4.3_2019-xx-xx.md | 1 + controllers/StockController.php | 2 ++ public/viewjs/shoppinglistitemform.js | 14 +++++++++----- views/shoppinglistitemform.blade.php | 9 +++++++++ 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/changelog/50_2.4.3_2019-xx-xx.md b/changelog/50_2.4.3_2019-xx-xx.md index 2d9fe270..0273776e 100644 --- a/changelog/50_2.4.3_2019-xx-xx.md +++ b/changelog/50_2.4.3_2019-xx-xx.md @@ -5,3 +5,4 @@ - Improved recipes API - added new endpoints to get stock fulfillment information (thanks @Aerex) - Improved date display for products that never expires (instead of "2999-12-31" now just "Never" will be shown) - Improved date display for dates of today and no time (instead of the hours since midnight now just "Today" will be shown) +- Improved shopping list handling, items can now be switched between lists (there is a shopping list dropdown on the item edit page) diff --git a/controllers/StockController.php b/controllers/StockController.php index a322b0ea..a395d07a 100644 --- a/controllers/StockController.php +++ b/controllers/StockController.php @@ -222,6 +222,7 @@ class StockController extends BaseController { return $this->AppContainer->view->render($response, 'shoppinglistitemform', [ 'products' => $this->Database->products()->orderBy('name'), + 'shoppingLists' => $this->Database->shopping_lists()->orderBy('name'), 'mode' => 'create' ]); } @@ -230,6 +231,7 @@ class StockController extends BaseController return $this->AppContainer->view->render($response, 'shoppinglistitemform', [ 'listItem' => $this->Database->shopping_list($args['itemId']), 'products' => $this->Database->products()->orderBy('name'), + 'shoppingLists' => $this->Database->shopping_lists()->orderBy('name'), 'mode' => 'edit' ]); } diff --git a/public/viewjs/shoppinglistitemform.js b/public/viewjs/shoppinglistitemform.js index c7248a0d..c2113aad 100644 --- a/public/viewjs/shoppinglistitemform.js +++ b/public/viewjs/shoppinglistitemform.js @@ -3,7 +3,6 @@ e.preventDefault(); var jsonData = $('#shoppinglist-form').serializeJSON(); - jsonData.shopping_list_id = GetUriParam("list"); Grocy.FrontendHelpers.BeginUiBusy("shoppinglist-form"); if (Grocy.EditMode === 'create') @@ -11,7 +10,7 @@ Grocy.Api.Post('objects/shopping_list', jsonData, function(result) { - window.location.href = U('/shoppinglist?list=' + GetUriParam("list")); + window.location.href = U('/shoppinglist?list=' + $("#shopping_list_id").val().toString()); }, function(xhr) { @@ -25,7 +24,7 @@ Grocy.Api.Put('objects/shopping_list/' + Grocy.EditObjectId, jsonData, function(result) { - window.location.href = U('/shoppinglist?list=' + GetUriParam("list")); + window.location.href = U('/shoppinglist?list=' + $("#shopping_list_id").val().toString()); }, function(xhr) { @@ -93,12 +92,12 @@ $('#amount').on('focus', function(e) } }); -$('#shoppinglist-form input').keyup(function (event) +$('#shoppinglist-form input').keyup(function(event) { Grocy.FrontendHelpers.ValidateForm('shoppinglist-form'); }); -$('#shoppinglist-form input').keydown(function (event) +$('#shoppinglist-form input').keydown(function(event) { if (event.keyCode === 13) //Enter { @@ -114,3 +113,8 @@ $('#shoppinglist-form input').keydown(function (event) } } }); + +if (GetUriParam("list") !== undefined) +{ + $("#shopping_list_id").val(GetUriParam("list")); +} diff --git a/views/shoppinglistitemform.blade.php b/views/shoppinglistitemform.blade.php index be88b71b..06021d18 100644 --- a/views/shoppinglistitemform.blade.php +++ b/views/shoppinglistitemform.blade.php @@ -21,6 +21,15 @@
+
+ + +
+ @php if($mode == 'edit') { $productId = $listItem->product_id; } else { $productId = ''; } @endphp @include('components.productpicker', array( 'products' => $products,