From 37d1377f99fef2d7342067e2c9f346b896a8371b Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Thu, 12 Jul 2018 19:12:31 +0200 Subject: [PATCH] Fixed the rest of the broken stuff after the dependency upgrade party --- app.php | 1 + config-dist.php | 14 +- helpers/extensions.php | 13 ++ localization/de.php | 4 +- localization/en.php | 1 - package.json | 1 - public/viewjs/components/datepicker.js | 92 ---------- public/viewjs/components/datetimepicker.js | 185 ++++++++++++++++++--- public/viewjs/consume.js | 10 +- public/viewjs/habittracking.js | 13 +- public/viewjs/inventory.js | 40 ++--- public/viewjs/purchase.js | 25 +-- public/viewjs/shoppinglistform.js | 8 +- version.json | 4 +- views/batteriesoverview.blade.php | 2 +- views/batterytracking.blade.php | 9 +- views/components/datepicker.blade.php | 14 -- views/components/datetimepicker.blade.php | 11 +- views/consume.blade.php | 2 +- views/habitsoverview.blade.php | 2 +- views/habittracking.blade.php | 9 +- views/inventory.blade.php | 14 +- views/layout/default.blade.php | 5 +- views/purchase.blade.php | 12 +- views/shoppinglistform.blade.php | 4 +- views/stockoverview.blade.php | 4 +- yarn.lock | 8 +- 27 files changed, 271 insertions(+), 236 deletions(-) delete mode 100644 public/viewjs/components/datepicker.js delete mode 100644 views/components/datepicker.blade.php diff --git a/app.php b/app.php index 5a3b4fb2..6308f3e5 100644 --- a/app.php +++ b/app.php @@ -8,6 +8,7 @@ use \Grocy\Controllers\LoginController; require_once __DIR__ . '/vendor/autoload.php'; require_once __DIR__ . '/data/config.php'; +require_once __DIR__ . '/config-dist.php'; //For not in own config defined values we use the default ones // Setup base application $appContainer = new \Slim\Container([ diff --git a/config-dist.php b/config-dist.php index 41ac6b7b..e79f867f 100644 --- a/config-dist.php +++ b/config-dist.php @@ -1,26 +1,26 @@ format('Y-m-d H:i:s') === $dateTimeString; } + +function BoolToString(bool $bool) +{ + return $bool ? 'true' : 'false'; +} + +function Setting(string $name, string $value) +{ + if (!defined($name)) + { + define($name, $value); + } +} diff --git a/localization/de.php b/localization/de.php index 9e05e476..edbd7e86 100644 --- a/localization/de.php +++ b/localization/de.php @@ -141,6 +141,9 @@ return array( 'This cannot be negative' => 'Dies darf nicht negativ sein', 'A quantity unit is required' => 'Eine Mengeneinheit muss ausgewählt werden', 'A period type is required' => 'Eine Periodentyp muss ausgewählt werden', + 'A best before date is required and must be later than today' => 'Ein Mindesthaltbarkeitsdatum ist erforderlich und muss später als heute sein', + 'Settings' => 'Einstellungen', + 'This can only be before now' => 'Dies kann nur vor jetzt sein', //Constants 'manually' => 'Manuell', @@ -150,7 +153,6 @@ return array( 'timeago_locale' => 'de', 'timeago_nan' => 'vor NaN Jahren', 'moment_locale' => 'de', - 'bootstrap_datepicker_locale' => 'de', 'datatables_localization' => '{"sEmptyTable":"Keine Daten in der Tabelle vorhanden","sInfo":"_START_ bis _END_ von _TOTAL_ Einträgen","sInfoEmpty":"Keine Daten vorhanden","sInfoFiltered":"(gefiltert von _MAX_ Einträgen)","sInfoPostFix":"","sInfoThousands":".","sLengthMenu":"_MENU_ Einträge anzeigen","sLoadingRecords":"Wird geladen ..","sProcessing":"Bitte warten ..","sSearch":"Suchen","sZeroRecords":"Keine Einträge vorhanden","oPaginate":{"sFirst":"Erste","sPrevious":"Zurück","sNext":"Nächste","sLast":"Letzte"},"oAria":{"sSortAscending":": aktivieren, um Spalte aufsteigend zu sortieren","sSortDescending":": aktivieren, um Spalte absteigend zu sortieren"},"select":{"rows":{"0":"Zum Auswählen auf eine Zeile klicken","1":"1 Zeile ausgewählt","_":"%d Zeilen ausgewählt"}},"buttons":{"print":"Drucken","colvis":"Spalten","copy":"Kopieren","copyTitle":"In Zwischenablage kopieren","copyKeys":"Taste ctrl oder + C um Tabelle
in Zwischenspeicher zu kopieren.

