From 2a7fbbecf83735ce16b0318f75e55a7dec70190e Mon Sep 17 00:00:00 2001 From: Katharina Bogad Date: Thu, 24 Jun 2021 22:18:19 +0200 Subject: [PATCH] Fix bugs --- js/components/BasePicker.js | 22 +- js/components/locationpicker.js | 2 +- js/components/numberpicker.js | 19 +- js/configs/globalstate.js | 31 -- js/grocy.js | 10 +- js/lib/proxy.js | 17 +- js/viewjs/about.js | 2 +- js/viewjs/barcodescannertesting.js | 2 +- js/viewjs/batteries.js | 2 +- js/viewjs/batteriesjournal.js | 2 +- js/viewjs/batteriesoverview.js | 2 +- js/viewjs/batteriessettings.js | 2 +- js/viewjs/batteryform.js | 4 +- js/viewjs/batterytracking.js | 4 +- js/viewjs/calendar.js | 4 +- js/viewjs/choreform.js | 4 +- js/viewjs/chores.js | 2 +- js/viewjs/choresjournal.js | 2 +- js/viewjs/choresoverview.js | 2 +- js/viewjs/choressettings.js | 2 +- js/viewjs/choretracking.js | 4 +- js/viewjs/consume.js | 18 +- js/viewjs/equipment.js | 2 +- js/viewjs/equipmentform.js | 4 +- js/viewjs/inventory.js | 10 +- js/viewjs/locationcontentsheet.js | 2 +- js/viewjs/locationform.js | 4 +- js/viewjs/locations.js | 2 +- js/viewjs/login.js | 2 +- js/viewjs/manageapikeys.js | 2 +- js/viewjs/mealplan.js | 16 +- js/viewjs/productbarcodeform.js | 4 +- js/viewjs/productform.js | 8 +- js/viewjs/productgroupform.js | 4 +- js/viewjs/productgroups.js | 2 +- js/viewjs/products.js | 2 +- js/viewjs/purchase.js | 397 ++++++++++++------------ js/viewjs/quantityunitconversionform.js | 4 +- js/viewjs/quantityunitform.js | 2 +- js/viewjs/quantityunitpluraltesting.js | 2 +- js/viewjs/quantityunits.js | 2 +- js/viewjs/recipeform.js | 6 +- js/viewjs/recipeposform.js | 4 +- js/viewjs/recipes.js | 2 +- js/viewjs/recipessettings.js | 2 +- js/viewjs/shoppinglist.js | 2 +- js/viewjs/shoppinglistform.js | 4 +- js/viewjs/shoppinglistitemform.js | 4 +- js/viewjs/shoppinglistsettings.js | 2 +- js/viewjs/shoppinglocationform.js | 4 +- js/viewjs/shoppinglocations.js | 2 +- js/viewjs/stockentries.js | 2 +- js/viewjs/stockentryform.js | 4 +- js/viewjs/stockjournal.js | 2 +- js/viewjs/stockjournalsummary.js | 2 +- js/viewjs/stockoverview.js | 2 +- js/viewjs/stocksettings.js | 2 +- js/viewjs/taskcategories.js | 2 +- js/viewjs/taskcategoryform.js | 4 +- js/viewjs/taskform.js | 4 +- js/viewjs/tasks.js | 2 +- js/viewjs/taskssettings.js | 2 +- js/viewjs/transfer.js | 12 +- js/viewjs/userentities.js | 2 +- js/viewjs/userentityform.js | 4 +- js/viewjs/userfieldform.js | 4 +- js/viewjs/userfields.js | 2 +- js/viewjs/userform.js | 6 +- js/viewjs/userobjectform.js | 2 +- js/viewjs/userobjects.js | 2 +- js/viewjs/userpermissions.js | 2 +- js/viewjs/users.js | 2 +- js/viewjs/usersettings.js | 2 +- views/consume.blade.php | 6 +- views/inventory.blade.php | 6 +- views/layout/json.blade.php | 2 +- views/stockentries.blade.php | 16 +- views/transfer.blade.php | 6 +- 78 files changed, 403 insertions(+), 363 deletions(-) diff --git a/js/components/BasePicker.js b/js/components/BasePicker.js index 1a452d0a..a598f150 100644 --- a/js/components/BasePicker.js +++ b/js/components/BasePicker.js @@ -14,6 +14,7 @@ class BasePicker this.input_element = null; this.basename = basename; + this.hasCombobox = false; } prefill() @@ -55,6 +56,7 @@ class BasePicker initCombobox(selector) { + this.hasCombobox = true; this.$(selector).combobox({ appendId: '_text_input', bsVersion: '4', @@ -79,15 +81,27 @@ class BasePicker SetValue(value) { - this.input_element.val(value); - this.input_element.trigger('change'); + if (this.input_element != null) + { + this.input_element.val(value); + this.input_element.trigger('change'); + } + else + { + this.picker.val(value); + this.picker.trigger("change"); + } } SetId(value) { this.picker.val(value); - this.picker.data('combobox').refresh(); - this.input_element.trigger('change'); + if (this.hasCombobox) + this.picker.data('combobox').refresh(); + if (this.input_element != null) + this.input_element.trigger('change'); + else + this.picker.trigger("change"); } Clear() diff --git a/js/components/locationpicker.js b/js/components/locationpicker.js index 48053200..38893ffc 100644 --- a/js/components/locationpicker.js +++ b/js/components/locationpicker.js @@ -7,7 +7,7 @@ class locationpicker extends BasePicker super(Grocy, "#location_id", scopeSelector); this.picker = this.$(this.basename); - this.inputElement = this.$('#location_id_text_input'); + this.input_element = this.$(this.basename + '_text_input'); this.initCombobox('.location-combobox'); diff --git a/js/components/numberpicker.js b/js/components/numberpicker.js index d05017d5..d101d13b 100644 --- a/js/components/numberpicker.js +++ b/js/components/numberpicker.js @@ -10,8 +10,8 @@ class numberpicker this.$ = scopeSelector != null ? (selector) => jScope.find(selector) : $; var self = this; - this.$(".numberpicker-down-button").unbind('click').on("click", () => self.valueDownHandler(this)); - this.$(".numberpicker-up-button").unbind('click').on("click", () => self.valueUpHandler(this)); + this.$(".numberpicker-down-button").unbind('click').on("click", function() { self.valueDownHandler(this) }); + this.$(".numberpicker-up-button").unbind('click').on("click", function() { self.valueUpHandler(this) }); this.$(".numberpicker").on("keyup", function() { @@ -40,17 +40,28 @@ class numberpicker } }); - var observer = new MutationObserver((mutations) => self.handleObservedChange(mutations)); + this.observer = new MutationObserver((mutations) => + { + for (let mutation of mutations) + { + self.handleObservedChange(mutation) + } + }); var elements = this.$(".numberpicker"); for (let element of elements) { - observer.observe(element, { attributes: true }); + this.observer.observe(element, { attributes: true }); } this.$(".numberpicker").attr("data-initialised", "true"); // Dummy change to trigger MutationObserver above once } + Unload() + { + this.observer.disconnect(); + } + modifyValueHandler(_this, newValue) { var inputElement = this.$(_this).parent().parent().find('input[type="number"]'); diff --git a/js/configs/globalstate.js b/js/configs/globalstate.js index 6b034827..29a09e8b 100644 --- a/js/configs/globalstate.js +++ b/js/configs/globalstate.js @@ -233,37 +233,6 @@ function setInitialGlobalState(Grocy) } }) - $('.table').on('column-sizing.dt', function(e, settings) - { - var dtScrollWidth = $('.dataTables_scroll').width(); - var tableWidth = $('.table').width(); - - if (dtScrollWidth < tableWidth) - { - $('.dataTables_scrollBody').addClass("no-force-overflow-visible"); - $('.dataTables_scrollBody').removeClass("force-overflow-visible"); - } - else - { - $('.dataTables_scrollBody').removeClass("no-force-overflow-visible"); - $('.dataTables_scrollBody').addClass("force-overflow-visible"); - } - }); - $('td .dropdown').on('show.bs.dropdown', function(e) - { - if ($('.dataTables_scrollBody').hasClass("no-force-overflow-visible")) - { - $('.dataTables_scrollBody').addClass("force-overflow-visible"); - } - }); - $("td .dropdown").on('hide.bs.dropdown', function(e) - { - if ($('.dataTables_scrollBody').hasClass("no-force-overflow-visible")) - { - $('.dataTables_scrollBody').removeClass("force-overflow-visible"); - } - }) - $(window).on("message", function(e) { var data = e.originalEvent.data; diff --git a/js/grocy.js b/js/grocy.js index fe11f001..9debfddf 100644 --- a/js/grocy.js +++ b/js/grocy.js @@ -248,7 +248,7 @@ class GrocyClass if (Object.prototype.hasOwnProperty.call(components, componentName)) { // add-then-init to resolve circular dependencies - this.initComponents.push(componentName); + this.initComponents.push(componentName + scopeName); var component = new components[componentName](this, scope); this.Components[componentName + scopeName] = component; return component; @@ -377,6 +377,14 @@ class GrocyClass // this occurs before the view is shown. grocyProxy.Initialize(proxy); self.LoadView(data.viewJsName, "#" + scopeId, proxy); + }, + onHide: () => + { + grocyProxy.Unload(); + }, + onHidden: () => + { + self.FrontendHelpers.EndUiBusy(); } }); }, diff --git a/js/lib/proxy.js b/js/lib/proxy.js index 820bef69..4b6ec2a7 100644 --- a/js/lib/proxy.js +++ b/js/lib/proxy.js @@ -48,12 +48,25 @@ class GrocyProxy Initialize(proxy) { + this.proxy = proxy; this.scope = $(this.scopeSelector); var jScope = this.scope; this.$scope = (selector) => jScope.find(selector); this.FrontendHelpers = new GrocyFrontendHelpers(proxy, this.RootGrocy.Api, this.scopeSelector); } + Unload() + { + for (let component in this.Components) + { + var comp = this.Components[component]; + if (Object.prototype.hasOwnProperty.call(comp, "Unload")) + { + comp.Unload(); + } + } + } + Use(componentName, scope = null) { let scopeName = scope || this.scopeSelector; @@ -64,8 +77,8 @@ class GrocyProxy if (Object.prototype.hasOwnProperty.call(components, componentName)) { // add-then-init to resolve circular dependencies - this.initComponents.push(componentName); - var component = new components[componentName](this, scope); + this.initComponents.push(componentName + scopeName); + var component = new components[componentName](this.proxy, scope); this.Components[componentName + scopeName] = component; return component; } diff --git a/js/viewjs/about.js b/js/viewjs/about.js index ec11b0c8..180bd9ef 100644 --- a/js/viewjs/about.js +++ b/js/viewjs/about.js @@ -3,7 +3,7 @@ var $scope = $; if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } $scope('[data-toggle="collapse-next"]').on("click", function(e) diff --git a/js/viewjs/barcodescannertesting.js b/js/viewjs/barcodescannertesting.js index 10b5ef98..59329597 100644 --- a/js/viewjs/barcodescannertesting.js +++ b/js/viewjs/barcodescannertesting.js @@ -3,7 +3,7 @@ var $scope = $; if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } Grocy.Use("barcodescanner"); diff --git a/js/viewjs/batteries.js b/js/viewjs/batteries.js index 9ba4be21..e310dbef 100644 --- a/js/viewjs/batteries.js +++ b/js/viewjs/batteries.js @@ -3,7 +3,7 @@ var $scope = $; if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } // preload some views. diff --git a/js/viewjs/batteriesjournal.js b/js/viewjs/batteriesjournal.js index 0548f436..78b5c1fe 100644 --- a/js/viewjs/batteriesjournal.js +++ b/js/viewjs/batteriesjournal.js @@ -3,7 +3,7 @@ var $scope = $; if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } var batteriesJournalTable = $scope('#batteries-journal-table').DataTable({ diff --git a/js/viewjs/batteriesoverview.js b/js/viewjs/batteriesoverview.js index d7bd8b4a..388fff74 100644 --- a/js/viewjs/batteriesoverview.js +++ b/js/viewjs/batteriesoverview.js @@ -3,7 +3,7 @@ var $scope = $; if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } var batterycard = Grocy.Use("batterycard"); diff --git a/js/viewjs/batteriessettings.js b/js/viewjs/batteriessettings.js index 6c49d146..d503ec21 100644 --- a/js/viewjs/batteriessettings.js +++ b/js/viewjs/batteriessettings.js @@ -3,7 +3,7 @@ var $scope = $; if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } Grocy.Use("numberpicker"); diff --git a/js/viewjs/batteryform.js b/js/viewjs/batteryform.js index c2247291..7d229714 100644 --- a/js/viewjs/batteryform.js +++ b/js/viewjs/batteryform.js @@ -5,7 +5,7 @@ function batteryformView(Grocy, scope = null) var $scope = $; if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } Grocy.Use("numberpicker"); @@ -85,7 +85,7 @@ function batteryformView(Grocy, scope = null) { event.preventDefault(); - if (document.getElementById('battery-form').checkValidity() === false) //There is at least one validation error + if ($scope('#battery-form')[0].checkValidity() === false) //There is at least one validation error { return false; } diff --git a/js/viewjs/batterytracking.js b/js/viewjs/batterytracking.js index f7d4e245..9a1d770f 100644 --- a/js/viewjs/batterytracking.js +++ b/js/viewjs/batterytracking.js @@ -3,7 +3,7 @@ var $scope = $; if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } var batterycard = Grocy.Use("batterycard"); @@ -92,7 +92,7 @@ { event.preventDefault(); - if (document.getElementById('batterytracking-form').checkValidity() === false) //There is at least one validation error + if ($scope('#batterytracking-form')[0].checkValidity() === false) //There is at least one validation error { return false; } diff --git a/js/viewjs/calendar.js b/js/viewjs/calendar.js index 0e4c779f..49d076c8 100644 --- a/js/viewjs/calendar.js +++ b/js/viewjs/calendar.js @@ -19,7 +19,7 @@ function calendarView(Grocy, scope = null) if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); $viewport = $(scope); } @@ -63,7 +63,7 @@ function calendarView(Grocy, scope = null) firstDay = parseInt(Grocy.CalendarFirstDayOfWeek); } - var calendar = new Calendar(document.getElementById("calendar"), calendarOptions); + var calendar = new Calendar($scope("#calendar")[0], calendarOptions); calendar.render(); $scope("#ical-button").on("click", function(e) diff --git a/js/viewjs/choreform.js b/js/viewjs/choreform.js index 37b8da7f..c1e62c37 100644 --- a/js/viewjs/choreform.js +++ b/js/viewjs/choreform.js @@ -3,7 +3,7 @@ var $scope = $; if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } Grocy.Use("numberpicker"); @@ -95,7 +95,7 @@ { event.preventDefault(); - if (document.getElementById('chore-form').checkValidity() === false) //There is at least one validation error + if ($scope('#chore-form')[0].checkValidity() === false) //There is at least one validation error { return false; } diff --git a/js/viewjs/chores.js b/js/viewjs/chores.js index 15809503..e02b93b2 100644 --- a/js/viewjs/chores.js +++ b/js/viewjs/chores.js @@ -3,7 +3,7 @@ var $scope = $; if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } var choresTable = $scope('#chores-table').DataTable({ diff --git a/js/viewjs/choresjournal.js b/js/viewjs/choresjournal.js index 0e6202e8..f9a437ce 100644 --- a/js/viewjs/choresjournal.js +++ b/js/viewjs/choresjournal.js @@ -3,7 +3,7 @@ var $scope = $; if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } var choresJournalTable = $scope('#chores-journal-table').DataTable({ diff --git a/js/viewjs/choresoverview.js b/js/viewjs/choresoverview.js index 7f492a39..46a21575 100644 --- a/js/viewjs/choresoverview.js +++ b/js/viewjs/choresoverview.js @@ -5,7 +5,7 @@ if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } var chorecard = Grocy.Use("chorecard"); diff --git a/js/viewjs/choressettings.js b/js/viewjs/choressettings.js index efe6621c..39608224 100644 --- a/js/viewjs/choressettings.js +++ b/js/viewjs/choressettings.js @@ -3,7 +3,7 @@ var $scope = $; if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } Grocy.Use("numberpicker"); diff --git a/js/viewjs/choretracking.js b/js/viewjs/choretracking.js index b52143d9..3313864b 100644 --- a/js/viewjs/choretracking.js +++ b/js/viewjs/choretracking.js @@ -3,7 +3,7 @@ var $scope = $; if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } var chorecard = Grocy.Use("chorecard"); @@ -110,7 +110,7 @@ { event.preventDefault(); - if (document.getElementById('choretracking-form').checkValidity() === false) //There is at least one validation error + if ($scope('#choretracking-form')[0].checkValidity() === false) //There is at least one validation error { return false; } diff --git a/js/viewjs/consume.js b/js/viewjs/consume.js index 287e59fc..07470df9 100644 --- a/js/viewjs/consume.js +++ b/js/viewjs/consume.js @@ -8,11 +8,13 @@ function consumeView(Grocy, scope = null) if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } var productamountpicker = Grocy.Use("productamountpicker"); - var productcard = Grocy.Use("productcard"); + var productcard = null; + if (!Grocy.GetUriParam("embedded")) + productcard = Grocy.Use("productcard"); var productpicker = Grocy.Use("productpicker"); var recipepicker = Grocy.Use("recipepicker"); @@ -139,7 +141,7 @@ function consumeView(Grocy, scope = null) $scope("#location_id").find("option").remove().end().append(""); } productpicker.GetInputElement().focus(); - productcard.Refresh(jsonForm.product_id); + if (productcard != null) productcard.Refresh(jsonForm.product_id); Grocy.FrontendHelpers.ValidateForm('consume-form'); $scope("#consume-exact-amount-group").addClass("d-none"); } @@ -298,7 +300,7 @@ function consumeView(Grocy, scope = null) } ); - if (document.getElementById("product_id").getAttribute("barcode") == "null") + if ($scope('#product_id').attr("barcode") == "null") { Grocy.ScanModeSubmit(); } @@ -329,7 +331,7 @@ function consumeView(Grocy, scope = null) if (productId) { - productcard.Refresh(productId); + if (productcard != null) productcard.Refresh(productId); Grocy.Api.Get('stock/products/' + productId, function(productDetails) @@ -382,9 +384,9 @@ function consumeView(Grocy, scope = null) } }); - if (document.getElementById("product_id").getAttribute("barcode") != "null") + if ($scope('#product_id').attr("barcode") != "null") { - Grocy.Api.Get('objects/product_barcodes?query[]=barcode=' + document.getElementById("product_id").getAttribute("barcode"), + Grocy.Api.Get('objects/product_barcodes?query[]=barcode=' + $scope('#product_id').attr("barcode"), function(barcodeResult) { if (barcodeResult != null) @@ -499,7 +501,7 @@ function consumeView(Grocy, scope = null) { event.preventDefault(); - if (document.getElementById('consume-form').checkValidity() === false) //There is at least one validation error + if ($scope('#consume-form')[0].checkValidity()() === false) //There is at least one validation error { return false; } diff --git a/js/viewjs/equipment.js b/js/viewjs/equipment.js index 2651d31b..ccb8cf61 100644 --- a/js/viewjs/equipment.js +++ b/js/viewjs/equipment.js @@ -5,7 +5,7 @@ function equipmentView(Grocy, scope = null) var $scope = $; if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } var equipmentTable = $scope('#equipment-table').DataTable({ diff --git a/js/viewjs/equipmentform.js b/js/viewjs/equipmentform.js index c18791dd..f290a8ff 100644 --- a/js/viewjs/equipmentform.js +++ b/js/viewjs/equipmentform.js @@ -6,7 +6,7 @@ function equipmentformView(Grocy, scope = null) var $scope = $; if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } var userfields = Grocy.Use("userfieldsform"); @@ -132,7 +132,7 @@ function equipmentformView(Grocy, scope = null) { event.preventDefault(); - if (document.getElementById('equipment-form').checkValidity() === false) //There is at least one validation error + if ($scope('#equipment-form')[0].checkValidity()() === false) //There is at least one validation error { return false; } diff --git a/js/viewjs/inventory.js b/js/viewjs/inventory.js index 22b3934d..7803f26a 100644 --- a/js/viewjs/inventory.js +++ b/js/viewjs/inventory.js @@ -5,7 +5,7 @@ function inventoryView(Grocy, scope = null) var $scope = $; if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } var dt1 = Grocy.Use("datetimepicker"); @@ -176,7 +176,7 @@ function inventoryView(Grocy, scope = null) $scope("#tare-weight-handling-info").addClass("d-none"); } - $scope('#price').val(parseFloat(productDetails.last_price)); + $scope('#price').val(parseFloat(productDetails.last_price).toFixed(Grocy.UserSettings.stock_decimal_places_prices)); RefreshLocaleNumberInput(); if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING) { @@ -205,9 +205,9 @@ function inventoryView(Grocy, scope = null) } } - if (document.getElementById("product_id").getAttribute("barcode") != "null") + if ($scope('#product_id').attr("barcode") != "null") { - Grocy.Api.Get('objects/product_barcodes?query[]=barcode=' + document.getElementById("product_id").getAttribute("barcode"), + Grocy.Api.Get('objects/product_barcodes?query[]=barcode=' + $scope('#product_id').attr("barcode"), function(barcodeResult) { if (barcodeResult != null) @@ -295,7 +295,7 @@ function inventoryView(Grocy, scope = null) { event.preventDefault(); - if (document.getElementById('inventory-form').checkValidity() === false) //There is at least one validation error + if ($scope('#inventory-form')[0].checkValidity()() === false) //There is at least one validation error { return false; } diff --git a/js/viewjs/locationcontentsheet.js b/js/viewjs/locationcontentsheet.js index 3029fcf4..5f502bc4 100644 --- a/js/viewjs/locationcontentsheet.js +++ b/js/viewjs/locationcontentsheet.js @@ -4,7 +4,7 @@ var top = scope != null ? $(scope) : $(document); if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } top.on("click", ".print-all-locations-button", function(e) diff --git a/js/viewjs/locationform.js b/js/viewjs/locationform.js index 21fff94f..1a30fb89 100644 --- a/js/viewjs/locationform.js +++ b/js/viewjs/locationform.js @@ -5,7 +5,7 @@ function locationformView(Grocy, scope = null) var $scope = $; if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } var userfields = Grocy.Use("userfieldsform"); @@ -84,7 +84,7 @@ function locationformView(Grocy, scope = null) { event.preventDefault(); - if (document.getElementById('location-form').checkValidity() === false) //There is at least one validation error + if ($scope('#location-form')[0].checkValidity()() === false) //There is at least one validation error { return false; } diff --git a/js/viewjs/locations.js b/js/viewjs/locations.js index bd893656..bbc2d3b2 100644 --- a/js/viewjs/locations.js +++ b/js/viewjs/locations.js @@ -3,7 +3,7 @@ var $scope = $; if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } // preload some views. diff --git a/js/viewjs/login.js b/js/viewjs/login.js index e9abd8fa..f2961ac2 100644 --- a/js/viewjs/login.js +++ b/js/viewjs/login.js @@ -3,7 +3,7 @@ var $scope = $; if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } $scope('#username').focus(); diff --git a/js/viewjs/manageapikeys.js b/js/viewjs/manageapikeys.js index afc02d5f..5d72c48a 100644 --- a/js/viewjs/manageapikeys.js +++ b/js/viewjs/manageapikeys.js @@ -5,7 +5,7 @@ function manageapikeysView(Grocy, scope = null) var $scope = $; if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } var apiKeysTable = $scope('#apikeys-table').DataTable({ diff --git a/js/viewjs/mealplan.js b/js/viewjs/mealplan.js index 96c9fad5..2b904743 100644 --- a/js/viewjs/mealplan.js +++ b/js/viewjs/mealplan.js @@ -16,7 +16,7 @@ function mealplanView(Grocy, scope = null) if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } Grocy.Use("numberpicker"); @@ -45,7 +45,7 @@ function mealplanView(Grocy, scope = null) firstDay = parseInt(Grocy.MealPlanFirstDayOfWeek); } - var calendar = new Calendar(document.getElementById("calendar"), { + var calendar = new Calendar($scope('#calendar')[0], { plugins: [dayGridPlugin, bootstrapPlugin, momentPlugin], themeSystem: "bootstrap", header: { @@ -432,7 +432,7 @@ function mealplanView(Grocy, scope = null) return; } - if (document.getElementById("add-recipe-form").checkValidity() === false) //There is at least one validation error + if ($scope('#add-recipe-form')[0].checkValidity()() === false) //There is at least one validation error { return false; } @@ -474,7 +474,7 @@ function mealplanView(Grocy, scope = null) return; } - if (document.getElementById("add-note-form").checkValidity() === false) //There is at least one validation error + if ($scope('#add-note-form')[0].checkValidity()() === false) //There is at least one validation error { return false; } @@ -520,7 +520,7 @@ function mealplanView(Grocy, scope = null) return; } - if (document.getElementById("add-product-form").checkValidity() === false) //There is at least one validation error + if ($scope('#add-product-form')[0].checkValidity()() === false) //There is at least one validation error { return false; } @@ -567,7 +567,7 @@ function mealplanView(Grocy, scope = null) { event.preventDefault(); - if (document.getElementById("add-recipe-form").checkValidity() === false) //There is at least one validation error + if ($scope('#add-recipe-form')[0].checkValidity()() === false) //There is at least one validation error { return false; } @@ -584,7 +584,7 @@ function mealplanView(Grocy, scope = null) { event.preventDefault(); - if (document.getElementById("add-product-form").checkValidity() === false) //There is at least one validation error + if ($scope('#add-product-form')[0].checkValidity()() === false) //There is at least one validation error { return false; } @@ -601,7 +601,7 @@ function mealplanView(Grocy, scope = null) { event.preventDefault(); - if (document.getElementById("add-recipe-form").checkValidity() === false) //There is at least one validation error + if ($scope('#add-recipe-form')[0].checkValidity()() === false) //There is at least one validation error { return false; } diff --git a/js/viewjs/productbarcodeform.js b/js/viewjs/productbarcodeform.js index e598d84f..c3e8faf1 100644 --- a/js/viewjs/productbarcodeform.js +++ b/js/viewjs/productbarcodeform.js @@ -7,7 +7,7 @@ function productbarcodeformView(Grocy, scope = null) if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } Grocy.Use('barcodescanner'); @@ -86,7 +86,7 @@ function productbarcodeformView(Grocy, scope = null) { event.preventDefault(); - if (document.getElementById('barcode-form').checkValidity() === false) //There is at least one validation error + if ($scope('#barcode-form')[0].checkValidity()() === false) //There is at least one validation error { return false; } diff --git a/js/viewjs/productform.js b/js/viewjs/productform.js index b7e8bc8d..f75261df 100644 --- a/js/viewjs/productform.js +++ b/js/viewjs/productform.js @@ -7,7 +7,7 @@ function productformView(Grocy, scope = null) if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } Grocy.Use("numberpicker"); @@ -217,7 +217,7 @@ function productformView(Grocy, scope = null) $scope(".input-group-qu").trigger("change"); $scope("#product-form select").trigger("select"); - if (document.getElementById('product-form').checkValidity() === false) //There is at least one validation error + if ($scope('#product-form')[0].checkValidity()() === false) //There is at least one validation error { $scope("#qu-conversion-add-button").addClass("disabled"); } @@ -226,7 +226,7 @@ function productformView(Grocy, scope = null) $scope("#qu-conversion-add-button").removeClass("disabled"); } - if (document.getElementById('product-form').checkValidity() === false) //There is at least one validation error + if ($scope('#product-form')[0].checkValidity()() === false) //There is at least one validation error { $scope("#barcode-add-button").addClass("disabled"); } @@ -243,7 +243,7 @@ function productformView(Grocy, scope = null) { event.preventDefault(); - if (document.getElementById('product-form').checkValidity() === false) //There is at least one validation error + if ($scope('#product-form')[0].checkValidity()() === false) //There is at least one validation error { return false; } diff --git a/js/viewjs/productgroupform.js b/js/viewjs/productgroupform.js index 32718edc..ab1fe273 100644 --- a/js/viewjs/productgroupform.js +++ b/js/viewjs/productgroupform.js @@ -5,7 +5,7 @@ function productgroupformView(Grocy, scope = null) var $scope = $; if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } var userfields = Grocy.Use("userfieldsform"); @@ -70,7 +70,7 @@ function productgroupformView(Grocy, scope = null) { event.preventDefault(); - if (document.getElementById('product-group-form').checkValidity() === false) //There is at least one validation error + if ($scope('#product-group-form')[0].checkValidity()() === false) //There is at least one validation error { return false; } diff --git a/js/viewjs/productgroups.js b/js/viewjs/productgroups.js index 9b60d5a8..a962f051 100644 --- a/js/viewjs/productgroups.js +++ b/js/viewjs/productgroups.js @@ -3,7 +3,7 @@ var $scope = $; if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } // preload some views. diff --git a/js/viewjs/products.js b/js/viewjs/products.js index a1ba3a4c..de6c6c69 100644 --- a/js/viewjs/products.js +++ b/js/viewjs/products.js @@ -3,7 +3,7 @@ var $scope = $; if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } var productsTable = $scope('#products-table').DataTable({ diff --git a/js/viewjs/purchase.js b/js/viewjs/purchase.js index 54d24b4d..44af1bc8 100644 --- a/js/viewjs/purchase.js +++ b/js/viewjs/purchase.js @@ -6,7 +6,7 @@ function purchaseView(Grocy, scope = null) var $scope = $; if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } var datetimepicker = Grocy.Use("datetimepicker"); @@ -17,7 +17,9 @@ function purchaseView(Grocy, scope = null) var locationpicker = Grocy.Use("locationpicker"); Grocy.Use("numberpicker"); var productamountpicker = Grocy.Use("productamountpicker"); - var productcard = Grocy.Use("productcard"); + var productcard = null; + if (!Grocy.GetUriParam("embedded")) + productcard = Grocy.Use("productcard"); var shoppinglocationpicker = Grocy.Use("shoppinglocationpicker"); var productpicker = Grocy.Use("productpicker"); @@ -123,7 +125,8 @@ function purchaseView(Grocy, scope = null) $scope("#flow-info-InplaceAddBarcodeToExistingProduct").addClass("d-none"); $scope('#barcode-lookup-disabled-hint').addClass('d-none'); $scope('#barcode-lookup-hint').removeClass('d-none'); - window.history.replaceState({}, document.title, U("/purchase")); + if (!Grocy.GetUriParam("embedded")) + window.history.replaceState({}, document.title, U("/purchase")); }, function(xhr) { @@ -207,7 +210,7 @@ function purchaseView(Grocy, scope = null) shoppinglocationpicker.SetValue(''); } productpicker.GetInputElement().focus(); - productcard.Refresh(jsonForm.product_id); + if (productcard != null) productcard.Refresh(jsonForm.product_id); $scope('#price-hint').text(""); var priceTypeUnitPrice = $scope("#price-type-unit-price"); @@ -232,215 +235,217 @@ function purchaseView(Grocy, scope = null) ); }); - if (productpicker !== undefined) + productpicker.GetPicker().on('change', function(e) { - productpicker.GetPicker().on('change', function(e) + if (BoolVal(Grocy.UserSettings.scan_mode_purchase_enabled)) { - if (BoolVal(Grocy.UserSettings.scan_mode_purchase_enabled)) - { - Grocy.UISound.BarcodeScannerBeep(); - } + Grocy.UISound.BarcodeScannerBeep(); + } - var productId = $scope(e.target).val(); + var productId = $scope(e.target).val(); - if (productId) - { - productcard.Refresh(productId); + if (productId) + { + if (productcard != null) productcard.Refresh(productId); - Grocy.Api.Get('stock/products/' + productId, - function(productDetails) + Grocy.Api.Get('stock/products/' + productId, + function(productDetails) + { + CurrentProductDetails = productDetails; + + productamountpicker.Reload(productDetails.product.id, productDetails.quantity_unit_stock.id); + productamountpicker.SetQuantityUnit(productDetails.default_quantity_unit_purchase.id); + $scope('#display_amount').val(parseFloat(Grocy.UserSettings.stock_default_purchase_amount)); + $scope(".input-group-productamountpicker").trigger("change"); + + if (Grocy.GetUriParam("flow") === "shoppinglistitemtostock") { - CurrentProductDetails = productDetails; - - productamountpicker.Reload(productDetails.product.id, productDetails.quantity_unit_stock.id); - productamountpicker.SetQuantityUnit(productDetails.default_quantity_unit_purchase.id); - $scope('#display_amount').val(parseFloat(Grocy.UserSettings.stock_default_purchase_amount)); - $scope(".input-group-productamountpicker").trigger("change"); - - if (Grocy.GetUriParam("flow") === "shoppinglistitemtostock") - { - productamountpicker.SetQuantityUnit(Grocy.GetUriParam("quId")); - $scope('#display_amount').val(parseFloat(Grocy.GetUriParam("amount") * $scope("#qu_id option:selected").attr("data-qu-factor"))); - } - - $scope(".input-group-productamountpicker").trigger("change"); - - if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING) - { - if (productDetails.last_shopping_location_id != null) - { - shoppinglocationpicker.SetId(productDetails.last_shopping_location_id); - } - else - { - shoppinglocationpicker.SetId(productDetails.default_shopping_location_id); - } - } - - if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_LOCATION_TRACKING) - { - locationpicker.SetId(productDetails.location.id); - } - - if (productDetails.last_price == null || productDetails.last_price == 0) - { - $scope("#price").val("") - } - else - { - $scope('#price').val(parseFloat(productDetails.last_price / $scope("#qu_id option:selected").attr("data-qu-factor"))); - } - - var priceTypeUnitPrice = $scope("#price-type-unit-price"); - var priceTypeUnitPriceLabel = $scope("[for=" + priceTypeUnitPrice.attr("id") + "]"); - priceTypeUnitPriceLabel.text($scope("#qu_id option:selected").text() + " " + __t("price")); - - refreshPriceHint(); - - if (productDetails.product.enable_tare_weight_handling == 1) - { - var minAmount = parseFloat(productDetails.product.tare_weight) / $scope("#qu_id option:selected").attr("data-qu-factor") + parseFloat(productDetails.stock_amount); - $scope("#display_amount").attr("min", minAmount); - $scope("#tare-weight-handling-info").removeClass("d-none"); - } - else - { - $scope("#display_amount").attr("min", Grocy.DefaultMinAmount); - $scope("#tare-weight-handling-info").addClass("d-none"); - } - - if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_BEST_BEFORE_DATE_TRACKING) - { - if (productDetails.product.default_best_before_days.toString() !== '0') - { - if (productDetails.product.default_best_before_days == -1) - { - if (!$scope("#datetimepicker-shortcut").is(":checked")) - { - $scope("#datetimepicker-shortcut").click(); - } - } - else - { - datetimepicker.SetValue(moment().add(productDetails.product.default_best_before_days, 'days').format('YYYY-MM-DD')); - } - } - } - - if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_LABELPRINTER) - { - $scope("#print_stock_label").val(productDetails.product.default_print_stock_label); - if (productDetails.product.allow_label_per_unit) - { - if ($scope('#default_print_stock_label').val() == "2") - { - $scope("#default_print_stock_label").val("0"); - } - $scope('#label-option-per-unit').prop("disabled", true); - } - else - { - $scope('#label-option-per-unit').prop("disabled", false); - } - } - - $scope("#display_amount").focus(); - - Grocy.FrontendHelpers.ValidateForm('purchase-form'); - if (Grocy.GetUriParam("flow") === "shoppinglistitemtostock" && BoolVal(Grocy.UserSettings.shopping_list_to_stock_workflow_auto_submit_when_prefilled) && document.getElementById("purchase-form").checkValidity() === true) - { - $scope("#save-purchase-button").click(); - } - - RefreshLocaleNumberInput(); - var elem = document.getElementById("product_id"); - if (elem.getAttribute("barcode") != "null" && !elem.getAttribute("barcode").startsWith("grcy")) - { - Grocy.Api.Get('objects/product_barcodes?query[]=barcode=' + document.getElementById("product_id").getAttribute("barcode"), - function(barcodeResult) - { - if (barcodeResult != null) - { - var barcode = barcodeResult[0]; - $scope("#purchase-form").attr("data-used-barcode", barcode.id); - - if (barcode != null) - { - if (barcode.amount != null && !barcode.amount.isEmpty()) - { - $scope("#display_amount").val(barcode.amount); - $scope("#display_amount").select(); - } - - if (barcode.qu_id != null) - { - productamountpicker.SetQuantityUnit(barcode.qu_id); - } - - if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING && barcode.shopping_location_id != null) - { - shoppinglocationpicker.SetId(barcode.shopping_location_id); - } - - if (barcode.last_price != null && !barcode.last_price.isEmpty()) - { - $scope("#price").val(barcode.last_price); - $scope("#price-type-total-price").click(); - } - - $scope(".input-group-productamountpicker").trigger("change"); - Grocy.FrontendHelpers.ValidateForm('purchase-form'); - RefreshLocaleNumberInput(); - } - } - - Grocy.ScanModeSubmit(false); - }, - function(xhr) - { - console.error(xhr); - } - ); - } - else - { - $scope("#purchase-form").removeAttr("data-used-barcode"); - Grocy.ScanModeSubmit(); - } - - $scope('#display_amount').trigger("keyup"); - }, - function(xhr) - { - console.error(xhr); + productamountpicker.SetQuantityUnit(Grocy.GetUriParam("quId")); + $scope('#display_amount').val(parseFloat(Grocy.GetUriParam("amount") * $scope("#qu_id option:selected").attr("data-qu-factor"))); } - ); - } - }); - } + + $scope(".input-group-productamountpicker").trigger("change"); + + if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING) + { + if (productDetails.last_shopping_location_id != null) + { + shoppinglocationpicker.SetId(productDetails.last_shopping_location_id); + } + else + { + shoppinglocationpicker.SetId(productDetails.default_shopping_location_id); + } + } + + if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_LOCATION_TRACKING) + { + locationpicker.SetId(productDetails.location.id); + } + + if (productDetails.last_price == null || productDetails.last_price == 0) + { + $scope("#price").val("") + } + else + { + $scope('#price').val( + parseFloat( + productDetails.last_price / $scope("#qu_id option:selected").attr("data-qu-factor") + ).toFixed(Grocy.UserSettings.stock_decimal_places_prices)); + } + + var priceTypeUnitPrice = $scope("#price-type-unit-price"); + var priceTypeUnitPriceLabel = $scope("[for=" + priceTypeUnitPrice.attr("id") + "]"); + priceTypeUnitPriceLabel.text($scope("#qu_id option:selected").text() + " " + __t("price")); + + refreshPriceHint(); + + if (productDetails.product.enable_tare_weight_handling == 1) + { + var minAmount = parseFloat(productDetails.product.tare_weight) / $scope("#qu_id option:selected").attr("data-qu-factor") + parseFloat(productDetails.stock_amount); + $scope("#display_amount").attr("min", minAmount); + $scope("#tare-weight-handling-info").removeClass("d-none"); + } + else + { + $scope("#display_amount").attr("min", Grocy.DefaultMinAmount); + $scope("#tare-weight-handling-info").addClass("d-none"); + } + + if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_BEST_BEFORE_DATE_TRACKING) + { + if (productDetails.product.default_best_before_days.toString() !== '0') + { + if (productDetails.product.default_best_before_days == -1) + { + if (!$scope("#datetimepicker-shortcut").is(":checked")) + { + $scope("#datetimepicker-shortcut").click(); + } + } + else + { + datetimepicker.SetValue(moment().add(productDetails.product.default_best_before_days, 'days').format('YYYY-MM-DD')); + } + } + } + + if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_LABELPRINTER) + { + $scope("#print_stock_label").val(productDetails.product.default_print_stock_label); + if (productDetails.product.allow_label_per_unit) + { + if ($scope('#default_print_stock_label').val() == "2") + { + $scope("#default_print_stock_label").val("0"); + } + $scope('#label-option-per-unit').prop("disabled", true); + } + else + { + $scope('#label-option-per-unit').prop("disabled", false); + } + } + + $scope("#display_amount").focus(); + + Grocy.FrontendHelpers.ValidateForm('purchase-form'); + var elem = productpicker.GetPicker()[0]; + if (Grocy.GetUriParam("flow") === "shoppinglistitemtostock" && BoolVal(Grocy.UserSettings.shopping_list_to_stock_workflow_auto_submit_when_prefilled) && elem.checkValidity() === true) + { + $scope("#save-purchase-button").click(); + } + + RefreshLocaleNumberInput(); + + if (elem.getAttribute("barcode") != null && !elem.getAttribute("barcode").startsWith("grcy")) + { + Grocy.Api.Get('objects/product_barcodes?query[]=barcode=' + elem.getAttribute("barcode"), + function(barcodeResult) + { + if (barcodeResult != null) + { + var barcode = barcodeResult[0]; + $scope("#purchase-form").attr("data-used-barcode", barcode.id); + + if (barcode != null) + { + if (barcode.amount != null && !barcode.amount.isEmpty()) + { + $scope("#display_amount").val(barcode.amount); + $scope("#display_amount").select(); + } + + if (barcode.qu_id != null) + { + productamountpicker.SetQuantityUnit(barcode.qu_id); + } + + if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING && barcode.shopping_location_id != null) + { + shoppinglocationpicker.SetId(barcode.shopping_location_id); + } + + if (barcode.last_price != null && !barcode.last_price.isEmpty()) + { + $scope("#price").val(barcode.last_price); + $scope("#price-type-total-price").click(); + } + + $scope(".input-group-productamountpicker").trigger("change"); + Grocy.FrontendHelpers.ValidateForm('purchase-form'); + RefreshLocaleNumberInput(); + } + } + + Grocy.ScanModeSubmit(false); + }, + function(xhr) + { + console.error(xhr); + } + ); + } + else + { + $scope("#purchase-form").removeAttr("data-used-barcode"); + Grocy.ScanModeSubmit(); + } + + $scope('#display_amount').trigger("keyup"); + }, + function(xhr) + { + console.error(xhr); + } + ); + } + }); $scope('#display_amount').val(parseFloat(Grocy.UserSettings.stock_default_purchase_amount)); RefreshLocaleNumberInput(); $scope(".input-group-productamountpicker").trigger("change"); + + productpicker.GetPicker().trigger("change"); + Grocy.FrontendHelpers.ValidateForm('purchase-form'); - if (productpicker) + if (productpicker.InAnyFlow() === false && Grocy.GetUriParam("embedded") === undefined) { - if (productpicker.InAnyFlow() === false && Grocy.GetUriParam("embedded") === undefined) + productpicker.GetInputElement().focus(); + } + else + { + productpicker.GetPicker().trigger('change'); + + if (productpicker.InProductModifyWorkflow()) { productpicker.GetInputElement().focus(); } - else - { - productpicker.GetPicker().trigger('change'); - - if (productpicker.InProductModifyWorkflow()) - { - productpicker.GetInputElement().focus(); - } - } } + $scope('#display_amount').on('focus', function(e) { if (productpicker.GetValue().length === 0) @@ -469,7 +474,7 @@ function purchaseView(Grocy, scope = null) { event.preventDefault(); - if (document.getElementById('purchase-form').checkValidity() === false) //There is at least one validation error + if ($scope('purchase-form')[0].checkValidity() === false) //There is at least one validation error { return false; } @@ -569,7 +574,7 @@ function purchaseView(Grocy, scope = null) $scope("#scan-mode-button").on("click", function(e) { - document.activeElement.blur(); + $(this).trigger('blur'); $scope("#scan-mode").click(); $scope("#scan-mode-button").toggleClass("btn-success").toggleClass("btn-danger"); if ($scope("#scan-mode").prop("checked")) diff --git a/js/viewjs/quantityunitconversionform.js b/js/viewjs/quantityunitconversionform.js index db895586..4f395118 100644 --- a/js/viewjs/quantityunitconversionform.js +++ b/js/viewjs/quantityunitconversionform.js @@ -5,7 +5,7 @@ function quantityunitconversionformView(Grocy, scope = null) var $scope = $; if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } Grocy.Use("numberpicker"); @@ -149,7 +149,7 @@ function quantityunitconversionformView(Grocy, scope = null) { event.preventDefault(); - if (document.getElementById('quconversion-form').checkValidity() === false) //There is at least one validation error + if ($scope('#quconversion-form')[0].checkValidity()() === false) //There is at least one validation error { return false; } diff --git a/js/viewjs/quantityunitform.js b/js/viewjs/quantityunitform.js index 840c3025..82dc6b5d 100644 --- a/js/viewjs/quantityunitform.js +++ b/js/viewjs/quantityunitform.js @@ -5,7 +5,7 @@ function quantityunitformView(Grocy, scope = null) var $scope = $; if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } var userfields = Grocy.Use("userfieldsform"); diff --git a/js/viewjs/quantityunitpluraltesting.js b/js/viewjs/quantityunitpluraltesting.js index 0fea8ab1..be6a47b2 100644 --- a/js/viewjs/quantityunitpluraltesting.js +++ b/js/viewjs/quantityunitpluraltesting.js @@ -3,7 +3,7 @@ var $scope = $; if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } Grocy.Use("numberpicker"); diff --git a/js/viewjs/quantityunits.js b/js/viewjs/quantityunits.js index 4774e607..06ec2065 100644 --- a/js/viewjs/quantityunits.js +++ b/js/viewjs/quantityunits.js @@ -3,7 +3,7 @@ var $scope = $; if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } var quantityUnitsTable = $scope('#quantityunits-table').DataTable({ diff --git a/js/viewjs/recipeform.js b/js/viewjs/recipeform.js index eff9ac1b..3c0f8b97 100644 --- a/js/viewjs/recipeform.js +++ b/js/viewjs/recipeform.js @@ -6,7 +6,7 @@ function recipeformView(Grocy, scope = null) var top = scope != null ? $(scope) : $(document); if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } Grocy.Use("numberpicker"); @@ -128,7 +128,7 @@ function recipeformView(Grocy, scope = null) { event.preventDefault(); - if (document.getElementById('recipe-form').checkValidity() === false) //There is at least one validation error + if ($scope('#recipe-form')[0].checkValidity()() === false) //There is at least one validation error { return false; } @@ -264,7 +264,7 @@ function recipeformView(Grocy, scope = null) return; } - if (document.getElementById("recipe-include-form").checkValidity() === false) //There is at least one validation error + if ($scope('#recipe-include-form')[0].checkValidity()() === false) //There is at least one validation error { return false; } diff --git a/js/viewjs/recipeposform.js b/js/viewjs/recipeposform.js index 91d05fcc..adea7665 100644 --- a/js/viewjs/recipeposform.js +++ b/js/viewjs/recipeposform.js @@ -5,7 +5,7 @@ function recipeposformView(Grocy, scope = null) var $scope = $; if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } Grocy.Use("numberpicker"); @@ -145,7 +145,7 @@ function recipeposformView(Grocy, scope = null) { event.preventDefault(); - if (document.getElementById('recipe-pos-form').checkValidity() === false) //There is at least one validation error + if ($scope('#recipe-pos-form')[0].checkValidity()() === false) //There is at least one validation error { return false; } diff --git a/js/viewjs/recipes.js b/js/viewjs/recipes.js index 8ed2517f..f7c81386 100644 --- a/js/viewjs/recipes.js +++ b/js/viewjs/recipes.js @@ -5,7 +5,7 @@ var top = scope != null ? $(scope) : $(document) if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } Grocy.Use("numberpicker"); diff --git a/js/viewjs/recipessettings.js b/js/viewjs/recipessettings.js index 226b3127..e3315882 100644 --- a/js/viewjs/recipessettings.js +++ b/js/viewjs/recipessettings.js @@ -5,7 +5,7 @@ function recipessettingsView(Grocy, scope = null) var $scope = $; if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } if (BoolVal(Grocy.UserSettings.recipe_ingredients_group_by_product_group)) diff --git a/js/viewjs/shoppinglist.js b/js/viewjs/shoppinglist.js index 5596c004..aa99d4d8 100644 --- a/js/viewjs/shoppinglist.js +++ b/js/viewjs/shoppinglist.js @@ -12,7 +12,7 @@ function shoppinglistView(Grocy, scope = null) if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } // preload some views. diff --git a/js/viewjs/shoppinglistform.js b/js/viewjs/shoppinglistform.js index c95d22f2..43e9594d 100644 --- a/js/viewjs/shoppinglistform.js +++ b/js/viewjs/shoppinglistform.js @@ -5,7 +5,7 @@ function shoppinglistformView(Grocy, scope = null) var $scope = $; if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } var userfields = Grocy.Use("userfieldsform"); @@ -74,7 +74,7 @@ function shoppinglistformView(Grocy, scope = null) { event.preventDefault(); - if (document.getElementById('shopping-list-form').checkValidity() === false) //There is at least one validation error + if ($scope('#shopping-list-form')[0].checkValidity()() === false) //There is at least one validation error { return false; } diff --git a/js/viewjs/shoppinglistitemform.js b/js/viewjs/shoppinglistitemform.js index cc4638ee..8279e53a 100644 --- a/js/viewjs/shoppinglistitemform.js +++ b/js/viewjs/shoppinglistitemform.js @@ -5,7 +5,7 @@ function shoppinglistitemformView(Grocy, scope = null) var $scope = $; if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } var productamountpicker = Grocy.Use("productamountpicker"); @@ -226,7 +226,7 @@ function shoppinglistitemformView(Grocy, scope = null) { event.preventDefault(); - if (document.getElementById('shoppinglist-form').checkValidity() === false) //There is at least one validation error + if ($scope('#shoppinglist-form')[0].checkValidity()() === false) //There is at least one validation error { return false; } diff --git a/js/viewjs/shoppinglistsettings.js b/js/viewjs/shoppinglistsettings.js index ef6e9d19..70038156 100644 --- a/js/viewjs/shoppinglistsettings.js +++ b/js/viewjs/shoppinglistsettings.js @@ -5,7 +5,7 @@ function shoppinglistsettingsView(Grocy, scope = null) var $scope = $; if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } if (BoolVal(Grocy.UserSettings.shopping_list_to_stock_workflow_auto_submit_when_prefilled)) diff --git a/js/viewjs/shoppinglocationform.js b/js/viewjs/shoppinglocationform.js index 89a3fa9d..0f45da07 100644 --- a/js/viewjs/shoppinglocationform.js +++ b/js/viewjs/shoppinglocationform.js @@ -5,7 +5,7 @@ function shoppinglocationformView(Grocy, scope = null) var $scope = $; if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } var userfields = Grocy.Use("userfieldsform"); @@ -84,7 +84,7 @@ function shoppinglocationformView(Grocy, scope = null) { event.preventDefault(); - if (document.getElementById('shoppinglocation-form').checkValidity() === false) //There is at least one validation error + if ($scope('#shoppinglocation-form')[0].checkValidity()() === false) //There is at least one validation error { return false; } diff --git a/js/viewjs/shoppinglocations.js b/js/viewjs/shoppinglocations.js index d165b08b..40af5274 100644 --- a/js/viewjs/shoppinglocations.js +++ b/js/viewjs/shoppinglocations.js @@ -3,7 +3,7 @@ var $scope = $; if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } // preload some views. diff --git a/js/viewjs/stockentries.js b/js/viewjs/stockentries.js index d42054bc..fd2b8f60 100644 --- a/js/viewjs/stockentries.js +++ b/js/viewjs/stockentries.js @@ -5,7 +5,7 @@ if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } var productcard = Grocy.Use("productcard"); diff --git a/js/viewjs/stockentryform.js b/js/viewjs/stockentryform.js index 5e654742..fa23743d 100644 --- a/js/viewjs/stockentryform.js +++ b/js/viewjs/stockentryform.js @@ -5,7 +5,7 @@ function stockentryformView(Grocy, scope = null) var $scope = $; if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } var datetimepicker = Grocy.Use("datetimepicker"); @@ -81,7 +81,7 @@ function stockentryformView(Grocy, scope = null) { event.preventDefault(); - if (document.getElementById('stockentry-form').checkValidity() === false) //There is at least one validation error + if ($scope('#stockentry-form')[0].checkValidity()() === false) //There is at least one validation error { return false; } diff --git a/js/viewjs/stockjournal.js b/js/viewjs/stockjournal.js index c08b3a30..3193ba1f 100644 --- a/js/viewjs/stockjournal.js +++ b/js/viewjs/stockjournal.js @@ -4,7 +4,7 @@ var top = scope != null ? $(scope) : $(document); if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } var stockJournalTable = $scope('#stock-journal-table').DataTable({ diff --git a/js/viewjs/stockjournalsummary.js b/js/viewjs/stockjournalsummary.js index 2626ea3f..cda75d4e 100644 --- a/js/viewjs/stockjournalsummary.js +++ b/js/viewjs/stockjournalsummary.js @@ -3,7 +3,7 @@ var $scope = $; if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } var journalSummaryTable = $scope('#stock-journal-summary-table').DataTable({ diff --git a/js/viewjs/stockoverview.js b/js/viewjs/stockoverview.js index 42f00b9f..c88157cc 100755 --- a/js/viewjs/stockoverview.js +++ b/js/viewjs/stockoverview.js @@ -4,7 +4,7 @@ var top = scope != null ? $(scope) : $(document); if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } var productcard = Grocy.Use("productcard"); diff --git a/js/viewjs/stocksettings.js b/js/viewjs/stocksettings.js index fee1ee00..978fd15a 100644 --- a/js/viewjs/stocksettings.js +++ b/js/viewjs/stocksettings.js @@ -5,7 +5,7 @@ function stocksettingsView(Grocy, scope = null) var $scope = $; if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } diff --git a/js/viewjs/taskcategories.js b/js/viewjs/taskcategories.js index e0fc8aef..13251e83 100644 --- a/js/viewjs/taskcategories.js +++ b/js/viewjs/taskcategories.js @@ -3,7 +3,7 @@ var $scope = $; if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } // preload some views. diff --git a/js/viewjs/taskcategoryform.js b/js/viewjs/taskcategoryform.js index 45739bf1..f93744d7 100644 --- a/js/viewjs/taskcategoryform.js +++ b/js/viewjs/taskcategoryform.js @@ -5,7 +5,7 @@ function taskcategoryformView(Grocy, scope = null) var $scope = $; if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } var userfields = Grocy.Use("userfieldsform"); @@ -84,7 +84,7 @@ function taskcategoryformView(Grocy, scope = null) { event.preventDefault(); - if (document.getElementById('task-category-form').checkValidity() === false) //There is at least one validation error + if ($scope('#task-category-form')[0].checkValidity()() === false) //There is at least one validation error { return false; } diff --git a/js/viewjs/taskform.js b/js/viewjs/taskform.js index 07d0a41a..157f0cf6 100644 --- a/js/viewjs/taskform.js +++ b/js/viewjs/taskform.js @@ -5,7 +5,7 @@ function taskformView(Grocy, scope = null) var $scope = $; if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } var datetimepicker = Grocy.Use("datetimepicker"); @@ -89,7 +89,7 @@ function taskformView(Grocy, scope = null) { event.preventDefault(); - if (document.getElementById('task-form').checkValidity() === false) //There is at least one validation error + if ($scope('#task-form')[0].checkValidity()() === false) //There is at least one validation error { return false; } diff --git a/js/viewjs/tasks.js b/js/viewjs/tasks.js index 52c1674b..4a9aceba 100644 --- a/js/viewjs/tasks.js +++ b/js/viewjs/tasks.js @@ -5,7 +5,7 @@ if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } // preload some views. diff --git a/js/viewjs/taskssettings.js b/js/viewjs/taskssettings.js index e7fb65e9..107f4e13 100644 --- a/js/viewjs/taskssettings.js +++ b/js/viewjs/taskssettings.js @@ -3,7 +3,7 @@ var $scope = $; if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } Grocy.Use("numberpicker"); diff --git a/js/viewjs/transfer.js b/js/viewjs/transfer.js index 4c1ba3f2..c443d7df 100644 --- a/js/viewjs/transfer.js +++ b/js/viewjs/transfer.js @@ -5,7 +5,7 @@ function transferView(Grocy, scope = null) var $scope = $; if (scope != null) { - $scope = (scope) => $(scope).find(scope); + $scope = (selector) => $(scope).find(selector); } var productpicker = Grocy.Use("productpicker"); @@ -192,7 +192,7 @@ function transferView(Grocy, scope = null) { if (productDetails.location.id == stockLocation.location_id) { - $scope("#location_id_from").append($scope("