Allow best before date on purchase/inventory to be today or in the past, but display a hint when so (closes #172)

This commit is contained in:
Bernd Bestel 2019-03-10 16:02:13 +01:00
parent 3d485d4850
commit bfcd05473a
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
5 changed files with 32 additions and 11 deletions

View File

@ -139,7 +139,7 @@ return array(
'This cannot be negative' => 'This cannot be negative', 'This cannot be negative' => 'This cannot be negative',
'A quantity unit is required' => 'A quantity unit is required', 'A quantity unit is required' => 'A quantity unit is required',
'A period type is required' => 'A period type is required', 'A period type is required' => 'A period type is required',
'A best before date is required and must be later than today' => 'A best before date is required and must be later than today', 'A best before date is required' => 'A best before date is required',
'Settings' => 'Settings', 'Settings' => 'Settings',
'This can only be before now' => 'This can only be before now', 'This can only be before now' => 'This can only be before now',
'Calendar' => 'Calendar', 'Calendar' => 'Calendar',
@ -354,5 +354,6 @@ return array(
'Journal for this battery' => 'Journal for this battery', 'Journal for this battery' => 'Journal for this battery',
'System info' => 'System info', 'System info' => 'System info',
'Changelog' => 'Changelog', 'Changelog' => 'Changelog',
'will be multiplied a factor of #1 to get #2' => 'will be multiplied a factor of #1 to get #2' 'will be multiplied a factor of #1 to get #2' => 'will be multiplied a factor of #1 to get #2',
'The given date is earlier than today, are you sure?' => 'The given date is earlier than today, are you sure?'
); );

View File

@ -193,6 +193,19 @@ Grocy.Components.DateTimePicker.GetInputElement().on('keyup', function(e)
{ {
element.setCustomValidity(""); element.setCustomValidity("");
} }
var earlierThanLimit = Grocy.Components.DateTimePicker.GetInputElement().data("earlier-than-limit");
if (!earlierThanLimit.isEmpty())
{
if (moment(value).isBefore(moment(earlierThanLimit)))
{
$("#datetimepicker-earlier-than-info").removeClass("d-none");
}
else
{
$("#datetimepicker-earlier-than-info").addClass("d-none");
}
}
} }
// "Click" the shortcut checkbox when the shortcut value was // "Click" the shortcut checkbox when the shortcut value was

View File

@ -4,6 +4,8 @@
@php if(!isset($isRequired)) { $isRequired = true; } @endphp @php if(!isset($isRequired)) { $isRequired = true; } @endphp
@php if(!isset($initialValue)) { $initialValue = ''; } @endphp @php if(!isset($initialValue)) { $initialValue = ''; } @endphp
@php if(empty($earlierThanInfoLimit)) { $earlierThanInfoLimit = ''; } @endphp
@php if(empty($earlierThanInfoText)) { $earlierThanInfoText = ''; } @endphp
<div class="form-group"> <div class="form-group">
<label for="{{ $id }}">{{ $L($label) }} <label for="{{ $id }}">{{ $L($label) }}
@ -20,12 +22,14 @@
data-init-value="{{ $initialValue }}" data-init-value="{{ $initialValue }}"
data-limit-end-to-now="{{ BoolToString($limitEndToNow) }}" data-limit-end-to-now="{{ BoolToString($limitEndToNow) }}"
data-limit-start-to-now="{{ BoolToString($limitStartToNow) }}" data-limit-start-to-now="{{ BoolToString($limitStartToNow) }}"
data-next-input-selector="{{ $nextInputSelector }}" /> data-next-input-selector="{{ $nextInputSelector }}"
data-earlier-than-limit="{{ $earlierThanInfoLimit }}" />
<div class="input-group-append" data-target="#{{ $id }}" data-toggle="datetimepicker"> <div class="input-group-append" data-target="#{{ $id }}" data-toggle="datetimepicker">
<div class="input-group-text"><i class="fas fa-calendar"></i></div> <div class="input-group-text"><i class="fas fa-calendar"></i></div>
</div> </div>
<div class="invalid-feedback">{{ $invalidFeedback }}</div> <div class="invalid-feedback">{{ $invalidFeedback }}</div>
</div> </div>
<div id="datetimepicker-earlier-than-info" class="form-text text-info font-italic d-none">{{ $earlierThanInfoText }}</div>
@if(isset($shortcutValue) && isset($shortcutLabel)) @if(isset($shortcutValue) && isset($shortcutLabel))
<div class="form-check w-100"> <div class="form-check w-100">
<input class="form-check-input" type="checkbox" id="datetimepicker-shortcut" data-datetimepicker-shortcut-value="{{ $shortcutValue }}"> <input class="form-check-input" type="checkbox" id="datetimepicker-shortcut" data-datetimepicker-shortcut-value="{{ $shortcutValue }}">

View File

@ -35,12 +35,14 @@
'format' => 'YYYY-MM-DD', 'format' => 'YYYY-MM-DD',
'initWithNow' => false, 'initWithNow' => false,
'limitEndToNow' => false, 'limitEndToNow' => false,
'limitStartToNow' => true, 'limitStartToNow' => false,
'invalidFeedback' => $L('A best before date is required and must be later than today'), 'invalidFeedback' => $L('A best before date is required'),
'nextInputSelector' => '#best_before_date', 'nextInputSelector' => '#best_before_date',
'additionalCssClasses' => 'date-only-datetimepicker', 'additionalCssClasses' => 'date-only-datetimepicker',
'shortcutValue' => '2999-12-31', 'shortcutValue' => '2999-12-31',
'shortcutLabel' => 'Never expires' 'shortcutLabel' => 'Never expires',
'earlierThanInfoLimit' => date('Y-m-d'),
'earlierThanInfoText' => $L('The given date is earlier than today, are you sure?')
)) ))
<button id="save-inventory-button" class="btn btn-success">{{ $L('OK') }}</button> <button id="save-inventory-button" class="btn btn-success">{{ $L('OK') }}</button>

View File

@ -22,12 +22,14 @@
'format' => 'YYYY-MM-DD', 'format' => 'YYYY-MM-DD',
'initWithNow' => false, 'initWithNow' => false,
'limitEndToNow' => false, 'limitEndToNow' => false,
'limitStartToNow' => true, 'limitStartToNow' => false,
'invalidFeedback' => $L('A best before date is required and must be later than today'), 'invalidFeedback' => $L('A best before date is required'),
'nextInputSelector' => '#amount', 'nextInputSelector' => '#amount',
'additionalCssClasses' => 'date-only-datetimepicker', 'additionalCssClasses' => 'date-only-datetimepicker',
'shortcutValue' => '2999-12-31', 'shortcutValue' => '2999-12-31',
'shortcutLabel' => 'Never expires' 'shortcutLabel' => 'Never expires',
'earlierThanInfoLimit' => date('Y-m-d'),
'earlierThanInfoText' => $L('The given date is earlier than today, are you sure?')
)) ))
@include('components.numberpicker', array( @include('components.numberpicker', array(
@ -52,8 +54,7 @@
@include('components.locationpicker', array( @include('components.locationpicker', array(
'locations' => $locations, 'locations' => $locations,
'isRequired' => false, 'isRequired' => false
'hint' => $L('This is for statistical purposes only')
)) ))
<button id="save-purchase-button" class="btn btn-success">{{ $L('OK') }}</button> <button id="save-purchase-button" class="btn btn-success">{{ $L('OK') }}</button>