Um abzubrechen die Nachricht anklicken oder Escape drücken.","copySuccess":{"1":"1 Spalte kopiert","_":"%d Spalten kopiert"}}}', //Demo data diff --git a/localization/en.php b/localization/en.php index 36516dd8..84f00ed2 100644 --- a/localization/en.php +++ b/localization/en.php @@ -9,6 +9,5 @@ return array( 'timeago_locale' => 'en', 'timeago_nan' => 'NaN years ago', 'moment_locale' => '', - 'bootstrap_datepicker_locale' => '', 'datatables_localization' => '{"sEmptyTable":"No data available in table","sInfo":"Showing _START_ to _END_ of _TOTAL_ entries","sInfoEmpty":"Showing 0 to 0 of 0 entries","sInfoFiltered":"(filtered from _MAX_ total entries)","sInfoPostFix":"","sInfoThousands":",","sLengthMenu":"Show _MENU_ entries","sLoadingRecords":"Loading...","sProcessing":"Processing...","sSearch":"Search:","sZeroRecords":"No matching records found","oPaginate":{"sFirst":"First","sLast":"Last","sNext":"Next","sPrevious":"Previous"},"oAria":{"sSortAscending":": activate to sort column ascending","sSortDescending":": activate to sort column descending"}}' ); diff --git a/package.json b/package.json index d4ad6283..f647ad63 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,6 @@ "TagManager": "https://github.com/max-favilli/tagmanager.git#3.0.2", "bootbox": "https://github.com/makeusabrew/bootbox.git#v5.x", "bootstrap": "^4.1.1", - "bootstrap-datepicker": "^1.8.0", "bootstrap-side-navbar": "https://github.com/samrayner/bootstrap-side-navbar.git#1.0.1", "datatables.net": "^1.10.19", "datatables.net-bs4": "^1.10.19", diff --git a/public/viewjs/components/datepicker.js b/public/viewjs/components/datepicker.js deleted file mode 100644 index 24fafe2f..00000000 --- a/public/viewjs/components/datepicker.js +++ /dev/null @@ -1,92 +0,0 @@ -$(function() -{ - $('.datepicker').datepicker( - { - format: 'yyyy-mm-dd', - startDate: '+0d', - todayHighlight: true, - autoclose: true, - calendarWeeks: true, - orientation: 'bottom auto', - weekStart: 1, - showOnFocus: false, - language: L('bootstrap_datepicker_locale') - }); - $('.datepicker').trigger('change'); - - EmptyElementWhenMatches('#datepicker-timeago', L('timeago_nan')); -}); - -$('.datepicker').on('keydown', function(e) -{ - if (e.keyCode === 13) //Enter - { - $('.datepicker').trigger('change'); - } -}); - -$('.datepicker').on('keypress', function(e) -{ - var element = $(e.target); - var value = element.val(); - var dateObj = moment(element.val(), 'YYYY-MM-DD', true); - - $('.datepicker').datepicker('hide'); - - //If input is empty and any arrow key is pressed, set date to today - if (value.length === 0 && (e.keyCode === 38 || e.keyCode === 40 || e.keyCode === 37 || e.keyCode === 39)) - { - dateObj = moment(new Date(), 'YYYY-MM-DD', true); - } - - if (dateObj.isValid()) - { - if (e.keyCode === 38) //Up - { - element.val(dateObj.add(-1, 'days').format('YYYY-MM-DD')); - } - else if (e.keyCode === 40) //Down - { - element.val(dateObj.add(1, 'days').format('YYYY-MM-DD')); - } - else if (e.keyCode === 37) //Left - { - element.val(dateObj.add(-1, 'weeks').format('YYYY-MM-DD')); - } - else if (e.keyCode === 39) //Right - { - element.val(dateObj.add(1, 'weeks').format('YYYY-MM-DD')); - } - } -}); - -$('.datepicker').on('change', function(e) -{ - var value = $('.datepicker').val(); - var now = new Date(); - var centuryStart = Number.parseInt(now.getFullYear().toString().substring(0, 2) + '00'); - var centuryEnd = Number.parseInt(now.getFullYear().toString().substring(0, 2) + '99'); - - if (value === 'x' || value === 'X') { - value = '29991231'; - } - - if (value.length === 4 && !(Number.parseInt(value) > centuryStart && Number.parseInt(value) < centuryEnd)) - { - value = (new Date()).getFullYear().toString() + value; - } - - if (value.length === 8 && $.isNumeric(value)) - { - value = value.replace(/(\d{4})(\d{2})(\d{2})/, '$1-$2-$3'); - $('.datepicker').val(value); - } - - $('#datepicker-timeago').text($.timeago($('.datepicker').val())); - EmptyElementWhenMatches('#datepicker-timeago', L('timeago_nan')); -}); - -$('#datepicker-button').on('click', function(e) -{ - $('.datepicker').datepicker('show'); -}); diff --git a/public/viewjs/components/datetimepicker.js b/public/viewjs/components/datetimepicker.js index 93b35411..e0aac5a2 100644 --- a/public/viewjs/components/datetimepicker.js +++ b/public/viewjs/components/datetimepicker.js @@ -1,27 +1,162 @@ -$(function() +Grocy.Components.DateTimePicker = { }; + +Grocy.Components.DateTimePicker.GetInputElement = function() { - $('.datetimepicker').datetimepicker( - { - format: 'YYYY-MM-DD HH:mm:ss', - buttons: { - showToday: true, - showClose: true - }, - calendarWeeks: true, - maxDate: moment(), - locale: moment.locale(), - defaultDate: moment().format('YYYY-MM-DD HH:mm:ss'), - icons: { - time: 'far fa-clock', - date: 'far fa-calendar', - up: 'fas fa-arrow-up', - down: 'fas fa-arrow-down', - previous: 'fas fa-chevron-left', - next: 'fas fa-chevron-right', - today: 'fas fa-calendar-check', - clear: 'far fa-trash-alt', - close: 'far fa-times-circle' - }, - sideBySide: true - }); + return $('.datetimepicker').find('input'); +} + +Grocy.Components.DateTimePicker.GetValue = function() +{ + return Grocy.Components.DateTimePicker.GetInputElement().val(); +} + +Grocy.Components.DateTimePicker.SetValue = function(value) +{ + Grocy.Components.DateTimePicker.GetInputElement().val(value); + Grocy.Components.DateTimePicker.GetInputElement().trigger('change'); +} + +var startDate = null; +if (Grocy.Components.DateTimePicker.GetInputElement().data('init-with-now') === true) +{ + startDate = moment().format(Grocy.Components.DateTimePicker.GetInputElement().data('format')); +} + +var limitDate = moment('2999-12-31 23:59:59'); +if (Grocy.Components.DateTimePicker.GetInputElement().data('limit-end-to-now') === true) +{ + limitDate = moment(); +} + +$('.datetimepicker').datetimepicker( +{ + format: Grocy.Components.DateTimePicker.GetInputElement().data('format'), + buttons: { + showToday: true, + showClose: true + }, + calendarWeeks: true, + maxDate: limitDate, + locale: moment.locale(), + defaultDate: startDate, + useCurrent: false, + icons: { + time: 'far fa-clock', + date: 'far fa-calendar', + up: 'fas fa-arrow-up', + down: 'fas fa-arrow-down', + previous: 'fas fa-chevron-left', + next: 'fas fa-chevron-right', + today: 'fas fa-calendar-check', + clear: 'far fa-trash-alt', + close: 'far fa-times-circle' + }, + sideBySide: true, + keyBinds: { + up: function(widget) { }, + down: function(widget) { }, + 'control up': function(widget) { }, + 'control down': function(widget) { }, + left: function(widget) { }, + right: function(widget) { }, + pageUp: function(widget) { }, + pageDown: function(widget) { }, + enter: function(widget) { }, + escape: function(widget) { }, + 'control space': function(widget) { }, + t: function(widget) { }, + 'delete': function(widget) { } + } +}); + +Grocy.Components.DateTimePicker.GetInputElement().on('keyup', function(e) +{ + $('.datetimepicker').datetimepicker('hide'); + + var value = Grocy.Components.DateTimePicker.GetValue(); + var now = new Date(); + var centuryStart = Number.parseInt(now.getFullYear().toString().substring(0, 2) + '00'); + var centuryEnd = Number.parseInt(now.getFullYear().toString().substring(0, 2) + '99'); + var format = Grocy.Components.DateTimePicker.GetInputElement().data('format'); + var nextInputElement = $(Grocy.Components.DateTimePicker.GetInputElement().data('next-input-selector')); + + //If input is empty and any arrow key is pressed, set date to today + if (value.length === 0 && (e.keyCode === 38 || e.keyCode === 40 || e.keyCode === 37 || e.keyCode === 39)) + { + Grocy.Components.DateTimePicker.SetValue(moment(new Date(), format, true).format(format)); + nextInputElement.focus(); + } + else if (value === 'x' || value === 'X') + { + Grocy.Components.DateTimePicker.SetValue(moment('2999-12-31 23:59:59').format(format)); + nextInputElement.focus(); + } + else if (value.length === 4 && !(Number.parseInt(value) > centuryStart && Number.parseInt(value) < centuryEnd)) + { + Grocy.Components.DateTimePicker.SetValue((new Date()).getFullYear().toString() + value); + nextInputElement.focus(); + } + else if (value.length === 8 && $.isNumeric(value)) + { + Grocy.Components.DateTimePicker.SetValue(value.replace(/(\d{4})(\d{2})(\d{2})/, '$1-$2-$3')); + nextInputElement.focus(); + } + else + { + var dateObj = moment(value, format, true); + if (dateObj.isValid()) + { + if (e.keyCode === 38) //Up + { + Grocy.Components.DateTimePicker.SetValue(dateObj.add(-1, 'days').format(format)); + } + else if (e.keyCode === 40) //Down + { + Grocy.Components.DateTimePicker.SetValue(dateObj.add(1, 'days').format(format)); + } + else if (e.keyCode === 37) //Left + { + Grocy.Components.DateTimePicker.SetValue(dateObj.add(-1, 'weeks').format(format)); + } + else if (e.keyCode === 39) //Right + { + Grocy.Components.DateTimePicker.SetValue(dateObj.add(1, 'weeks').format(format)); + } + } + } + + //Custom validation + value = Grocy.Components.DateTimePicker.GetValue(); + dateObj = moment(value, format, true); + var element = Grocy.Components.DateTimePicker.GetInputElement()[0]; + if (!dateObj.isValid()) + { + element.setCustomValidity("error"); + } + else + { + if (Grocy.Components.DateTimePicker.GetInputElement().data('limit-end-to-now') === true && dateObj.isAfter(moment())) + { + element.setCustomValidity("error"); + } + else if (Grocy.Components.DateTimePicker.GetInputElement().data('limit-start-to-now') === true && dateObj.isBefore(moment())) + { + element.setCustomValidity("error"); + } + else + { + element.setCustomValidity(""); + } + } +}); + +Grocy.Components.DateTimePicker.GetInputElement().on('input', function(e) +{ + $('#datetimepicker-timeago').text($.timeago(Grocy.Components.DateTimePicker.GetValue())); + EmptyElementWhenMatches('#datetimepicker-timeago', L('timeago_nan')); +}); + +$('.datetimepicker').on('update.datetimepicker', function(e) +{ + Grocy.Components.DateTimePicker.GetInputElement().trigger('input'); }); diff --git a/public/viewjs/consume.js b/public/viewjs/consume.js index 2319343f..ac7f849d 100644 --- a/public/viewjs/consume.js +++ b/public/viewjs/consume.js @@ -96,17 +96,11 @@ $('#product_id').val(''); $('#product_id_text_input').focus(); $('#product_id_text_input').val(''); $('#product_id_text_input').trigger('change'); +Grocy.FrontendHelpers.ValidateForm('consume-form'); $('#amount').on('focus', function(e) { - if ($('#product_id_text_input').val().length === 0) - { - $('#product_id_text_input').focus(); - } - else - { - $(this).select(); - } + $(this).select(); }); $('#consume-form input').keyup(function (event) diff --git a/public/viewjs/habittracking.js b/public/viewjs/habittracking.js index 8f742c49..0ff5031d 100644 --- a/public/viewjs/habittracking.js +++ b/public/viewjs/habittracking.js @@ -7,16 +7,15 @@ Grocy.Api.Get('habits/get-habit-details/' + jsonForm.habit_id, function (habitDetails) { - Grocy.Api.Get('habits/track-habit-execution/' + jsonForm.habit_id + '?tracked_time=' + $('#tracked_time').find('input').val(), + Grocy.Api.Get('habits/track-habit-execution/' + jsonForm.habit_id + '?tracked_time=' + Grocy.Components.DateTimePicker.GetValue(), function(result) { - toastr.success(L('Tracked execution of habit #1 on #2', habitDetails.habit.name, $('#tracked_time').find('input').val())); + toastr.success(L('Tracked execution of habit #1 on #2', habitDetails.habit.name, Grocy.Components.DateTimePicker.GetValue())); $('#habit_id').val(''); $('#habit_id_text_input').focus(); $('#habit_id_text_input').val(''); - $('#tracked_time').find('input').val(moment().format('YYYY-MM-DD HH:mm:ss')); - $('#tracked_time').find('input').trigger('change'); + Grocy.Components.DateTimePicker.SetValue(moment().format('YYYY-MM-DD HH:mm:ss')); $('#habit_id_text_input').trigger('change'); Grocy.FrontendHelpers.ValidateForm('habittracking-form'); }, @@ -40,7 +39,7 @@ $('#habit_id').on('change', function(e) if (habitId) { Grocy.Components.HabitCard.Refresh(habitId); - $('#tracked_time').find('input').focus(); + Grocy.Components.DateTimePicker.GetInputElement().focus(); } }); @@ -48,9 +47,7 @@ $('.combobox').combobox({ appendId: '_text_input' }); -$('#habit_id').val(''); $('#habit_id_text_input').focus(); -$('#habit_id_text_input').val(''); $('#habit_id_text_input').trigger('change'); Grocy.FrontendHelpers.ValidateForm('habittracking-form'); @@ -75,7 +72,7 @@ $('#habittracking-form input').keydown(function(event) } }); -$('#tracked_time').find('input').on('keypress', function(e) +Grocy.Components.DateTimePicker.GetInputElement().on('keypress', function(e) { Grocy.FrontendHelpers.ValidateForm('habittracking-form'); }); diff --git a/public/viewjs/inventory.js b/public/viewjs/inventory.js index b56da31c..7c83f781 100644 --- a/public/viewjs/inventory.js +++ b/public/viewjs/inventory.js @@ -7,7 +7,7 @@ Grocy.Api.Get('stock/get-product-details/' + jsonForm.product_id, function (productDetails) { - Grocy.Api.Get('stock/inventory-product/' + jsonForm.product_id + '/' + jsonForm.new_amount + '?bestbeforedate=' + $('#best_before_date').val(), + Grocy.Api.Get('stock/inventory-product/' + jsonForm.product_id + '/' + jsonForm.new_amount + '?bestbeforedate=' + Grocy.Components.DateTimePicker.GetValue(), function(result) { var addBarcode = GetUriParam('addbarcodetoselection'); @@ -42,7 +42,7 @@ { $('#inventory-change-info').addClass('d-none'); $('#new_amount').val(''); - $('#best_before_date').val(''); + Grocy.Components.DateTimePicker.SetValue(''); $('#product_id').val(''); $('#product_id_text_input').focus(); $('#product_id_text_input').val(''); @@ -164,11 +164,11 @@ $('#product_id_text_input').on('change', function(e) }); $('#new_amount').val(''); -$('#best_before_date').val(''); $('#product_id').val(''); $('#product_id_text_input').focus(); $('#product_id_text_input').val(''); $('#product_id_text_input').trigger('change'); +Grocy.FrontendHelpers.ValidateForm('inventory-form'); $('#new_amount').on('focus', function(e) { @@ -234,55 +234,41 @@ $('#new_amount').on('keypress', function(e) $('#new_amount').trigger('change'); }); -$('#best_before_date').on('change', function(e) +Grocy.Components.DateTimePicker.GetInputElement().on('change', function(e) { Grocy.FrontendHelpers.ValidateForm('inventory-form'); }); -$('#best_before_date').on('keypress', function(e) +Grocy.Components.DateTimePicker.GetInputElement().on('keypress', function(e) { Grocy.FrontendHelpers.ValidateForm('inventory-form'); }); -$('#best_before_date').on('keydown', function(e) -{ - if (e.keyCode === 13) //Enter - { - $('#best_before_date').trigger('change'); - } -}); - $('#new_amount').on('keyup', function(e) { - if ($('#product_id').parent().hasClass('has-error')) - { - $('#inventory-change-info').addClass('d-none'); - return; - } - var productId = $('#product_id').val(); - var newAmount = $('#new_amount').val(); - + var newAmount = parseInt($('#new_amount').val()); + if (productId) { Grocy.Api.Get('stock/get-product-details/' + productId, function(productDetails) { - var productStockAmount = productDetails.stock_amount || '0'; - + var productStockAmount = parseInt(productDetails.stock_amount || '0'); + if (newAmount > productStockAmount) { var amountToAdd = newAmount - productDetails.stock_amount; $('#inventory-change-info').text(L('This means #1 will be added to stock', amountToAdd.toString() + ' ' + productDetails.quantity_unit_stock.name)); - $('#inventory-change-info').removeClass('d-none') - $('#best_before_date').attr('required', 'required'); + $('#inventory-change-info').removeClass('d-none'); + Grocy.Components.DateTimePicker.GetInputElement().attr('required', ''); } else if (newAmount < productStockAmount) { var amountToRemove = productStockAmount - newAmount; $('#inventory-change-info').text(L('This means #1 will be removed from stock', amountToRemove.toString() + ' ' + productDetails.quantity_unit_stock.name)); - $('#inventory-change-info').removeClass('d-none') - $('#best_before_date').removeAttr('required'); + $('#inventory-change-info').removeClass('d-none'); + Grocy.Components.DateTimePicker.GetInputElement().removeAttr('required'); } else { diff --git a/public/viewjs/purchase.js b/public/viewjs/purchase.js index 0949a35d..457583a2 100644 --- a/public/viewjs/purchase.js +++ b/public/viewjs/purchase.js @@ -9,7 +9,7 @@ { var amount = jsonForm.amount * productDetails.product.qu_factor_purchase_to_stock; - Grocy.Api.Get('stock/add-product/' + jsonForm.product_id + '/' + amount + '?bestbeforedate=' + $('#best_before_date').val(), + Grocy.Api.Get('stock/add-product/' + jsonForm.product_id + '/' + amount + '?bestbeforedate=' + Grocy.Components.DateTimePicker.GetValue(), function(result) { var addBarcode = GetUriParam('addbarcodetoselection'); @@ -43,7 +43,7 @@ else { $('#amount').val(0); - $('#best_before_date').val(''); + Grocy.Components.DateTimePicker.SetValue(''); $('#product_id').val(''); $('#product_id_text_input').focus(); $('#product_id_text_input').val(''); @@ -79,13 +79,12 @@ $('#product_id').on('change', function(e) if (productDetails.product.default_best_before_days.toString() !== '0') { - $('#best_before_date').val(moment().add(productDetails.product.default_best_before_days, 'days').format('YYYY-MM-DD')); - $('#best_before_date').trigger('change'); + Grocy.Components.DateTimePicker.SetValue(moment().add(productDetails.product.default_best_before_days, 'days').format('YYYY-MM-DD')); $('#amount').focus(); } else { - $('#best_before_date').focus(); + Grocy.Components.DateTimePicker.GetInputElement().focus(); } }, function(xhr) @@ -174,19 +173,11 @@ $('#product_id_text_input').on('change', function(e) }); $('#amount').val(0); -$('#best_before_date').val(''); $('#product_id').val(''); $('#product_id_text_input').focus(); $('#product_id_text_input').val(''); $('#product_id_text_input').trigger('change'); - -$('#best_before_date').on('focus', function(e) -{ - if ($('#product_id_text_input').val().length === 0) - { - $('#product_id_text_input').focus(); - } -}); +Grocy.FrontendHelpers.ValidateForm('purchase-form'); $('#amount').on('focus', function(e) { @@ -235,7 +226,7 @@ if (prefillProduct !== undefined) $('#product_id').val(possibleOptionElement.val()); $('#product_id').data('combobox').refresh(); $('#product_id').trigger('change'); - $('#best_before_date').focus(); + Grocy.Components.DateTimePicker.GetInputElement().focus(); } } @@ -247,12 +238,12 @@ if (addBarcode !== undefined) $('#barcode-lookup-disabled-hint').removeClass('d-none'); } -$('#best_before_date').on('change', function(e) +Grocy.Components.DateTimePicker.GetInputElement().on('change', function(e) { Grocy.FrontendHelpers.ValidateForm('purchase-form'); }); -$('#best_before_date').on('keypress', function(e) +Grocy.Components.DateTimePicker.GetInputElement().on('keypress', function(e) { Grocy.FrontendHelpers.ValidateForm('purchase-form'); }); diff --git a/public/viewjs/shoppinglistform.js b/public/viewjs/shoppinglistform.js index 7f2d0c2b..519122eb 100644 --- a/public/viewjs/shoppinglistform.js +++ b/public/viewjs/shoppinglistform.js @@ -42,6 +42,7 @@ $('#product_id').on('change', function(e) function (productDetails) { $('#amount_qu_unit').text(productDetails.quantity_unit_purchase.name); + $('#amount').focus(); }, function(xhr) { @@ -60,7 +61,8 @@ $('#product_id_text_input').on('change', function(e) var input = $('#product_id_text_input').val().toString(); var possibleOptionElement = $("#product_id option[data-additional-searchdata*='" + input + "']").first(); - if (possibleOptionElement.length > 0 && possibleOptionElement.text().length > 0) { + if (possibleOptionElement.length > 0 && possibleOptionElement.text().length > 0) + { $('#product_id').val(possibleOptionElement.val()); $('#product_id').data('combobox').refresh(); $('#product_id').trigger('change'); @@ -84,6 +86,10 @@ $('#amount').on('focus', function(e) { $('#product_id_text_input').focus(); } + else + { + $(this).select(); + } }); $('#shoppinglist-form input').keyup(function (event) diff --git a/version.json b/version.json index 7aaef4ef..ba88cd5b 100644 --- a/version.json +++ b/version.json @@ -1,4 +1,4 @@ { - "Version": "1.12.1", - "ReleaseDate": "2018-07-08" + "Version": "1.13.0", + "ReleaseDate": "2018-07-12" } diff --git a/views/batteriesoverview.blade.php b/views/batteriesoverview.blade.php index b2507690..3a565f86 100644 --- a/views/batteriesoverview.blade.php +++ b/views/batteriesoverview.blade.php @@ -19,7 +19,7 @@
- +
diff --git a/views/batterytracking.blade.php b/views/batterytracking.blade.php index 5c500b63..280f08cf 100644 --- a/views/batterytracking.blade.php +++ b/views/batterytracking.blade.php @@ -6,7 +6,7 @@ @section('content')
-
+

