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.
This commit is contained in:
Katharina Bogad 2021-06-18 20:55:09 +02:00
parent 71ccd22d3c
commit 3d7f0652ce
30 changed files with 158 additions and 139 deletions

View File

@ -42,6 +42,7 @@ var eslint_config = {
"clearTimeout", "clearTimeout",
"XMLHttpRequest", "XMLHttpRequest",
"btoa", "btoa",
"atob",
"Audio", "Audio",
"MutationObserver", "MutationObserver",
"URLSearchParams", "URLSearchParams",

View File

@ -32,6 +32,7 @@ class GrocyClass
this.FeatureFlags = config.FeatureFlags; this.FeatureFlags = config.FeatureFlags;
this.QuantityUnits = config.QuantityUnits; this.QuantityUnits = config.QuantityUnits;
this.QuantityUnitConversionsResolved = config.QuantityUnitConversionsResolved || []; this.QuantityUnitConversionsResolved = config.QuantityUnitConversionsResolved || [];
this.QuantityUnitEditFormRedirectUri = config.QuantityUnitEditFormRedirectUri;
this.MealPlanFirstDayOfWeek = config.MealPlanFirstDayOfWeek; this.MealPlanFirstDayOfWeek = config.MealPlanFirstDayOfWeek;
this.EditMode = config.EditMode; this.EditMode = config.EditMode;
this.EditObjectId = config.EditObjectId; this.EditObjectId = config.EditObjectId;

View File

@ -1,4 +1,6 @@
import { Calendar } from '@fullcalendar/core'; /* global fullcalendarEventSources */
import { Calendar } from '@fullcalendar/core';
import dayGridPlugin from '@fullcalendar/daygrid'; import dayGridPlugin from '@fullcalendar/daygrid';
import bootstrapPlugin from '@fullcalendar/bootstrap'; import bootstrapPlugin from '@fullcalendar/bootstrap';
import listPlugin from '@fullcalendar/list'; import listPlugin from '@fullcalendar/list';
@ -35,7 +37,7 @@ var calendarOptions = {
}, },
eventClick: function(info) eventClick: function(info)
{ {
location.href = info.link; window.location.href = info.link;
} }
}; };

View File

@ -1,9 +1,8 @@
/* global Quagga2DatamatrixReader */
import Quagga from '@ericblade/quagga2/dist/quagga'; import Quagga from '@ericblade/quagga2/dist/quagga';
Grocy.Components.BarcodeScanner = {}; Grocy.Components.BarcodeScanner = {};
//import Quagga2DatamatrixReader from '../../components_unmanaged/quagga2-reader-datamatrix/index.js'
Quagga.registerReader("datamatrix", Quagga2DatamatrixReader); Quagga.registerReader("datamatrix", Quagga2DatamatrixReader);
Grocy.Components.BarcodeScanner.LiveVideoSizeAdjusted = false; Grocy.Components.BarcodeScanner.LiveVideoSizeAdjusted = false;

View File

@ -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() === "+")) 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"); var endOfMonth = moment(value.substring(0, 4) + "-" + value.substring(4, 6) + "-01").endOf("month");
Grocy.Components.DateTimePicker.SetValue(date.format(format)); Grocy.Components.DateTimePicker.SetValue(endOfMonth.format(format));
nextInputElement.focus(); nextInputElement.focus();
} }
else else

View File

@ -35,7 +35,7 @@ Grocy.Components.DateTimePicker2.Clear = function()
// "Click" the shortcut checkbox when the desired value is // "Click" the shortcut checkbox when the desired value is
// not the shortcut value and it is currently set // not the shortcut value and it is currently set
value = ""; var value = "";
var shortcutValue = $("#datetimepicker2-shortcut").data("datetimepicker2-shortcut-value"); var shortcutValue = $("#datetimepicker2-shortcut").data("datetimepicker2-shortcut-value");
if (value != shortcutValue && $("#datetimepicker2-shortcut").is(":checked")) 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() === "+")) 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"); var endOfMonth = moment(value.substring(0, 4) + "-" + value.substring(4, 6) + "-01").endOf("month");
Grocy.Components.DateTimePicker2.SetValue(date.format(format)); Grocy.Components.DateTimePicker2.SetValue(endOfMonth.format(format));
nextInputElement.focus(); nextInputElement.focus();
} }
else else

