From 3d7f0652ceae75b4906954c571f54eab3b28a80b Mon Sep 17 00:00:00 2001 From: Katharina Bogad Date: Fri, 18 Jun 2021 20:55:09 +0200 Subject: [PATCH] eslint: viewjs Fixed all reported errors, deduped some code in the picker components. However, these edits were small enough that I'm positive they work. --- gulpfile.babel.js | 1 + js/grocy.js | 1 + js/viewjs/calendar.js | 6 ++-- js/viewjs/components/barcodescanner.js | 3 +- js/viewjs/components/datetimepicker.js | 4 +-- js/viewjs/components/datetimepicker2.js | 6 ++-- js/viewjs/components/locationpicker.js | 34 ++++++++++-------- js/viewjs/components/productpicker.js | 30 +++++++++------- js/viewjs/components/recipepicker.js | 31 ++++++++-------- .../components/shoppinglocationpicker.js | 32 +++++++++-------- js/viewjs/components/userfieldsform.js | 2 ++ js/viewjs/components/userpicker.js | 36 +++++++++++-------- js/viewjs/consume.js | 5 +-- js/viewjs/equipmentform.js | 16 +++++---- js/viewjs/manageapikeys.js | 4 ++- js/viewjs/mealplan.js | 2 +- js/viewjs/openapiui.js | 3 +- js/viewjs/productform.js | 2 +- js/viewjs/products.js | 2 +- js/viewjs/purchase.js | 30 ++-------------- js/viewjs/quantityunitform.js | 5 +-- js/viewjs/quantityunits.js | 2 +- js/viewjs/recipeform.js | 2 +- js/viewjs/recipes.js | 2 +- js/viewjs/stockentries.js | 4 +-- js/viewjs/stockentryform.js | 3 +- js/viewjs/stockoverview.js | 5 +-- js/viewjs/tasks.js | 1 - js/viewjs/transfer.js | 20 +++++++++-- js/viewjs/userform.js | 3 +- 30 files changed, 158 insertions(+), 139 deletions(-) diff --git a/gulpfile.babel.js b/gulpfile.babel.js index b56497fb..309f9294 100644 --- a/gulpfile.babel.js +++ b/gulpfile.babel.js @@ -42,6 +42,7 @@ var eslint_config = { "clearTimeout", "XMLHttpRequest", "btoa", + "atob", "Audio", "MutationObserver", "URLSearchParams", diff --git a/js/grocy.js b/js/grocy.js index a12c5074..7273c81b 100644 --- a/js/grocy.js +++ b/js/grocy.js @@ -32,6 +32,7 @@ class GrocyClass this.FeatureFlags = config.FeatureFlags; this.QuantityUnits = config.QuantityUnits; this.QuantityUnitConversionsResolved = config.QuantityUnitConversionsResolved || []; + this.QuantityUnitEditFormRedirectUri = config.QuantityUnitEditFormRedirectUri; this.MealPlanFirstDayOfWeek = config.MealPlanFirstDayOfWeek; this.EditMode = config.EditMode; this.EditObjectId = config.EditObjectId; diff --git a/js/viewjs/calendar.js b/js/viewjs/calendar.js index 9c765f81..8cea570a 100644 --- a/js/viewjs/calendar.js +++ b/js/viewjs/calendar.js @@ -1,4 +1,6 @@ -import { Calendar } from '@fullcalendar/core'; +/* global fullcalendarEventSources */ + +import { Calendar } from '@fullcalendar/core'; import dayGridPlugin from '@fullcalendar/daygrid'; import bootstrapPlugin from '@fullcalendar/bootstrap'; import listPlugin from '@fullcalendar/list'; @@ -35,7 +37,7 @@ var calendarOptions = { }, eventClick: function(info) { - location.href = info.link; + window.location.href = info.link; } }; diff --git a/js/viewjs/components/barcodescanner.js b/js/viewjs/components/barcodescanner.js index 5d287c40..9477e3e7 100644 --- a/js/viewjs/components/barcodescanner.js +++ b/js/viewjs/components/barcodescanner.js @@ -1,9 +1,8 @@ +/* global Quagga2DatamatrixReader */ import Quagga from '@ericblade/quagga2/dist/quagga'; Grocy.Components.BarcodeScanner = {}; -//import Quagga2DatamatrixReader from '../../components_unmanaged/quagga2-reader-datamatrix/index.js' - Quagga.registerReader("datamatrix", Quagga2DatamatrixReader); Grocy.Components.BarcodeScanner.LiveVideoSizeAdjusted = false; diff --git a/js/viewjs/components/datetimepicker.js b/js/viewjs/components/datetimepicker.js index 7bd80eac..d6dc97a5 100644 --- a/js/viewjs/components/datetimepicker.js +++ b/js/viewjs/components/datetimepicker.js @@ -160,8 +160,8 @@ Grocy.Components.DateTimePicker.GetInputElement().on('keyup', function(e) } else if (value.length === 7 && $.isNumeric(value.substring(0, 6)) && (value.substring(6, 7).toLowerCase() === "e" || value.substring(6, 7).toLowerCase() === "+")) { - var date = moment(value.substring(0, 4) + "-" + value.substring(4, 6) + "-01").endOf("month"); - Grocy.Components.DateTimePicker.SetValue(date.format(format)); + var endOfMonth = moment(value.substring(0, 4) + "-" + value.substring(4, 6) + "-01").endOf("month"); + Grocy.Components.DateTimePicker.SetValue(endOfMonth.format(format)); nextInputElement.focus(); } else diff --git a/js/viewjs/components/datetimepicker2.js b/js/viewjs/components/datetimepicker2.js index 68d54511..5fcc4209 100644 --- a/js/viewjs/components/datetimepicker2.js +++ b/js/viewjs/components/datetimepicker2.js @@ -35,7 +35,7 @@ Grocy.Components.DateTimePicker2.Clear = function() // "Click" the shortcut checkbox when the desired value is // not the shortcut value and it is currently set - value = ""; + var value = ""; var shortcutValue = $("#datetimepicker2-shortcut").data("datetimepicker2-shortcut-value"); if (value != shortcutValue && $("#datetimepicker2-shortcut").is(":checked")) { @@ -161,8 +161,8 @@ Grocy.Components.DateTimePicker2.GetInputElement().on('keyup', function(e) } else if (value.length === 7 && $.isNumeric(value.substring(0, 6)) && (value.substring(6, 7).toLowerCase() === "e" || value.substring(6, 7).toLowerCase() === "+")) { - var date = moment(value.substring(0, 4) + "-" + value.substring(4, 6) + "-01").endOf("month"); - Grocy.Components.DateTimePicker2.SetValue(date.format(format)); + var endOfMonth = moment(value.substring(0, 4) + "-" + value.substring(4, 6) + "-01").endOf("month"); + Grocy.Components.DateTimePicker2.SetValue(endOfMonth.format(format)); nextInputElement.focus(); } else diff --git a/js/viewjs/components/locationpicker.js b/js/viewjs/components/locationpicker.js index efdb4eb4..7ed5f7fd 100644 --- a/js/viewjs/components/locationpicker.js +++ b/js/viewjs/components/locationpicker.js @@ -40,29 +40,35 @@ $('.location-combobox').combobox({ clearIfNoMatch: true }); -var prefillByName = Grocy.Components.LocationPicker.GetPicker().parent().data('prefill-by-name').toString(); +// these names seem a bit long, but as they live in global space +// and this is a component, they need to be unique. +var locationpicker_doFocus = false; +var this_location_picker = Grocy.Components.LocationPicker.GetPicker(); + +var prefillByName = this_location_picker.parent().data('prefill-by-name').toString(); if (typeof prefillByName !== "undefined") { var possibleOptionElement = $("#location_id option:contains(\"" + prefillByName + "\")").first(); if (possibleOptionElement.length > 0) { - $('#location_id').val(possibleOptionElement.val()); - $('#location_id').data('combobox').refresh(); - $('#location_id').trigger('change'); - - var nextInputElement = $(Grocy.Components.LocationPicker.GetPicker().parent().data('next-input-selector').toString()); - nextInputElement.focus(); + locationpicker_doFocus = true; + this_location_picker.val(possibleOptionElement.val()); } } -var prefillById = Grocy.Components.LocationPicker.GetPicker().parent().data('prefill-by-id').toString(); +var prefillById = this_location_picker.parent().data('prefill-by-id').toString(); if (typeof prefillById !== "undefined") { - $('#location_id').val(prefillById); - $('#location_id').data('combobox').refresh(); - $('#location_id').trigger('change'); - - var nextInputElement = $(Grocy.Components.LocationPicker.GetPicker().parent().data('next-input-selector').toString()); - nextInputElement.focus(); + locationpicker_doFocus = true; + this_location_picker.val(prefillById); +} + +if (locationpicker_doFocus) +{ + this_location_picker.data('combobox').refresh(); + this_location_picker.trigger('change'); + + $(this_location_picker.parent().data('next-input-selector').toString()) + .focus(); } diff --git a/js/viewjs/components/productpicker.js b/js/viewjs/components/productpicker.js index 6345acb5..6081e392 100644 --- a/js/viewjs/components/productpicker.js +++ b/js/viewjs/components/productpicker.js @@ -88,8 +88,11 @@ $('.product-combobox').combobox({ clearIfNoMatch: false }); +var this_product_picker = Grocy.Components.ProductPicker.GetPicker(); +var productpicker_doFocus = false; + var prefillProduct = GetUriParam('product-name'); -var prefillProduct2 = Grocy.Components.ProductPicker.GetPicker().parent().data('prefill-by-name').toString(); +var prefillProduct2 = this_product_picker.parent().data('prefill-by-name').toString(); if (!prefillProduct2.isEmpty()) { prefillProduct = prefillProduct2; @@ -104,29 +107,30 @@ if (typeof prefillProduct !== "undefined") if (possibleOptionElement.length > 0) { - $('#product_id').val(possibleOptionElement.val()); - $('#product_id').data('combobox').refresh(); - $('#product_id').trigger('change'); - - var nextInputElement = $(Grocy.Components.ProductPicker.GetPicker().parent().data('next-input-selector').toString()); - nextInputElement.focus(); + productpicker_doFocus = true; + this_product_picker.val(possibleOptionElement.val()); } } var prefillProductId = GetUriParam("product"); -var prefillProductId2 = Grocy.Components.ProductPicker.GetPicker().parent().data('prefill-by-id').toString(); +var prefillProductId2 = this_product_picker.parent().data('prefill-by-id').toString(); if (!prefillProductId2.isEmpty()) { prefillProductId = prefillProductId2; } if (typeof prefillProductId !== "undefined") { - $('#product_id').val(prefillProductId); - $('#product_id').data('combobox').refresh(); - $('#product_id').trigger('change'); + this_product_picker.val(prefillProductId); + productpicker_doFocus = true; +} - var nextInputElement = $(Grocy.Components.ProductPicker.GetPicker().parent().data('next-input-selector').toString()); - nextInputElement.focus(); +if (productpicker_doFocus) +{ + this_product_picker.data('combobox').refresh(); + this_product_picker.trigger('change'); + + $(this_product_picker.parent().data('next-input-selector').toString()) + .focus(); } if (GetUriParam("flow") === "InplaceAddBarcodeToExistingProduct") diff --git a/js/viewjs/components/recipepicker.js b/js/viewjs/components/recipepicker.js index 7cc46240..3e398eca 100644 --- a/js/viewjs/components/recipepicker.js +++ b/js/viewjs/components/recipepicker.js @@ -40,29 +40,32 @@ $('.recipe-combobox').combobox({ clearIfNoMatch: true }); -var prefillByName = Grocy.Components.RecipePicker.GetPicker().parent().data('prefill-by-name').toString(); +var this_recipe_picker = Grocy.Components.RecipePicker.GetPicker(); +var recipe_picker_doFocus = false; + +var prefillByName = this_recipe_picker.parent().data('prefill-by-name').toString(); if (typeof prefillByName !== "undefined") { var possibleOptionElement = $("#recipe_id option:contains(\"" + prefillByName + "\")").first(); if (possibleOptionElement.length > 0) { - $('#recipe_id').val(possibleOptionElement.val()); - $('#recipe_id').data('combobox').refresh(); - $('#recipe_id').trigger('change'); - - var nextInputElement = $(Grocy.Components.RecipePicker.GetPicker().parent().data('next-input-selector').toString()); - nextInputElement.focus(); + recipe_picker_doFocus = true; + this_recipe_picker.val(possibleOptionElement.val()); } } -var prefillById = Grocy.Components.RecipePicker.GetPicker().parent().data('prefill-by-id').toString(); +var prefillById = this_recipe_picker.parent().data('prefill-by-id').toString(); if (typeof prefillById !== "undefined") { - $('#recipe_id').val(prefillById); - $('#recipe_id').data('combobox').refresh(); - $('#recipe_id').trigger('change'); - - var nextInputElement = $(Grocy.Components.RecipePicker.GetPicker().parent().data('next-input-selector').toString()); - nextInputElement.focus(); + recipe_picker_doFocus = true; + this_recipe_picker.val(prefillById); } + +if (recipe_picker_doFocus) +{ + this_recipe_picker.data('combobox').refresh(); + this_recipe_picker.trigger('change'); + + $(this_recipe_picker.parent().data('next-input-selector').toString()).focus(); +} \ No newline at end of file diff --git a/js/viewjs/components/shoppinglocationpicker.js b/js/viewjs/components/shoppinglocationpicker.js index d36c75d0..7f1de6d7 100644 --- a/js/viewjs/components/shoppinglocationpicker.js +++ b/js/viewjs/components/shoppinglocationpicker.js @@ -40,29 +40,33 @@ $('.shopping-location-combobox').combobox({ clearIfNoMatch: true }); -var prefillByName = Grocy.Components.ShoppingLocationPicker.GetPicker().parent().data('prefill-by-name').toString(); +var shoppinglocationpicker_doFocus = false; +var this_shoppinglocation_picker = $('#shopping_location_id'); + +var prefillByName = this_shoppinglocation_picker.parent().data('prefill-by-name').toString(); if (typeof prefillByName !== "undefined") { var possibleOptionElement = $("#shopping_location_id option:contains(\"" + prefillByName + "\")").first(); if (possibleOptionElement.length > 0) { - $('#shopping_location_id').val(possibleOptionElement.val()); - $('#shopping_location_id').data('combobox').refresh(); - $('#shopping_location_id').trigger('change'); - - var nextInputElement = $(Grocy.Components.ShoppingLocationPicker.GetPicker().parent().data('next-input-selector').toString()); - nextInputElement.focus(); + this_shoppinglocation_picker.val(possibleOptionElement.val()); + shoppinglocationpicker_doFocus = true; } } -var prefillById = Grocy.Components.ShoppingLocationPicker.GetPicker().parent().data('prefill-by-id').toString(); +var prefillById = this_shoppinglocation_picker.parent().data('prefill-by-id').toString(); if (typeof prefillById !== "undefined") { - $('#shopping_location_id').val(prefillById); - $('#shopping_location_id').data('combobox').refresh(); - $('#shopping_location_id').trigger('change'); - - var nextInputElement = $(Grocy.Components.ShoppingLocationPicker.GetPicker().parent().data('next-input-selector').toString()); - nextInputElement.focus(); + this_shoppinglocation_picker.val(prefillById); + shoppinglocationpicker_doFocus = true; } + +if (shoppinglocationpicker_doFocus) +{ + this_shoppinglocation_picker.data('combobox').refresh(); + this_shoppinglocation_picker.trigger('change'); + + $(this_shoppinglocation_picker.parent().data('next-input-selector').toString()) + .focus(); +} \ No newline at end of file diff --git a/js/viewjs/components/userfieldsform.js b/js/viewjs/components/userfieldsform.js index ee18b690..43409bd6 100644 --- a/js/viewjs/components/userfieldsform.js +++ b/js/viewjs/components/userfieldsform.js @@ -1,3 +1,5 @@ +import { RandomString } from '../../helpers/extensions'; + Grocy.Components.UserfieldsForm = {}; Grocy.Components.UserfieldsForm.Save = function(success, error) diff --git a/js/viewjs/components/userpicker.js b/js/viewjs/components/userpicker.js index f36a83fb..abfc3a50 100644 --- a/js/viewjs/components/userpicker.js +++ b/js/viewjs/components/userpicker.js @@ -39,10 +39,14 @@ $('.user-combobox').combobox({ bsVersion: '4' }); -var prefillUser = Grocy.Components.UserPicker.GetPicker().parent().data('prefill-by-username').toString(); +var this_user_picker = Grocy.Components.UserPicker.GetPicker(); +var user_picker_doFocus = false; +var possibleOptionElement = null; + +var prefillUser = this_user_picker.parent().data('prefill-by-username').toString(); if (typeof prefillUser !== "undefined") { - var possibleOptionElement = $("#user_id option[data-additional-searchdata*=\"" + prefillUser + "\"]").first(); + possibleOptionElement = $("#user_id option[data-additional-searchdata*=\"" + prefillUser + "\"]").first(); if (possibleOptionElement.length === 0) { possibleOptionElement = $("#user_id option:contains(\"" + prefillUser + "\")").first(); @@ -50,26 +54,28 @@ if (typeof prefillUser !== "undefined") if (possibleOptionElement.length > 0) { - $('#user_id').val(possibleOptionElement.val()); - $('#user_id').data('combobox').refresh(); - $('#user_id').trigger('change'); + user_picker_doFocus = true; + this_user_picker.val(possibleOptionElement.val()); - var nextInputElement = $(Grocy.Components.UserPicker.GetPicker().parent().data('next-input-selector').toString()); - nextInputElement.focus(); } } -var prefillUserId = Grocy.Components.UserPicker.GetPicker().parent().data('prefill-by-user-id').toString(); +var prefillUserId = this_user_picker.parent().data('prefill-by-user-id').toString(); if (typeof prefillUserId !== "undefined") { - var possibleOptionElement = $("#user_id option[value='" + prefillUserId + "']").first(); + possibleOptionElement = $("#user_id option[value='" + prefillUserId + "']").first(); if (possibleOptionElement.length > 0) { - $('#user_id').val(possibleOptionElement.val()); - $('#user_id').data('combobox').refresh(); - $('#user_id').trigger('change'); - - var nextInputElement = $(Grocy.Components.UserPicker.GetPicker().parent().data('next-input-selector').toString()); - nextInputElement.focus(); + user_picker_doFocus = true; + this_user_picker.val(possibleOptionElement.val()); } } + +if (user_picker_doFocus) +{ + this_user_picker.data('combobox').refresh(); + this_user_picker.trigger('change'); + + $(this_user_picker.parent().data('next-input-selector').toString()) + .focus(); +} \ No newline at end of file diff --git a/js/viewjs/consume.js b/js/viewjs/consume.js index aa8d211d..473ce1c1 100644 --- a/js/viewjs/consume.js +++ b/js/viewjs/consume.js @@ -78,13 +78,14 @@ $('#save-consume-button').on('click', function(e) $("#use_specific_stock_entry").click(); } + var successMessage = null; if (productDetails.product.enable_tare_weight_handling == 1 && !jsonData.exact_amount) { - var successMessage = __t('Removed %1$s of %2$s from stock', Math.abs(jsonForm.amount - (parseFloat(productDetails.product.tare_weight) + parseFloat(productDetails.stock_amount))) + " " + __n(jsonForm.amount, productDetails.quantity_unit_stock.name, productDetails.quantity_unit_stock.name_plural), productDetails.product.name) + '
' + __t("Undo") + ''; + successMessage = __t('Removed %1$s of %2$s from stock', Math.abs(jsonForm.amount - (parseFloat(productDetails.product.tare_weight) + parseFloat(productDetails.stock_amount))) + " " + __n(jsonForm.amount, productDetails.quantity_unit_stock.name, productDetails.quantity_unit_stock.name_plural), productDetails.product.name) + '
' + __t("Undo") + ''; } else { - var successMessage = __t('Removed %1$s of %2$s from stock', Math.abs(jsonForm.amount) + " " + __n(jsonForm.amount, productDetails.quantity_unit_stock.name, productDetails.quantity_unit_stock.name_plural), productDetails.product.name) + '
' + __t("Undo") + ''; + successMessage = __t('Removed %1$s of %2$s from stock', Math.abs(jsonForm.amount) + " " + __n(jsonForm.amount, productDetails.quantity_unit_stock.name, productDetails.quantity_unit_stock.name_plural), productDetails.product.name) + '
' + __t("Undo") + ''; } if (GetUriParam("embedded") !== undefined) diff --git a/js/viewjs/equipmentform.js b/js/viewjs/equipmentform.js index 3cc44439..f442d666 100644 --- a/js/viewjs/equipmentform.js +++ b/js/viewjs/equipmentform.js @@ -1,4 +1,7 @@ -$('#save-equipment-button').on('click', function(e) +import { RandomString } from '../helpers/extensions'; +import { ResizeResponsiveEmbeds } from '../helpers/embeds'; + +$('#save-equipment-button').on('click', function(e) { e.preventDefault(); @@ -29,7 +32,8 @@ Grocy.EditObjectId = result.created_object_id; Grocy.Components.UserfieldsForm.Save(function() { - if (jsonData.hasOwnProperty("instruction_manual_file_name") && !Grocy.DeleteInstructionManualOnSave) + // https://eslint.org/docs/rules/no-prototype-builtins + if (Object.prototype.hasOwnProperty.call(jsonData, "instruction_manual_file_name") && !Grocy.DeleteInstructionManualOnSave) { Grocy.Api.UploadFile($("#instruction-manual")[0].files[0], 'equipmentmanuals', jsonData.instruction_manual_file_name, function(result) @@ -71,19 +75,19 @@ Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response) } ); - }; + } Grocy.Api.Put('objects/equipment/' + Grocy.EditObjectId, jsonData, function(result) { Grocy.Components.UserfieldsForm.Save(function() { - if (jsonData.hasOwnProperty("instruction_manual_file_name") && !Grocy.DeleteInstructionManualOnSave) + if (Object.prototype.hasOwnProperty.call(jsonData, "instruction_manual_file_name") && !Grocy.DeleteInstructionManualOnSave) { Grocy.Api.UploadFile($("#instruction-manual")[0].files[0], 'equipmentmanuals', jsonData.instruction_manual_file_name, function(result) { - window.location.href = U('/equipment');; + window.location.href = U('/equipment'); }, function(xhr) { @@ -94,7 +98,7 @@ } else { - window.location.href = U('/equipment');; + window.location.href = U('/equipment'); } }); }, diff --git a/js/viewjs/manageapikeys.js b/js/viewjs/manageapikeys.js index 4323f0db..c2d745f1 100644 --- a/js/viewjs/manageapikeys.js +++ b/js/viewjs/manageapikeys.js @@ -1,4 +1,6 @@ -var apiKeysTable = $('#apikeys-table').DataTable({ +import { QrCodeImgHtml } from "../helpers/qrcode"; + +var apiKeysTable = $('#apikeys-table').DataTable({ 'order': [[4, 'desc']], 'columnDefs': [ { 'orderable': false, 'targets': 0 }, diff --git a/js/viewjs/mealplan.js b/js/viewjs/mealplan.js index 35c036b4..aee7b85d 100644 --- a/js/viewjs/mealplan.js +++ b/js/viewjs/mealplan.js @@ -298,7 +298,7 @@ var calendar = new Calendar(document.getElementById("calendar"), { calendar.render(); if (setLocale) { - calendar.setLocale(__t('fullcalendar_locale')); + calendar.setOption("locale", __t('fullcalendar_locale')); } // this triggers a re-render, so we can't do that in the callback; diff --git a/js/viewjs/openapiui.js b/js/viewjs/openapiui.js index d4f77c11..07f68a4d 100644 --- a/js/viewjs/openapiui.js +++ b/js/viewjs/openapiui.js @@ -1,4 +1,5 @@ -function HideTopbarPlugin() +/* global SwaggerUIBundle, SwaggerUIStandalonePreset */ +function HideTopbarPlugin() { return { components: { diff --git a/js/viewjs/productform.js b/js/viewjs/productform.js index 0ab292c3..480416dc 100644 --- a/js/viewjs/productform.js +++ b/js/viewjs/productform.js @@ -6,7 +6,7 @@ function saveProductPicture(result, location, jsonData) Grocy.Components.UserfieldsForm.Save(() => { - if (jsonData.hasOwnProperty("picture_file_name") && !Grocy.DeleteProductPictureOnSave) + if (Object.prototype.hasOwnProperty.call(jsonData, "picture_file_name") && !Grocy.DeleteProductPictureOnSave) { Grocy.Api.UploadFile($("#product-picture")[0].files[0], 'productpictures', jsonData.picture_file_name, (result) => diff --git a/js/viewjs/products.js b/js/viewjs/products.js index 3d66e7de..dadea461 100644 --- a/js/viewjs/products.js +++ b/js/viewjs/products.js @@ -69,7 +69,7 @@ $(document).on('click', '.product-delete-button', function(e) { if (result === true) { - jsonData = {}; + var jsonData = {}; jsonData.active = 0; Grocy.Api.Delete('objects/products/' + objectId, {}, function(result) diff --git a/js/viewjs/purchase.js b/js/viewjs/purchase.js index d9f2afee..e5002052 100644 --- a/js/viewjs/purchase.js +++ b/js/viewjs/purchase.js @@ -374,7 +374,7 @@ if (Grocy.Components.ProductPicker !== undefined) } } - ScanModeSubmit(false); + Grocy.ScanModeSubmit(false); }, function(xhr) { @@ -385,7 +385,7 @@ if (Grocy.Components.ProductPicker !== undefined) else { $("#purchase-form").removeAttr("data-used-barcode"); - ScanModeSubmit(); + Grocy.ScanModeSubmit(); } $('#display_amount').trigger("keyup"); @@ -537,8 +537,7 @@ function refreshPriceHint() { $('#price-hint').text(""); } -}; - +} $("#scan-mode").on("change", function(e) { @@ -570,26 +569,3 @@ $('#qu_id').on('change', function(e) priceTypeUnitPriceLabel.text($("#qu_id option:selected").text() + " " + __t("price")); refreshPriceHint(); }); - -function ScanModeSubmit(singleUnit = true) -{ - if (BoolVal(Grocy.UserSettings.scan_mode_purchase_enabled)) - { - if (singleUnit) - { - $("#display_amount").val(1); - $(".input-group-productamountpicker").trigger("change"); - } - - Grocy.FrontendHelpers.ValidateForm("purchase-form"); - if (document.getElementById("purchase-form").checkValidity() === true) - { - $('#save-purchase-button').click(); - } - else - { - toastr.warning(__t("Scan mode is on but not all required fields could be populated automatically")); - Grocy.UISound.Error(); - } - } -} diff --git a/js/viewjs/quantityunitform.js b/js/viewjs/quantityunitform.js index b35eb163..7aee3426 100644 --- a/js/viewjs/quantityunitform.js +++ b/js/viewjs/quantityunitform.js @@ -7,14 +7,11 @@ $('.save-quantityunit-button').on('click', function(e) var jsonData = $('#quantityunit-form').serializeJSON(); Grocy.FrontendHelpers.BeginUiBusy("quantityunit-form"); + var redirectDestination = U('/quantityunits'); if (Grocy.QuantityUnitEditFormRedirectUri !== undefined) { redirectDestination = Grocy.QuantityUnitEditFormRedirectUri; } - else - { - redirectDestination = U('/quantityunits'); - } if ($(e.currentTarget).attr('data-location') == "continue") { diff --git a/js/viewjs/quantityunits.js b/js/viewjs/quantityunits.js index 504c30fe..e3be09fe 100644 --- a/js/viewjs/quantityunits.js +++ b/js/viewjs/quantityunits.js @@ -22,7 +22,7 @@ $("#search").on("keyup", Delay(function() $("#clear-filter-button").on("click", function() { $("#search").val(""); - equipmentTable.search("").draw(); + quantityUnitsTable.search("").draw(); }); $(document).on('click', '.quantityunit-delete-button', function(e) diff --git a/js/viewjs/recipeform.js b/js/viewjs/recipeform.js index 0e460ac5..bb2b40da 100644 --- a/js/viewjs/recipeform.js +++ b/js/viewjs/recipeform.js @@ -5,7 +5,7 @@ function saveRecipePicture(result, location, jsonData) var recipeId = Grocy.EditObjectId || result.created_object_id; Grocy.Components.UserfieldsForm.Save(() => { - if (jsonData.hasOwnProperty("picture_file_name") && !Grocy.DeleteRecipePictureOnSave) + if (Object.prototype.hasOwnProperty.call(jsonData, "picture_file_name") && !Grocy.DeleteRecipePictureOnSave) { Grocy.Api.UploadFile($("#recipe-picture")[0].files[0], 'recipepictures', jsonData.picture_file_name, (result) => diff --git a/js/viewjs/recipes.js b/js/viewjs/recipes.js index 1ec045c0..40abfd69 100644 --- a/js/viewjs/recipes.js +++ b/js/viewjs/recipes.js @@ -233,7 +233,7 @@ recipesTables.on('select', function(e, dt, type, indexes) if (type === 'row') { var selectedRecipeId = $(recipesTables.row(indexes[0]).node()).data("recipe-id"); - var currentRecipeId = location.search.split('recipe=')[1]; + var currentRecipeId = window.location.search.split('recipe=')[1]; if (selectedRecipeId.toString() !== currentRecipeId) { window.location.href = U('/recipes?recipe=' + selectedRecipeId.toString()); diff --git a/js/viewjs/stockentries.js b/js/viewjs/stockentries.js index ebd28582..bcc3973a 100644 --- a/js/viewjs/stockentries.js +++ b/js/viewjs/stockentries.js @@ -1,6 +1,4 @@ -import { WindowMessageBag } from '../helpers/messagebag'; - -var stockEntriesTable = $('#stockentries-table').DataTable({ +var stockEntriesTable = $('#stockentries-table').DataTable({ 'order': [[2, 'asc']], 'columnDefs': [ { 'orderable': false, 'targets': 0 }, diff --git a/js/viewjs/stockentryform.js b/js/viewjs/stockentryform.js index 07281afb..cfd1d79c 100644 --- a/js/viewjs/stockentryform.js +++ b/js/viewjs/stockentryform.js @@ -14,7 +14,7 @@ $('#save-stockentry-button').on('click', function(e) if (!jsonForm.price.toString().isEmpty()) { - price = parseFloat(jsonForm.price).toFixed(Grocy.UserSettings.stock_decimal_places_prices); + jsonData.price = parseFloat(jsonForm.price).toFixed(Grocy.UserSettings.stock_decimal_places_prices); } var jsonData = {}; @@ -33,7 +33,6 @@ $('#save-stockentry-button').on('click', function(e) { jsonData.location_id = 1; } - jsonData.price = price; jsonData.open = $("#open").is(":checked"); diff --git a/js/viewjs/stockoverview.js b/js/viewjs/stockoverview.js index 91a4f991..aec3ae52 100755 --- a/js/viewjs/stockoverview.js +++ b/js/viewjs/stockoverview.js @@ -137,13 +137,14 @@ $(document).on('click', '.product-consume-button', function(e) Grocy.Api.Get('stock/products/' + productId, function(result) { + var toastMessage = ""; if (result.product.enable_tare_weight_handling == 1) { - var toastMessage = __t('Removed %1$s of %2$s from stock', parseFloat(originalTotalStockAmount).toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_amounts }) + " " + __n(consumeAmount, result.quantity_unit_stock.name, result.quantity_unit_stock.name_plural), result.product.name) + '
' + __t("Undo") + ''; + toastMessage = __t('Removed %1$s of %2$s from stock', parseFloat(originalTotalStockAmount).toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_amounts }) + " " + __n(consumeAmount, result.quantity_unit_stock.name, result.quantity_unit_stock.name_plural), result.product.name) + '
' + __t("Undo") + ''; } else { - var toastMessage = __t('Removed %1$s of %2$s from stock', parseFloat(consumeAmount).toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_amounts }) + " " + __n(consumeAmount, result.quantity_unit_stock.name, result.quantity_unit_stock.name_plural), result.product.name) + '
' + __t("Undo") + ''; + toastMessage = __t('Removed %1$s of %2$s from stock', parseFloat(consumeAmount).toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_amounts }) + " " + __n(consumeAmount, result.quantity_unit_stock.name, result.quantity_unit_stock.name_plural), result.product.name) + '
' + __t("Undo") + ''; } if (wasSpoiled) diff --git a/js/viewjs/tasks.js b/js/viewjs/tasks.js index 662b627d..9b274ce5 100644 --- a/js/viewjs/tasks.js +++ b/js/viewjs/tasks.js @@ -111,7 +111,6 @@ $(document).on('click', '.undo-task-button', function(e) Grocy.FrontendHelpers.BeginUiBusy(); var taskId = $(e.currentTarget).attr('data-task-id'); - var taskName = $(e.currentTarget).attr('data-task-name'); Grocy.Api.Post('tasks/' + taskId + '/undo', {}, function() diff --git a/js/viewjs/transfer.js b/js/viewjs/transfer.js index ee5f6887..94743352 100644 --- a/js/viewjs/transfer.js +++ b/js/viewjs/transfer.js @@ -55,16 +55,30 @@ $('#save-transfer-button').on('click', function(e) } ); } - + var amount = ""; if (productDetails.product.enable_tare_weight_handling == 1) { - var successMessage = __t('Transfered %1$s of %2$s from %3$s to %4$s', Math.abs(jsonForm.amount - parseFloat(productDetails.product.tare_weight)) + " " + __n(jsonForm.amount, productDetails.quantity_unit_stock.name, productDetails.quantity_unit_stock.name_plural), productDetails.product.name, $('option:selected', "#location_id_from").text(), $('option:selected', "#location_id_to").text()) + '
' + __t("Undo") + ''; + amount = Math.abs(jsonForm.amount - parseFloat(productDetails.product.tare_weight)).toString(); + } else { - var successMessage = __t('Transfered %1$s of %2$s from %3$s to %4$s', Math.abs(jsonForm.amount) + " " + __n(jsonForm.amount, productDetails.quantity_unit_stock.name, productDetails.quantity_unit_stock.name_plural), productDetails.product.name, $('option:selected', "#location_id_from").text(), $('option:selected', "#location_id_to").text()) + '
' + __t("Undo") + ''; + amount = Math.abs(jsonForm.amount).toString() } + amount += " " + + __n(jsonForm.amount, + productDetails.quantity_unit_stock.name, + productDetails.quantity_unit_stock.name_plural + ); + + var successMessage = __t('Transfered %1$s of %2$s from %3$s to %4$s', + amount, + productDetails.product.name, + $('option:selected', "#location_id_from").text(), + $('option:selected', "#location_id_to").text() + ) + '
' + __t("Undo") + ''; + if (GetUriParam("embedded") !== undefined) { window.parent.postMessage(WindowMessageBag("ProductChanged", jsonForm.product_id), Grocy.BaseUrl); diff --git a/js/viewjs/userform.js b/js/viewjs/userform.js index e55ffd44..f8da5e7e 100644 --- a/js/viewjs/userform.js +++ b/js/viewjs/userform.js @@ -1,9 +1,8 @@ function SaveUserPicture(result, jsonData) { - var userId = Grocy.EditObjectId || result.created_object_id; Grocy.Components.UserfieldsForm.Save(() => { - if (jsonData.hasOwnProperty("picture_file_name") && !Grocy.DeleteUserPictureOnSave) + if (Object.prototype.hasOwnProperty.call(jsonData, "picture_file_name") && !Grocy.DeleteUserPictureOnSave) { Grocy.Api.UploadFile($("#user-picture")[0].files[0], 'userpictures', jsonData.picture_file_name, (result) =>