@yield('title')

@@ -24,7 +24,12 @@ @include('components.datetimepicker', array( 'id' => 'tracked_time', - 'label' => 'Tracked time' + 'label' => 'Tracked time', + 'format' => 'YYYY-MM-DD HH:mm:ss', + 'initWithNow' => true, + 'limitEndToNow' => true, + 'limitStartToNow' => false, + 'invalidFeedback' => $L('This can only be before now') )) diff --git a/views/components/datepicker.blade.php b/views/components/datepicker.blade.php deleted file mode 100644 index 839677d3..00000000 --- a/views/components/datepicker.blade.php +++ /dev/null @@ -1,14 +0,0 @@ -@push('componentScripts') - -@endpush - -
- -
- -
-
-
-
-
-
diff --git a/views/components/datetimepicker.blade.php b/views/components/datetimepicker.blade.php index c1d2d4f2..5393791a 100644 --- a/views/components/datetimepicker.blade.php +++ b/views/components/datetimepicker.blade.php @@ -3,12 +3,17 @@ @endpush
- +
- +
+
{{ $invalidFeedback }}
-
diff --git a/views/consume.blade.php b/views/consume.blade.php index 132fcb8e..d4b5d96b 100644 --- a/views/consume.blade.php +++ b/views/consume.blade.php @@ -6,7 +6,7 @@ @section('content')
-
+

