Make presets for new products configurable (closes #92)

This commit is contained in:
Bernd Bestel 2018-10-20 14:55:49 +02:00
parent 5318e79f55
commit 04c93d937e
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
10 changed files with 92 additions and 1 deletions

View File

@ -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

View File

@ -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', [

View File

@ -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',

View File

@ -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")
{

View File

@ -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');

View File

@ -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);

View File

@ -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');

View File

@ -46,6 +46,7 @@
<div class="form-group">
<label for="location_id">{{ $L('Location') }}</label>
<select required class="form-control" id="location_id" name="location_id">
<option></option>
@foreach($locations as $location)
<option @if($mode == 'edit' && $location->id == $product->location_id) selected="selected" @endif value="{{ $location->id }}">{{ $location->name }}</option>
@endforeach
@ -85,6 +86,7 @@
<div class="form-group">
<label for="qu_id_purchase">{{ $L('Quantity unit purchase') }}</label>
<select required class="form-control input-group-qu" id="qu_id_purchase" name="qu_id_purchase">
<option></option>
@foreach($quantityunits as $quantityunit)
<option @if($mode == 'edit' && $quantityunit->id == $product->qu_id_purchase) selected="selected" @endif value="{{ $quantityunit->id }}">{{ $quantityunit->name }}</option>
@endforeach
@ -95,6 +97,7 @@
<div class="form-group">
<label for="qu_id_stock">{{ $L('Quantity unit stock') }}</label>
<select required class="form-control input-group-qu" id="qu_id_stock" name="qu_id_stock">
<option></option>
@foreach($quantityunits as $quantityunit)
<option @if($mode == 'edit' && $quantityunit->id == $product->qu_id_stock) selected="selected" @endif value="{{ $quantityunit->id }}">{{ $quantityunit->name }}</option>
@endforeach

View File

@ -0,0 +1,45 @@
@extends('layout.default')
@section('title', $L('Presets for new products'))
@section('viewJsName', 'productpresets')
@section('content')
<div class="row">
<div class="col-lg-6 col-xs-12">
<h1>@yield('title')</h1>
<div class="form-group">
<label for="product_presets_location_id">{{ $L('Location') }}</label>
<select class="form-control user-setting-control" id="product_presets_location_id" data-setting-key="product_presets_location_id">
<option value="-1"></option>
@foreach($locations as $location)
<option value="{{ $location->id }}">{{ $location->name }}</option>
@endforeach
</select>
</div>
<div class="form-group">
<label for="product_presets_product_group_id">{{ $L('Product group') }}</label>
<select class="form-control user-setting-control" id="product_presets_product_group_id" data-setting-key="product_presets_product_group_id">
<option value="-1"></option>
@foreach($productgroups as $productgroup)
<option value="{{ $productgroup->id }}">{{ $productgroup->name }}</option>
@endforeach
</select>
</div>
<div class="form-group">
<label for="product_presets_qu_id">{{ $L('Quantity unit purchase') }}</label>
<select class="form-control user-setting-control" id="product_presets_qu_id" data-setting-key="product_presets_qu_id">
<option value="-1"></option>
@foreach($quantityunits as $quantityunit)
<option value="{{ $quantityunit->id }}">{{ $quantityunit->name }}</option>
@endforeach
</select>
</div>
<a href="{{ $U('/products') }}" class="btn btn-success">{{ $L('OK') }}</a>
</div>
</div>
@stop

View File

@ -12,6 +12,9 @@
<a class="btn btn-outline-dark" href="{{ $U('/product/new') }}">
<i class="fas fa-plus"></i>&nbsp;{{ $L('Add') }}
</a>
<a class="btn btn-outline-secondary" href="{{ $U('/productpresets') }}">
<i class="fas fa-sliders-h"></i>&nbsp;{{ $L('Presets for new products') }}
</a>
</h1>
</div>
</div>