View File

@ -40,29 +40,35 @@ $('.location-combobox').combobox({
clearIfNoMatch: true 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") if (typeof prefillByName !== "undefined")
{ {
var possibleOptionElement = $("#location_id option:contains(\"" + prefillByName + "\")").first(); var possibleOptionElement = $("#location_id option:contains(\"" + prefillByName + "\")").first();
if (possibleOptionElement.length > 0) if (possibleOptionElement.length > 0)
{ {
$('#location_id').val(possibleOptionElement.val()); locationpicker_doFocus = true;
$('#location_id').data('combobox').refresh(); this_location_picker.val(possibleOptionElement.val());
$('#location_id').trigger('change');
var nextInputElement = $(Grocy.Components.LocationPicker.GetPicker().parent().data('next-input-selector').toString());
nextInputElement.focus();
} }
} }
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") if (typeof prefillById !== "undefined")
{ {
$('#location_id').val(prefillById); locationpicker_doFocus = true;
$('#location_id').data('combobox').refresh(); this_location_picker.val(prefillById);
$('#location_id').trigger('change'); }
var nextInputElement = $(Grocy.Components.LocationPicker.GetPicker().parent().data('next-input-selector').toString()); if (locationpicker_doFocus)
nextInputElement.focus(); {
this_location_picker.data('combobox').refresh();
this_location_picker.trigger('change');
$(this_location_picker.parent().data('next-input-selector').toString())
.focus();
} }

View File

@ -88,8 +88,11 @@ $('.product-combobox').combobox({
clearIfNoMatch: false clearIfNoMatch: false
}); });
var this_product_picker = Grocy.Components.ProductPicker.GetPicker();
var productpicker_doFocus = false;
var prefillProduct = GetUriParam('product-name'); 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()) if (!prefillProduct2.isEmpty())
{ {
prefillProduct = prefillProduct2; prefillProduct = prefillProduct2;
@ -104,29 +107,30 @@ if (typeof prefillProduct !== "undefined")
if (possibleOptionElement.length > 0) if (possibleOptionElement.length > 0)
{ {
$('#product_id').val(possibleOptionElement.val()); productpicker_doFocus = true;
$('#product_id').data('combobox').refresh(); this_product_picker.val(possibleOptionElement.val());
$('#product_id').trigger('change');
var nextInputElement = $(Grocy.Components.ProductPicker.GetPicker().parent().data('next-input-selector').toString());
nextInputElement.focus();
} }
} }
var prefillProductId = GetUriParam("product"); 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()) if (!prefillProductId2.isEmpty())
{ {
prefillProductId = prefillProductId2; prefillProductId = prefillProductId2;
} }
if (typeof prefillProductId !== "undefined") if (typeof prefillProductId !== "undefined")
{ {
$('#product_id').val(prefillProductId); this_product_picker.val(prefillProductId);
$('#product_id').data('combobox').refresh(); productpicker_doFocus = true;
$('#product_id').trigger('change'); }
var nextInputElement = $(Grocy.Components.ProductPicker.GetPicker().parent().data('next-input-selector').toString()); if (productpicker_doFocus)
nextInputElement.focus(); {
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") if (GetUriParam("flow") === "InplaceAddBarcodeToExistingProduct")

View File

@ -40,29 +40,32 @@ $('.recipe-combobox').combobox({
clearIfNoMatch: true 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") if (typeof prefillByName !== "undefined")
{ {
var possibleOptionElement = $("#recipe_id option:contains(\"" + prefillByName + "\")").first(); var possibleOptionElement = $("#recipe_id option:contains(\"" + prefillByName + "\")").first();
if (possibleOptionElement.length > 0) if (possibleOptionElement.length > 0)
{ {
$('#recipe_id').val(possibleOptionElement.val()); recipe_picker_doFocus = true;
$('#recipe_id').data('combobox').refresh(); this_recipe_picker.val(possibleOptionElement.val());
$('#recipe_id').trigger('change');
var nextInputElement = $(Grocy.Components.RecipePicker.GetPicker().parent().data('next-input-selector').toString());
nextInputElement.focus();
} }
} }
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") if (typeof prefillById !== "undefined")
{ {
$('#recipe_id').val(prefillById); recipe_picker_doFocus = true;
$('#recipe_id').data('combobox').refresh(); this_recipe_picker.val(prefillById);
$('#recipe_id').trigger('change');
var nextInputElement = $(Grocy.Components.RecipePicker.GetPicker().parent().data('next-input-selector').toString());
nextInputElement.focus();
} }
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();
}

View File

@ -40,29 +40,33 @@ $('.shopping-location-combobox').combobox({
clearIfNoMatch: true 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") if (typeof prefillByName !== "undefined")
{ {
var possibleOptionElement = $("#shopping_location_id option:contains(\"" + prefillByName + "\")").first(); var possibleOptionElement = $("#shopping_location_id option:contains(\"" + prefillByName + "\")").first();
if (possibleOptionElement.length > 0) if (possibleOptionElement.length > 0)
{ {
$('#shopping_location_id').val(possibleOptionElement.val()); this_shoppinglocation_picker.val(possibleOptionElement.val());
$('#shopping_location_id').data('combobox').refresh(); shoppinglocationpicker_doFocus = true;
$('#shopping_location_id').trigger('change');
var nextInputElement = $(Grocy.Components.ShoppingLocationPicker.GetPicker().parent().data('next-input-selector').toString());
nextInputElement.focus();
} }
} }
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") if (typeof prefillById !== "undefined")
{ {
$('#shopping_location_id').val(prefillById); this_shoppinglocation_picker.val(prefillById);
$('#shopping_location_id').data('combobox').refresh(); shoppinglocationpicker_doFocus = true;
$('#shopping_location_id').trigger('change');
var nextInputElement = $(Grocy.Components.ShoppingLocationPicker.GetPicker().parent().data('next-input-selector').toString());
nextInputElement.focus();
} }
if (shoppinglocationpicker_doFocus)
{
this_shoppinglocation_picker.data('combobox').refresh();
this_shoppinglocation_picker.trigger('change');
$(this_shoppinglocation_picker.parent().data('next-input-selector').toString())
.focus();
}

View File

@ -1,3 +1,5 @@
import { RandomString } from '../../helpers/extensions';
Grocy.Components.UserfieldsForm = {}; Grocy.Components.UserfieldsForm = {};
Grocy.Components.UserfieldsForm.Save = function(success, error) Grocy.Components.UserfieldsForm.Save = function(success, error)

View File

@ -39,10 +39,14 @@ $('.user-combobox').combobox({
bsVersion: '4' 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") 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) if (possibleOptionElement.length === 0)
{ {
possibleOptionElement = $("#user_id option:contains(\"" + prefillUser + "\")").first(); possibleOptionElement = $("#user_id option:contains(\"" + prefillUser + "\")").first();
@ -50,26 +54,28 @@ if (typeof prefillUser !== "undefined")
if (possibleOptionElement.length > 0) if (possibleOptionElement.length > 0)
{ {
$('#user_id').val(possibleOptionElement.val()); user_picker_doFocus = true;
$('#user_id').data('combobox').refresh(); this_user_picker.val(possibleOptionElement.val());
$('#user_id').trigger('change');
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") if (typeof prefillUserId !== "undefined")
{ {
var possibleOptionElement = $("#user_id option[value='" + prefillUserId + "']").first(); possibleOptionElement = $("#user_id option[value='" + prefillUserId + "']").first();
if (possibleOptionElement.length > 0) if (possibleOptionElement.length > 0)
{ {
$('#user_id').val(possibleOptionElement.val()); user_picker_doFocus = true;
$('#user_id').data('combobox').refresh(); this_user_picker.val(possibleOptionElement.val());
$('#user_id').trigger('change');
var nextInputElement = $(Grocy.Components.UserPicker.GetPicker().parent().data('next-input-selector').toString());
nextInputElement.focus();
} }
} }
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();
}

View File

@ -78,13 +78,14 @@ $('#save-consume-button').on('click', function(e)
$("#use_specific_stock_entry").click(); $("#use_specific_stock_entry").click();
} }
var successMessage = null;
if (productDetails.product.enable_tare_weight_handling == 1 && !jsonData.exact_amount) 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) + '<br><a class="btn btn-secondary btn-sm mt-2" href="#" onclick="Grocy.UndoStockTransaction(\'' + bookingResponse[0].transaction_id + '\')"><i class="fas fa-undo"></i> ' + __t("Undo") + '</a>'; 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) + '<br><a class="btn btn-secondary btn-sm mt-2" href="#" onclick="Grocy.UndoStockTransaction(\'' + bookingResponse[0].transaction_id + '\')"><i class="fas fa-undo"></i> ' + __t("Undo") + '</a>';
} }
else 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) + '<br><a class="btn btn-secondary btn-sm mt-2" href="#" onclick="Grocy.UndoStockTransaction(\'' + bookingResponse[0].transaction_id + '\')"><i class="fas fa-undo"></i> ' + __t("Undo") + '</a>'; 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) + '<br><a class="btn btn-secondary btn-sm mt-2" href="#" onclick="Grocy.UndoStockTransaction(\'' + bookingResponse[0].transaction_id + '\')"><i class="fas fa-undo"></i> ' + __t("Undo") + '</a>';
} }
if (GetUriParam("embedded") !== undefined) if (GetUriParam("embedded") !== undefined)

View File

@ -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(); e.preventDefault();
@ -29,7 +32,8 @@
Grocy.EditObjectId = result.created_object_id; Grocy.EditObjectId = result.created_object_id;
Grocy.Components.UserfieldsForm.Save(function() 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, Grocy.Api.UploadFile($("#instruction-manual")[0].files[0], 'equipmentmanuals', jsonData.instruction_manual_file_name,
function(result) function(result)
@ -71,19 +75,19 @@
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response) Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response)
} }
); );
}; }
Grocy.Api.Put('objects/equipment/' + Grocy.EditObjectId, jsonData, Grocy.Api.Put('objects/equipment/' + Grocy.EditObjectId, jsonData,
function(result) function(result)
{ {
Grocy.Components.UserfieldsForm.Save(function() 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, Grocy.Api.UploadFile($("#instruction-manual")[0].files[0], 'equipmentmanuals', jsonData.instruction_manual_file_name,
function(result) function(result)
{ {
window.location.href = U('/equipment');; window.location.href = U('/equipment');
}, },
function(xhr) function(xhr)
{ {
@ -94,7 +98,7 @@
} }
else else
{ {
window.location.href = U('/equipment');; window.location.href = U('/equipment');
} }
}); });
}, },