@yield('title')

diff --git a/views/habitsoverview.blade.php b/views/habitsoverview.blade.php index c7baae09..a0b69535 100644 --- a/views/habitsoverview.blade.php +++ b/views/habitsoverview.blade.php @@ -19,7 +19,7 @@
- +
diff --git a/views/habittracking.blade.php b/views/habittracking.blade.php index 7c7483e7..718ecfe1 100644 --- a/views/habittracking.blade.php +++ b/views/habittracking.blade.php @@ -6,7 +6,7 @@ @section('content')
-
+

@yield('title')

@@ -24,7 +24,12 @@ @include('components.datetimepicker', array( 'id' => 'tracked_time', - 'label' => 'Tracked time' + 'label' => 'Tracked time', + 'format' => 'YYYY-MM-DD HH:mm:ss', + 'initWithNow' => true, + 'limitEndToNow' => true, + 'limitStartToNow' => false, + 'invalidFeedback' => $L('This can only be before now') )) diff --git a/views/inventory.blade.php b/views/inventory.blade.php index f4be8120..bddaabe4 100644 --- a/views/inventory.blade.php +++ b/views/inventory.blade.php @@ -6,7 +6,7 @@ @section('content')
-
+

@yield('title')

@@ -29,11 +29,17 @@
{{ $L('The amount cannot be lower than #1', '0') }}
- - @include('components.datepicker', array( + + @include('components.datetimepicker', array( 'id' => 'best_before_date', 'label' => 'Best before', - 'hint' => 'This will apply to added products' + 'hint' => 'This will apply to added products', + 'format' => 'YYYY-MM-DD', + 'initWithNow' => false, + 'limitEndToNow' => false, + 'limitStartToNow' => true, + 'invalidFeedback' => $L('A best before date is required and must be later than today'), + 'nextInputSelector' => '#best_before_date' )) diff --git a/views/layout/default.blade.php b/views/layout/default.blade.php index 3b79c5d1..a6e11db2 100644 --- a/views/layout/default.blade.php +++ b/views/layout/default.blade.php @@ -16,7 +16,6 @@ - @@ -163,7 +162,7 @@ @endif