From 04c93d937e8b0d4c42740b1db34ae48d3cb640c5 Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Sat, 20 Oct 2018 14:55:49 +0200 Subject: [PATCH] Make presets for new products configurable (closes #92) --- config-dist.php | 3 +++ controllers/StockController.php | 9 +++++++ localization/de.php | 1 + public/js/grocy.js | 7 ++++- public/viewjs/productform.js | 18 +++++++++++++ public/viewjs/productpresets.js | 3 +++ routes.php | 1 + views/productform.blade.php | 3 +++ views/productpresets.blade.php | 45 +++++++++++++++++++++++++++++++++ views/products.blade.php | 3 +++ 10 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 public/viewjs/productpresets.js create mode 100644 views/productpresets.blade.php diff --git a/config-dist.php b/config-dist.php index 44bdc278..6f2318fc 100644 --- a/config-dist.php +++ b/config-dist.php @@ -38,6 +38,9 @@ DefaultUserSetting('auto_night_mode_time_range_from', "20:00"); // Format HH:mm DefaultUserSetting('auto_night_mode_time_range_to', "07:00"); // Format HH:mm DefaultUserSetting('auto_night_mode_time_range_goes_over_midnight', true); // If the time range above goes over midnight DefaultUserSetting('currently_inside_night_mode_range', false); // If we're currently inside of night mode time range (this is not user configurable, but stored as a user setting because it's evaluated client side to be able to use the client time instead of the maybe different server time) +DefaultUserSetting('product_presets_location_id', -1); // Default location id for new products (-1 means no location is preset) +DefaultUserSetting('product_presets_product_group_id', -1); // Default product group id for new products (-1 means no product group is preset) +DefaultUserSetting('product_presets_qu_id', -1); // Default quantity unit id for new products (-1 means no quantity unit is preset) # If the page should be automatically reloaded when there was # an external change diff --git a/controllers/StockController.php b/controllers/StockController.php index 1bafe1d1..63e330bd 100644 --- a/controllers/StockController.php +++ b/controllers/StockController.php @@ -70,6 +70,15 @@ class StockController extends BaseController ]); } + public function ProductDefaults(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args) + { + return $this->AppContainer->view->render($response, 'productpresets', [ + 'locations' => $this->Database->locations()->orderBy('name'), + 'quantityunits' => $this->Database->quantity_units()->orderBy('name'), + 'productGroups' => $this->Database->product_groups()->orderBy('name') + ]); + } + public function LocationsList(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args) { return $this->AppContainer->view->render($response, 'locations', [ diff --git a/localization/de.php b/localization/de.php index 8dc56887..aa44381f 100644 --- a/localization/de.php +++ b/localization/de.php @@ -279,6 +279,7 @@ return array( 'The current instruction manual will be deleted when you save the equipment' => 'Die aktuelle Bedienungsanleitung wird beim Speichern des Geräts gelöscht', 'No picture available' => 'Kein Bild vorhanden', 'Filter by product group' => 'Nach Produktgruppe filtern', + 'Presets for new products' => 'Vorgaben für neue Produkte', //Constants 'manually' => 'Manuell', diff --git a/public/js/grocy.js b/public/js/grocy.js index 1d925244..31f894ce 100644 --- a/public/js/grocy.js +++ b/public/js/grocy.js @@ -283,8 +283,13 @@ $("form").on("click", "select", function() $(".user-setting-control").on("change", function() { var element = $(this); - var inputType = element.attr("type").toLowerCase(); var settingKey = element.attr("data-setting-key"); + + var inputType = "unknown"; + if (typeof element.attr("type") !== typeof undefined && element.attr("type") !== false) + { + inputType = element.attr("type").toLowerCase(); + } if (inputType === "checkbox") { diff --git a/public/viewjs/productform.js b/public/viewjs/productform.js index a87aed14..311ae065 100644 --- a/public/viewjs/productform.js +++ b/public/viewjs/productform.js @@ -196,6 +196,24 @@ $('#delete-current-product-picture-button').on('click', function (e) $("#delete-current-product-picture-button").addClass("disabled"); }); +if (Grocy.EditMode === 'create') +{ + if (Grocy.UserSettings.product_presets_location_id.toString() !== '-1') + { + $("#location_id").val(Grocy.UserSettings.product_presets_location_id); + } + + if (Grocy.UserSettings.product_presets_product_group_id.toString() !== '-1') + { + $("#product_group_id").val(Grocy.UserSettings.product_presets_product_group_id); + } + + if (Grocy.UserSettings.product_presets_qu_id.toString() !== '-1') + { + $("select.input-group-qu").val(Grocy.UserSettings.product_presets_qu_id); + } +} + $('#name').focus(); $('.input-group-qu').trigger('change'); Grocy.FrontendHelpers.ValidateForm('product-form'); diff --git a/public/viewjs/productpresets.js b/public/viewjs/productpresets.js new file mode 100644 index 00000000..5280271a --- /dev/null +++ b/public/viewjs/productpresets.js @@ -0,0 +1,3 @@ +$("#product_presets_location_id").val(Grocy.UserSettings.product_presets_location_id); +$("#product_presets_product_group_id").val(Grocy.UserSettings.product_presets_product_group_id); +$("#product_presets_qu_id").val(Grocy.UserSettings.product_presets_qu_id); diff --git a/routes.php b/routes.php index 4b3cbce7..3014f735 100644 --- a/routes.php +++ b/routes.php @@ -26,6 +26,7 @@ $app->group('', function() $this->get('/inventory', '\Grocy\Controllers\StockController:Inventory'); $this->get('/products', '\Grocy\Controllers\StockController:ProductsList'); $this->get('/product/{productId}', '\Grocy\Controllers\StockController:ProductEditForm'); + $this->get('/productpresets', '\Grocy\Controllers\StockController:ProductDefaults'); $this->get('/locations', '\Grocy\Controllers\StockController:LocationsList'); $this->get('/location/{locationId}', '\Grocy\Controllers\StockController:LocationEditForm'); $this->get('/quantityunits', '\Grocy\Controllers\StockController:QuantityUnitsList'); diff --git a/views/productform.blade.php b/views/productform.blade.php index c34c9721..a6e149b4 100644 --- a/views/productform.blade.php +++ b/views/productform.blade.php @@ -46,6 +46,7 @@
+ @foreach($quantityunits as $quantityunit) @endforeach @@ -95,6 +97,7 @@
+ + @foreach($locations as $location) + + @endforeach + +
+ +
+ + +
+ +
+ + +
+ + {{ $L('OK') }} +
+ +@stop diff --git a/views/products.blade.php b/views/products.blade.php index 8d9da003..56323c2a 100644 --- a/views/products.blade.php +++ b/views/products.blade.php @@ -12,6 +12,9 @@  {{ $L('Add') }} + +  {{ $L('Presets for new products') }} +