View File

@ -1,4 +1,6 @@
var apiKeysTable = $('#apikeys-table').DataTable({ import { QrCodeImgHtml } from "../helpers/qrcode";
var apiKeysTable = $('#apikeys-table').DataTable({
'order': [[4, 'desc']], 'order': [[4, 'desc']],
'columnDefs': [ 'columnDefs': [
{ 'orderable': false, 'targets': 0 }, { 'orderable': false, 'targets': 0 },

View File

@ -298,7 +298,7 @@ var calendar = new Calendar(document.getElementById("calendar"), {
calendar.render(); calendar.render();
if (setLocale) 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; // this triggers a re-render, so we can't do that in the callback;

View File

@ -1,4 +1,5 @@
function HideTopbarPlugin() /* global SwaggerUIBundle, SwaggerUIStandalonePreset */
function HideTopbarPlugin()
{ {
return { return {
components: { components: {

View File

@ -6,7 +6,7 @@ function saveProductPicture(result, location, jsonData)
Grocy.Components.UserfieldsForm.Save(() => 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, Grocy.Api.UploadFile($("#product-picture")[0].files[0], 'productpictures', jsonData.picture_file_name,
(result) => (result) =>

View File

@ -69,7 +69,7 @@ $(document).on('click', '.product-delete-button', function(e)
{ {
if (result === true) if (result === true)
{ {
jsonData = {}; var jsonData = {};
jsonData.active = 0; jsonData.active = 0;
Grocy.Api.Delete('objects/products/' + objectId, {}, Grocy.Api.Delete('objects/products/' + objectId, {},
function(result) function(result)

View File

@ -374,7 +374,7 @@ if (Grocy.Components.ProductPicker !== undefined)
} }
} }
ScanModeSubmit(false); Grocy.ScanModeSubmit(false);
}, },
function(xhr) function(xhr)
{ {
@ -385,7 +385,7 @@ if (Grocy.Components.ProductPicker !== undefined)
else else
{ {
$("#purchase-form").removeAttr("data-used-barcode"); $("#purchase-form").removeAttr("data-used-barcode");
ScanModeSubmit(); Grocy.ScanModeSubmit();
} }
$('#display_amount').trigger("keyup"); $('#display_amount').trigger("keyup");
@ -537,8 +537,7 @@ function refreshPriceHint()
{ {
$('#price-hint').text(""); $('#price-hint').text("");
} }
}; }
$("#scan-mode").on("change", function(e) $("#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")); priceTypeUnitPriceLabel.text($("#qu_id option:selected").text() + " " + __t("price"));
refreshPriceHint(); 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();
}
}
}

View File

@ -7,14 +7,11 @@ $('.save-quantityunit-button').on('click', function(e)
var jsonData = $('#quantityunit-form').serializeJSON(); var jsonData = $('#quantityunit-form').serializeJSON();
Grocy.FrontendHelpers.BeginUiBusy("quantityunit-form"); Grocy.FrontendHelpers.BeginUiBusy("quantityunit-form");
var redirectDestination = U('/quantityunits');
if (Grocy.QuantityUnitEditFormRedirectUri !== undefined) if (Grocy.QuantityUnitEditFormRedirectUri !== undefined)
{ {
redirectDestination = Grocy.QuantityUnitEditFormRedirectUri; redirectDestination = Grocy.QuantityUnitEditFormRedirectUri;
} }
else
{
redirectDestination = U('/quantityunits');
}
if ($(e.currentTarget).attr('data-location') == "continue") if ($(e.currentTarget).attr('data-location') == "continue")
{ {

View File

@ -22,7 +22,7 @@ $("#search").on("keyup", Delay(function()
$("#clear-filter-button").on("click", function() $("#clear-filter-button").on("click", function()
{ {
$("#search").val(""); $("#search").val("");
equipmentTable.search("").draw(); quantityUnitsTable.search("").draw();
}); });
$(document).on('click', '.quantityunit-delete-button', function(e) $(document).on('click', '.quantityunit-delete-button', function(e)

View File

@ -5,7 +5,7 @@ function saveRecipePicture(result, location, jsonData)
var recipeId = Grocy.EditObjectId || result.created_object_id; var recipeId = Grocy.EditObjectId || result.created_object_id;
Grocy.Components.UserfieldsForm.Save(() => 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, Grocy.Api.UploadFile($("#recipe-picture")[0].files[0], 'recipepictures', jsonData.picture_file_name,
(result) => (result) =>

View File

@ -233,7 +233,7 @@ recipesTables.on('select', function(e, dt, type, indexes)
if (type === 'row') if (type === 'row')
{ {
var selectedRecipeId = $(recipesTables.row(indexes[0]).node()).data("recipe-id"); 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) if (selectedRecipeId.toString() !== currentRecipeId)
{ {
window.location.href = U('/recipes?recipe=' + selectedRecipeId.toString()); window.location.href = U('/recipes?recipe=' + selectedRecipeId.toString());

View File

@ -1,6 +1,4 @@
import { WindowMessageBag } from '../helpers/messagebag'; var stockEntriesTable = $('#stockentries-table').DataTable({
var stockEntriesTable = $('#stockentries-table').DataTable({
'order': [[2, 'asc']], 'order': [[2, 'asc']],
'columnDefs': [ 'columnDefs': [
{ 'orderable': false, 'targets': 0 }, { 'orderable': false, 'targets': 0 },

View File

@ -14,7 +14,7 @@ $('#save-stockentry-button').on('click', function(e)
if (!jsonForm.price.toString().isEmpty()) 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 = {}; var jsonData = {};
@ -33,7 +33,6 @@ $('#save-stockentry-button').on('click', function(e)
{ {
jsonData.location_id = 1; jsonData.location_id = 1;
} }
jsonData.price = price;
jsonData.open = $("#open").is(":checked"); jsonData.open = $("#open").is(":checked");

View File

@ -137,13 +137,14 @@ $(document).on('click', '.product-consume-button', function(e)
Grocy.Api.Get('stock/products/' + productId, Grocy.Api.Get('stock/products/' + productId,
function(result) function(result)
{ {
var toastMessage = "";
if (result.product.enable_tare_weight_handling == 1) 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) + '<br><a class="btn btn-secondary btn-sm mt-2" href="#" onclick="Grocy.UndoStockTransaction(\'' + bookingResponse[0].transaction_id + '\')"><i class="fas fa-undo"></i> ' + __t("Undo") + '</a>'; 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) + '<br><a class="btn btn-secondary btn-sm mt-2" href="#" onclick="Grocy.UndoStockTransaction(\'' + bookingResponse[0].transaction_id + '\')"><i class="fas fa-undo"></i> ' + __t("Undo") + '</a>';
} }
else 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) + '<br><a class="btn btn-secondary btn-sm mt-2" href="#" onclick="Grocy.UndoStockTransaction(\'' + bookingResponse[0].transaction_id + '\')"><i class="fas fa-undo"></i> ' + __t("Undo") + '</a>'; 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) + '<br><a class="btn btn-secondary btn-sm mt-2" href="#" onclick="Grocy.UndoStockTransaction(\'' + bookingResponse[0].transaction_id + '\')"><i class="fas fa-undo"></i> ' + __t("Undo") + '</a>';
} }
if (wasSpoiled) if (wasSpoiled)

View File

@ -111,7 +111,6 @@ $(document).on('click', '.undo-task-button', function(e)
Grocy.FrontendHelpers.BeginUiBusy(); Grocy.FrontendHelpers.BeginUiBusy();
var taskId = $(e.currentTarget).attr('data-task-id'); var taskId = $(e.currentTarget).attr('data-task-id');
var taskName = $(e.currentTarget).attr('data-task-name');
Grocy.Api.Post('tasks/' + taskId + '/undo', {}, Grocy.Api.Post('tasks/' + taskId + '/undo', {},
function() function()

View File

@ -55,16 +55,30 @@ $('#save-transfer-button').on('click', function(e)
} }
); );
} }
var amount = "";
if (productDetails.product.enable_tare_weight_handling == 1) 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()) + '<br><a class="btn btn-secondary btn-sm mt-2" href="#" onclick="Grocy.UndoStockTransaction(\'' + bookingResponse[0].transaction_id + '\')"><i class="fas fa-undo"></i> ' + __t("Undo") + '</a>'; amount = Math.abs(jsonForm.amount - parseFloat(productDetails.product.tare_weight)).toString();
} }
else 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()) + '<br><a class="btn btn-secondary btn-sm mt-2" href="#" onclick="Grocy.UndoStockTransaction(\'' + bookingResponse[0].transaction_id + '\')"><i class="fas fa-undo"></i> ' + __t("Undo") + '</a>'; 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()
) + '<br><a class="btn btn-secondary btn-sm mt-2" href="#" onclick="Grocy.UndoStockTransaction(\'' + bookingResponse[0].transaction_id + '\')"><i class="fas fa-undo"></i> ' + __t("Undo") + '</a>';
if (GetUriParam("embedded") !== undefined) if (GetUriParam("embedded") !== undefined)
{ {
window.parent.postMessage(WindowMessageBag("ProductChanged", jsonForm.product_id), Grocy.BaseUrl); window.parent.postMessage(WindowMessageBag("ProductChanged", jsonForm.product_id), Grocy.BaseUrl);

View File

@ -1,9 +1,8 @@
function SaveUserPicture(result, jsonData) function SaveUserPicture(result, jsonData)
{ {
var userId = Grocy.EditObjectId || result.created_object_id;
Grocy.Components.UserfieldsForm.Save(() => 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, Grocy.Api.UploadFile($("#user-picture")[0].files[0], 'userpictures', jsonData.picture_file_name,
(result) => (result) =>