' + resolvedRecipe.calories + ' kcal ' + __t('per serving') + '';
}
-
+
if (!Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK)
{
fulfillmentIconHtml = "";
fulfillmentInfoHtml = "";
}
-
+
element.html('\
\
' + recipe.name + ' \
@@ -208,7 +211,7 @@
\
\
');
-
+
if (recipe.picture_file_name && !recipe.picture_file_name.isEmpty())
{
element.html(element.html() + '![]()
')
@@ -221,26 +224,26 @@
{
return false;
}
-
+
if (productDetails.last_price === null)
{
productDetails.last_price = 0;
}
-
+
element.attr("data-product-details", event.productDetails);
-
+
var productOrderMissingButtonDisabledClasses = "disabled";
if (parseFloat(productDetails.stock_amount_aggregated) < parseFloat(mealPlanEntry.product_amount))
{
productOrderMissingButtonDisabledClasses = "";
}
-
+
var productConsumeButtonDisabledClasses = "disabled";
if (parseFloat(productDetails.stock_amount_aggregated) >= parseFloat(mealPlanEntry.product_amount))
{
productConsumeButtonDisabledClasses = "";
}
-
+
fulfillmentInfoHtml = __t('Not enough in stock');
fulfillmentIconHtml = '';
if (parseFloat(productDetails.stock_amount_aggregated) >= parseFloat(mealPlanEntry.product_amount))
@@ -248,7 +251,7 @@
fulfillmentInfoHtml = __t('Enough in stock');
fulfillmentIconHtml = '';
}
-
+
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING)
{
costsAndCaloriesPerServing = '' + productDetails.last_price * mealPlanEntry.product_amount + ' / ' + productDetails.product.calories * mealPlanEntry.product_amount + ' kcal ' + '';
@@ -257,7 +260,7 @@
{
costsAndCaloriesPerServing = '' + productDetails.product.calories * mealPlanEntry.product_amount + ' kcal ' + '';
}
-
+
element.html('\
\
' + productDetails.product.name + ' \
@@ -271,7 +274,7 @@
\
\
');
-
+
if (productDetails.product.picture_file_name && !productDetails.product.picture_file_name.isEmpty())
{
element.html(element.html() + '')
@@ -298,7 +301,7 @@
RefreshLocaleNumberDisplay();
LoadImagesLazy();
elem.find('[data-toggle="tooltip"]').tooltip();
-
+
if (!Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK)
{
elem.find(".recipe-order-missing-button").addClass("d-none");
@@ -312,103 +315,103 @@
{
calendar.setOption("locale", __t('fullcalendar_locale'));
}
-
+
// this triggers a re-render, so we can't do that in the callback;
// but it works here no problem.
if (GetUriParam("week") !== undefined)
{
calendar.gotoDate(GetUriParam("week"));
}
-
- $(document).on("click", ".add-recipe-button", function(e)
+
+ top.on("click", ".add-recipe-button", function(e)
{
var day = $(this).parent().parent().data("date");
-
- $("#add-recipe-modal-title").text(__t("Add recipe on %s", day.toString()));
- $("#day").val(day.toString());
+
+ $scope("#add-recipe-modal-title").text(__t("Add recipe on %s", day.toString()));
+ $scope("#day").val(day.toString());
Grocy.Components.RecipePicker.Clear();
- $("#add-recipe-modal").modal("show");
+ $scope("#add-recipe-modal").modal("show");
Grocy.FrontendHelpers.ValidateForm("add-recipe-form");
Grocy.IsMealPlanEntryEditAction = false;
});
-
- $(document).on("click", ".add-note-button", function(e)
+
+ top.on("click", ".add-note-button", function(e)
{
var day = $(this).parent().parent().parent().data("date");
-
- $("#add-note-modal-title").text(__t("Add note on %s", day.toString()));
- $("#day").val(day.toString());
- $("#note").val("");
- $("#add-note-modal").modal("show");
+
+ $scope("#add-note-modal-title").text(__t("Add note on %s", day.toString()));
+ $scope("#day").val(day.toString());
+ $scope("#note").val("");
+ $scope("#add-note-modal").modal("show");
Grocy.FrontendHelpers.ValidateForm("add-note-form");
Grocy.IsMealPlanEntryEditAction = false;
});
-
- $(document).on("click", ".add-product-button", function(e)
+
+ top.on("click", ".add-product-button", function(e)
{
var day = $(this).parent().parent().parent().data("date");
-
- $("#add-product-modal-title").text(__t("Add product on %s", day.toString()));
- $("#day").val(day.toString());
+
+ $scope("#add-product-modal-title").text(__t("Add product on %s", day.toString()));
+ $scope("#day").val(day.toString());
Grocy.Components.ProductPicker.Clear();
- $("#add-product-modal").modal("show");
+ $scope("#add-product-modal").modal("show");
Grocy.FrontendHelpers.ValidateForm("add-product-form");
Grocy.IsMealPlanEntryEditAction = false;
});
-
- $(document).on("click", ".edit-meal-plan-entry-button", function(e)
+
+ top.on("click", ".edit-meal-plan-entry-button", function(e)
{
var mealPlanEntry = JSON.parse($(this).parents(".fc-h-event:first").attr("data-meal-plan-entry"));
-
+
if (mealPlanEntry.type == "recipe")
{
- $("#add-recipe-modal-title").text(__t("Edit recipe on %s", mealPlanEntry.day.toString()));
- $("#day").val(mealPlanEntry.day.toString());
- $("#recipe_servings").val(mealPlanEntry.recipe_servings);
+ $scope("#add-recipe-modal-title").text(__t("Edit recipe on %s", mealPlanEntry.day.toString()));
+ $scope("#day").val(mealPlanEntry.day.toString());
+ $scope("#recipe_servings").val(mealPlanEntry.recipe_servings);
Grocy.Components.RecipePicker.SetId(mealPlanEntry.recipe_id);
- $("#add-recipe-modal").modal("show");
+ $scope("#add-recipe-modal").modal("show");
Grocy.FrontendHelpers.ValidateForm("add-recipe-form");
}
else if (mealPlanEntry.type == "product")
{
- $("#add-product-modal-title").text(__t("Edit product on %s", mealPlanEntry.day.toString()));
- $("#day").val(mealPlanEntry.day.toString());
+ $scope("#add-product-modal-title").text(__t("Edit product on %s", mealPlanEntry.day.toString()));
+ $scope("#day").val(mealPlanEntry.day.toString());
Grocy.Components.ProductPicker.SetId(mealPlanEntry.product_id);
- $("#add-product-modal").modal("show");
+ $scope("#add-product-modal").modal("show");
Grocy.FrontendHelpers.ValidateForm("add-product-form");
Grocy.Components.ProductPicker.GetPicker().trigger("change");
}
else if (mealPlanEntry.type == "note")
{
- $("#add-note-modal-title").text(__t("Edit note on %s", mealPlanEntry.day.toString()));
- $("#day").val(mealPlanEntry.day.toString());
- $("#note").val(mealPlanEntry.note);
- $("#add-note-modal").modal("show");
+ $scope("#add-note-modal-title").text(__t("Edit note on %s", mealPlanEntry.day.toString()));
+ $scope("#day").val(mealPlanEntry.day.toString());
+ $scope("#note").val(mealPlanEntry.note);
+ $scope("#add-note-modal").modal("show");
Grocy.FrontendHelpers.ValidateForm("add-note-form");
}
Grocy.IsMealPlanEntryEditAction = true;
Grocy.MealPlanEntryEditObjectId = mealPlanEntry.id;
});
-
- $("#add-recipe-modal").on("shown.bs.modal", function(e)
+
+ $scope("#add-recipe-modal").on("shown.bs.modal", function(e)
{
Grocy.Components.RecipePicker.GetInputElement().focus();
})
-
- $("#add-note-modal").on("shown.bs.modal", function(e)
+
+ $scope("#add-note-modal").on("shown.bs.modal", function(e)
{
- $("#note").focus();
+ $scope("#note").focus();
})
-
- $("#add-product-modal").on("shown.bs.modal", function(e)
+
+ $scope("#add-product-modal").on("shown.bs.modal", function(e)
{
Grocy.Components.ProductPicker.GetInputElement().focus();
})
-
- $(document).on("click", ".remove-recipe-button, .remove-note-button, .remove-product-button", function(e)
+
+ top.on("click", ".remove-recipe-button, .remove-note-button, .remove-product-button", function(e)
{
var mealPlanEntry = JSON.parse($(this).parents(".fc-h-event:first").attr("data-meal-plan-entry"));
-
+
Grocy.Api.Delete('objects/meal_plan/' + mealPlanEntry.id.toString(), {},
function(result)
{
@@ -420,24 +423,24 @@
}
);
});
-
- $('#save-add-recipe-button').on('click', function(e)
+
+ $scope('#save-add-recipe-button').on('click', function(e)
{
e.preventDefault();
-
- if ($(".combobox-menu-visible").length)
+
+ if ($scope(".combobox-menu-visible").length)
{
return;
}
-
+
if (document.getElementById("add-recipe-form").checkValidity() === false) //There is at least one validation error
{
return false;
}
-
+
if (Grocy.IsMealPlanEntryEditAction)
{
- Grocy.Api.Put('objects/meal_plan/' + Grocy.MealPlanEntryEditObjectId.toString(), $('#add-recipe-form').serializeJSON(),
+ Grocy.Api.Put('objects/meal_plan/' + Grocy.MealPlanEntryEditObjectId.toString(), $scope('#add-recipe-form').serializeJSON(),
function(result)
{
window.location.reload();
@@ -450,7 +453,7 @@
}
else
{
- Grocy.Api.Post('objects/meal_plan', $('#add-recipe-form').serializeJSON(),
+ Grocy.Api.Post('objects/meal_plan', $scope('#add-recipe-form').serializeJSON(),
function(result)
{
window.location.reload();
@@ -462,24 +465,24 @@
);
}
});
-
- $('#save-add-note-button').on('click', function(e)
+
+ $scope('#save-add-note-button').on('click', function(e)
{
e.preventDefault();
-
- if ($(".combobox-menu-visible").length)
+
+ if ($scope(".combobox-menu-visible").length)
{
return;
}
-
+
if (document.getElementById("add-note-form").checkValidity() === false) //There is at least one validation error
{
return false;
}
-
- var jsonData = $('#add-note-form').serializeJSON();
- jsonData.day = $("#day").val();
-
+
+ var jsonData = $scope('#add-note-form').serializeJSON();
+ jsonData.day = $scope("#day").val();
+
if (Grocy.IsMealPlanEntryEditAction)
{
Grocy.Api.Put('objects/meal_plan/' + Grocy.MealPlanEntryEditObjectId.toString(), jsonData,
@@ -506,31 +509,31 @@
}
);
}
-
+
});
-
- $('#save-add-product-button').on('click', function(e)
+
+ $scope('#save-add-product-button').on('click', function(e)
{
e.preventDefault();
-
- if ($(".combobox-menu-visible").length)
+
+ if ($scope(".combobox-menu-visible").length)
{
return;
}
-
+
if (document.getElementById("add-product-form").checkValidity() === false) //There is at least one validation error
{
return false;
}
-
- var jsonData = $('#add-product-form').serializeJSON();
- jsonData.day = $("#day").val();
+
+ var jsonData = $scope('#add-product-form').serializeJSON();
+ jsonData.day = $scope("#day").val();
delete jsonData.display_amount;
jsonData.product_amount = jsonData.amount;
delete jsonData.amount;
jsonData.product_qu_id = jsonData.qu_id;
delete jsonData.qu_id;
-
+
if (Grocy.IsMealPlanEntryEditAction)
{
Grocy.Api.Put('objects/meal_plan/' + Grocy.MealPlanEntryEditObjectId.toString(), jsonData,
@@ -558,69 +561,69 @@
);
}
});
-
- $('#add-recipe-form input').keydown(function(event)
+
+ $scope('#add-recipe-form input').keydown(function(event)
{
if (event.keyCode === 13) //Enter
{
event.preventDefault();
-
+
if (document.getElementById("add-recipe-form").checkValidity() === false) //There is at least one validation error
{
return false;
}
else
{
- $("#save-add-recipe-button").click();
+ $scope("#save-add-recipe-button").click();
}
}
});
-
- $('#add-product-form input').keydown(function(event)
+
+ $scope('#add-product-form input').keydown(function(event)
{
if (event.keyCode === 13) //Enter
{
event.preventDefault();
-
+
if (document.getElementById("add-product-form").checkValidity() === false) //There is at least one validation error
{
return false;
}
else
{
- $("#save-add-product-button").click();
+ $scope("#save-add-product-button").click();
}
}
});
-
- $(document).on("keydown", "#servings", function(event)
+
+ top.on("keydown", "#servings", function(event)
{
if (event.key === 13) //Enter
{
event.preventDefault();
-
+
if (document.getElementById("add-recipe-form").checkValidity() === false) //There is at least one validation error
{
return false;
}
else
{
- $("#save-add-recipe-button").click();
+ $scope("#save-add-recipe-button").click();
}
}
});
-
- $(document).on('click', '.recipe-order-missing-button', function(e)
+
+ top.on('click', '.recipe-order-missing-button', function(e)
{
// Remove the focus from the current button
// to prevent that the tooltip stays until clicked anywhere else
document.activeElement.blur();
-
- var objectName = $(e.currentTarget).attr('data-recipe-name');
- var objectId = $(e.currentTarget).attr('data-recipe-id');
+
+ var objectName = $scope(e.currentTarget).attr('data-recipe-name');
+ var objectId = $scope(e.currentTarget).attr('data-recipe-id');
var button = $(this);
- var servings = $(e.currentTarget).attr('data-mealplan-servings');
-
+ var servings = $scope(e.currentTarget).attr('data-mealplan-servings');
+
bootbox.confirm({
message: __t('Are you sure to put all missing ingredients for recipe "%s" on the shopping list?', objectName),
closeButton: false,
@@ -639,7 +642,7 @@
if (result === true)
{
Grocy.FrontendHelpers.BeginUiBusy();
-
+
// Set the recipes desired_servings so that the "recipes resolved"-views resolve correctly based on the meal plan entry servings
Grocy.Api.Put('objects/recipes/' + objectId, { "desired_servings": servings },
function(result)
@@ -673,20 +676,20 @@
}
});
});
-
- $(document).on('click', '.product-consume-button', function(e)
+
+ top.on('click', '.product-consume-button', function(e)
{
e.preventDefault();
-
+
// Remove the focus from the current button
// to prevent that the tooltip stays until clicked anywhere else
document.activeElement.blur();
-
+
Grocy.FrontendHelpers.BeginUiBusy();
-
- var productId = $(e.currentTarget).attr('data-product-id');
- var consumeAmount = parseFloat($(e.currentTarget).attr('data-product-amount'));
-
+
+ var productId = $scope(e.currentTarget).attr('data-product-id');
+ var consumeAmount = parseFloat($scope(e.currentTarget).attr('data-product-amount'));
+
Grocy.Api.Post('stock/products/' + productId + '/consume', { 'amount': consumeAmount, 'spoiled': false },
function(bookingResponse)
{
@@ -694,7 +697,7 @@
function(result)
{
var toastMessage = __t('Removed %1$s of %2$s from stock', consumeAmount.toString() + " " + __n(consumeAmount, result.quantity_unit_stock.name, result.quantity_unit_stock.name_plural), result.product.name) + '
' + __t("Undo") + '';
-
+
Grocy.FrontendHelpers.EndUiBusy();
toastr.success(toastMessage);
window.location.reload();
@@ -713,17 +716,17 @@
}
);
});
-
- $(document).on('click', '.recipe-consume-button', function(e)
+
+ top.on('click', '.recipe-consume-button', function(e)
{
// Remove the focus from the current button
// to prevent that the tooltip stays until clicked anywhere else
document.activeElement.blur();
-
- var objectName = $(e.currentTarget).attr('data-recipe-name');
- var objectId = $(e.currentTarget).attr('data-recipe-id');
- var servings = $(e.currentTarget).attr('data-mealplan-servings');
-
+
+ var objectName = $scope(e.currentTarget).attr('data-recipe-name');
+ var objectId = $scope(e.currentTarget).attr('data-recipe-id');
+ var servings = $scope(e.currentTarget).attr('data-mealplan-servings');
+
bootbox.confirm({
message: __t('Are you sure to consume all ingredients needed by recipe "%s" (ingredients marked with "only check if any amount is in stock" will be ignored)?', objectName),
closeButton: false,
@@ -742,7 +745,7 @@
if (result === true)
{
Grocy.FrontendHelpers.BeginUiBusy();
-
+
// Set the recipes desired_servings so that the "recipes resolved"-views resolve correctly based on the meal plan entry servings
Grocy.Api.Put('objects/recipes/' + objectId, { "desired_servings": servings },
function(result)
@@ -771,16 +774,16 @@
}
});
});
-
- $(document).on("click", ".recipe-popup-button", function(e)
+
+ top.on("click", ".recipe-popup-button", function(e)
{
// Remove the focus from the current button
// to prevent that the tooltip stays until clicked anywhere else
document.activeElement.blur();
-
- var objectId = $(e.currentTarget).attr('data-recipe-id');
- var servings = $(e.currentTarget).attr('data-mealplan-servings');
-
+
+ var objectId = $scope(e.currentTarget).attr('data-recipe-id');
+ var servings = $scope(e.currentTarget).attr('data-mealplan-servings');
+
// Set the recipes desired_servings so that the "recipes resolved"-views resolve correctly based on the meal plan entry servings
Grocy.Api.Put('objects/recipes/' + objectId, { "desired_servings": servings },
function(result)
@@ -808,12 +811,12 @@
}
);
});
-
+
$(window).one("resize", function()
{
// Automatically switch the calendar to "basicDay" view on small screens
// and to "basicWeek" otherwise
- if ($(window).width() < 768)
+ if (viewport.width() < 768)
{
calendar.changeView("dayGridDay");
}
@@ -822,24 +825,24 @@
calendar.changeView("dayGridWeek");
}
});
-
+
Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
{
- var productId = $(e.target).val();
-
+ var productId = $scope(e.target).val();
+
if (productId)
{
Grocy.Api.Get('stock/products/' + productId,
function(productDetails)
{
Grocy.Components.ProductAmountPicker.Reload(productDetails.product.id, productDetails.quantity_unit_stock.id);
-
- $('#display_amount').val(1);
+
+ $scope('#display_amount').val(1);
RefreshLocaleNumberInput();
- $(".input-group-productamountpicker").trigger("change");
- $('#display_amount').focus();
- $('#display_amount').select();
- $(".input-group-productamountpicker").trigger("change");
+ $scope(".input-group-productamountpicker").trigger("change");
+ $scope('#display_amount').focus();
+ $scope('#display_amount').select();
+ $scope(".input-group-productamountpicker").trigger("change");
Grocy.FrontendHelpers.ValidateForm('add-product-form');
},
function(xhr)
@@ -849,19 +852,19 @@
);
}
});
-
+
Grocy.Components.RecipePicker.GetPicker().on('change', function(e)
{
- var recipeId = $(e.target).val();
-
+ var recipeId = $scope(e.target).val();
+
if (recipeId)
{
Grocy.Api.Get('objects/recipes/' + recipeId,
function(recipe)
{
- $("#recipe_servings").val(recipe.base_servings);
- $("#recipe_servings").focus();
- $("#recipe_servings").select();
+ $scope("#recipe_servings").val(recipe.base_servings);
+ $scope("#recipe_servings").focus();
+ $scope("#recipe_servings").select();
},
function(xhr)
{
@@ -870,5 +873,5 @@
);
}
});
-
+
}
diff --git a/js/viewjs/productbarcodeform.js b/js/viewjs/productbarcodeform.js
index 1a60ed2d..56d170d8 100644
--- a/js/viewjs/productbarcodeform.js
+++ b/js/viewjs/productbarcodeform.js
@@ -1,32 +1,34 @@
-function productbarcodeformView(Grocy, scope = null)
+import { WindowMessageBag } from '../helpers/messagebag';
+
+function productbarcodeformView(Grocy, scope = null)
{
var $scope = $;
+ var top = scope != null ? $(scope) : $(document);
+
if (scope != null)
{
$scope = $(scope).find;
}
- import { WindowMessageBag } from '../helpers/messagebag';
-
Grocy.Use('barcodescanner');
Grocy.Use("productamountpicker");
Grocy.Use("userfieldsform");
-
- $('#save-barcode-button').on('click', function(e)
+
+ $scope('#save-barcode-button').on('click', function(e)
{
e.preventDefault();
-
- if ($(".combobox-menu-visible").length)
+
+ if ($scope(".combobox-menu-visible").length)
{
return;
}
-
- var jsonData = $('#barcode-form').serializeJSON();
+
+ var jsonData = $scope('#barcode-form').serializeJSON();
jsonData.amount = jsonData.display_amount;
delete jsonData.display_amount;
-
+
Grocy.FrontendHelpers.BeginUiBusy("barcode-form");
-
+
if (Grocy.EditMode === 'create')
{
Grocy.Api.Post('objects/product_barcodes', jsonData,
@@ -34,7 +36,7 @@
{
Grocy.EditObjectId = result.created_object_id;
Grocy.Components.UserfieldsForm.Save()
-
+
window.parent.postMessage(WindowMessageBag("ProductBarcodesChanged"), U("/product/" + GetUriParam("product")));
window.parent.postMessage(WindowMessageBag("CloseAllModals"), U("/product/" + GetUriParam("product")));
},
@@ -62,60 +64,62 @@
);
}
});
-
- $('#barcode').on('keyup', function(e)
+
+ $scope('#barcode').on('keyup', function(e)
{
Grocy.FrontendHelpers.ValidateForm('barcode-form');
});
-
- $('#qu_id').on('change', function(e)
+
+ $scope('#qu_id').on('change', function(e)
{
Grocy.FrontendHelpers.ValidateForm('barcode-form');
});
-
- $('#display_amount').on('keyup', function(e)
+
+ $scope('#display_amount').on('keyup', function(e)
{
Grocy.FrontendHelpers.ValidateForm('barcode-form');
});
-
- $('#barcode-form input').keydown(function(event)
+
+ $scope('#barcode-form input').keydown(function(event)
{
if (event.keyCode === 13) //Enter
{
event.preventDefault();
-
+
if (document.getElementById('barcode-form').checkValidity() === false) //There is at least one validation error
{
return false;
}
else
{
- $('#save-barcode-button').click();
+ $scope('#save-barcode-button').click();
}
}
});
-
+
Grocy.Components.ProductAmountPicker.Reload(Grocy.EditObjectProduct.id, Grocy.EditObjectProduct.qu_id_purchase);
if (Grocy.EditMode == "edit")
{
- $("#display_amount").val(Grocy.EditObject.amount);
- $(".input-group-productamountpicker").trigger("change");
+ $scope("#display_amount").val(Grocy.EditObject.amount);
+ $scope(".input-group-productamountpicker").trigger("change");
Grocy.Components.ProductAmountPicker.SetQuantityUnit(Grocy.EditObject.qu_id);
}
-
+
Grocy.FrontendHelpers.ValidateForm('barcode-form');
- $('#barcode').focus();
+ $scope('#barcode').focus();
RefreshLocaleNumberInput();
Grocy.Components.UserfieldsForm.Load()
-
- $(document).on("Grocy.BarcodeScanned", function(e, barcode, target)
+
+ top.on("Grocy.BarcodeScanned", function(e, barcode, target)
{
if (target !== "#barcode")
{
return;
}
-
- $("#barcode").val(barcode);
+
+ $scope("#barcode").val(barcode);
});
-
+
}
+
+window.productbarcodeformView = productbarcodeformView
\ No newline at end of file
diff --git a/js/viewjs/productform.js b/js/viewjs/productform.js
index 998b1d1a..da4a688e 100644
--- a/js/viewjs/productform.js
+++ b/js/viewjs/productform.js
@@ -1,26 +1,28 @@
-function productformView(Grocy, scope = null)
+import { BoolVal } from '../helpers/extensions';
+
+function productformView(Grocy, scope = null)
{
var $scope = $;
+ var top = scope != null ? $(scope) : $(document);
+
if (scope != null)
{
$scope = $(scope).find;
}
- import { BoolVal } from '../helpers/extensions';
-
Grocy.Use("numberpicker");
Grocy.Use("shoppinglocationpicker");
Grocy.Use("userfieldsform");
-
+
function saveProductPicture(result, location, jsonData)
{
var productId = Grocy.EditObjectId || result.created_object_id;
-
+
Grocy.Components.UserfieldsForm.Save(() =>
{
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($scope("#product-picture")[0].files[0], 'productpictures', jsonData.picture_file_name,
(result) =>
{
if (Grocy.ProductEditFormRedirectUri == "reload")
@@ -28,7 +30,7 @@
window.location.reload();
return
}
-
+
var returnTo = GetUriParam('returnto');
if (GetUriParam("closeAfterCreation") !== undefined)
{
@@ -38,19 +40,19 @@
{
if (GetUriParam("flow") !== undefined)
{
- window.location.href = U(returnTo) + '&product-name=' + encodeURIComponent($('#name').val());
+ window.location.href = U(returnTo) + '&product-name=' + encodeURIComponent($scope('#name').val());
}
else
{
window.location.href = U(returnTo);
}
-
+
}
else
{
window.location.href = U(location + productId);
}
-
+
},
(xhr) =>
{
@@ -66,7 +68,7 @@
window.location.reload();
return
}
-
+
var returnTo = GetUriParam('returnto');
if (GetUriParam("closeAfterCreation") !== undefined)
{
@@ -76,7 +78,7 @@
{
if (GetUriParam("flow") !== undefined)
{
- window.location.href = U(returnTo) + '&product-name=' + encodeURIComponent($('#name').val());
+ window.location.href = U(returnTo) + '&product-name=' + encodeURIComponent($scope('#name').val());
}
else
{
@@ -90,30 +92,30 @@
}
});
}
-
- $('.save-product-button').on('click', function(e)
+
+ $scope('.save-product-button').on('click', function(e)
{
e.preventDefault();
-
- var jsonData = $('#product-form').serializeJSON();
+
+ var jsonData = $scope('#product-form').serializeJSON();
var parentProductId = jsonData.product_id;
delete jsonData.product_id;
jsonData.parent_product_id = parentProductId;
Grocy.FrontendHelpers.BeginUiBusy("product-form");
-
+
if (jsonData.parent_product_id.toString().isEmpty())
{
jsonData.parent_product_id = null;
}
-
- if ($("#product-picture")[0].files.length > 0)
+
+ if ($scope("#product-picture")[0].files.length > 0)
{
var someRandomStuff = Math.random().toString(36).substring(2, 100) + Math.random().toString(36).substring(2, 100);
- jsonData.picture_file_name = someRandomStuff + $("#product-picture")[0].files[0].name;
+ jsonData.picture_file_name = someRandomStuff + $scope("#product-picture")[0].files[0].name;
}
-
- const location = $(e.currentTarget).attr('data-location') == 'return' ? '/products?product=' : '/product/';
-
+
+ const location = $scope(e.currentTarget).attr('data-location') == 'return' ? '/products?product=' : '/product/';
+
if (Grocy.EditMode == 'create')
{
Grocy.Api.Post('objects/products', jsonData,
@@ -125,11 +127,11 @@
});
return;
}
-
+
if (Grocy.DeleteProductPictureOnSave)
{
jsonData.picture_file_name = null;
-
+
Grocy.Api.DeleteFile(Grocy.ProductPictureFileName, 'productpictures', {},
function(result)
{
@@ -142,7 +144,7 @@
}
);
}
-
+
Grocy.Api.Put('objects/products/' + Grocy.EditObjectId, jsonData,
(result) => saveProductPicture(result, location, jsonData),
function(xhr)
@@ -152,7 +154,7 @@
}
);
});
-
+
if (Grocy.EditMode == "edit")
{
Grocy.Api.Get('stock/products/' + Grocy.EditObjectId,
@@ -160,7 +162,7 @@
{
if (productDetails.last_purchased == null)
{
- $('#qu_id_stock').removeAttr("disabled");
+ $scope('#qu_id_stock').removeAttr("disabled");
}
},
function(xhr)
@@ -169,118 +171,118 @@
}
);
}
-
+
if (GetUriParam("flow") == "InplaceNewProductWithName")
{
- $('#name').val(GetUriParam("name"));
- $('#name').focus();
+ $scope('#name').val(GetUriParam("name"));
+ $scope('#name').focus();
}
-
+
if (GetUriParam("flow") !== undefined || GetUriParam("returnto") !== undefined)
{
- $("#save-hint").addClass("d-none");
- $(".save-product-button[data-location='return']").addClass("d-none");
+ $scope("#save-hint").addClass("d-none");
+ $scope(".save-product-button[data-location='return']").addClass("d-none");
}
-
- $('.input-group-qu').on('change', function(e)
+
+ $scope('.input-group-qu').on('change', function(e)
{
- var quIdPurchase = $("#qu_id_purchase").val();
- var quIdStock = $("#qu_id_stock").val();
- var factor = $('#qu_factor_purchase_to_stock').val();
-
+ var quIdPurchase = $scope("#qu_id_purchase").val();
+ var quIdStock = $scope("#qu_id_stock").val();
+ var factor = $scope('#qu_factor_purchase_to_stock').val();
+
if (factor > 1 || quIdPurchase != quIdStock)
{
- $('#qu-conversion-info').text(__t('This means 1 %1$s purchased will be converted into %2$s %3$s in stock', $("#qu_id_purchase option:selected").text(), (1 * factor).toString(), __n((1 * factor).toString(), $("#qu_id_stock option:selected").text(), $("#qu_id_stock option:selected").data("plural-form"))));
- $('#qu-conversion-info').removeClass('d-none');
+ $scope('#qu-conversion-info').text(__t('This means 1 %1$s purchased will be converted into %2$s %3$s in stock', $scope("#qu_id_purchase option:selected").text(), (1 * factor).toString(), __n((1 * factor).toString(), $scope("#qu_id_stock option:selected").text(), $scope("#qu_id_stock option:selected").data("plural-form"))));
+ $scope('#qu-conversion-info').removeClass('d-none');
}
else
{
- $('#qu-conversion-info').addClass('d-none');
+ $scope('#qu-conversion-info').addClass('d-none');
}
-
- $("#tare_weight_qu_info").text($("#qu_id_stock option:selected").text());
- $("#quick_consume_qu_info").text($("#qu_id_stock option:selected").text());
-
+
+ $scope("#tare_weight_qu_info").text($scope("#qu_id_stock option:selected").text());
+ $scope("#quick_consume_qu_info").text($scope("#qu_id_stock option:selected").text());
+
Grocy.FrontendHelpers.ValidateForm('product-form');
});
-
- $('#product-form input').keyup(function(event)
+
+ $scope('#product-form input').keyup(function(event)
{
Grocy.FrontendHelpers.ValidateForm('product-form');
- $(".input-group-qu").trigger("change");
- $("#product-form select").trigger("select");
-
+ $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
{
- $("#qu-conversion-add-button").addClass("disabled");
+ $scope("#qu-conversion-add-button").addClass("disabled");
}
else
{
- $("#qu-conversion-add-button").removeClass("disabled");
+ $scope("#qu-conversion-add-button").removeClass("disabled");
}
-
+
if (document.getElementById('product-form').checkValidity() === false) //There is at least one validation error
{
- $("#barcode-add-button").addClass("disabled");
+ $scope("#barcode-add-button").addClass("disabled");
}
});
-
- $('#location_id').change(function(event)
+
+ $scope('#location_id').change(function(event)
{
Grocy.FrontendHelpers.ValidateForm('product-form');
});
-
- $('#product-form input').keydown(function(event)
+
+ $scope('#product-form input').keydown(function(event)
{
if (event.keyCode === 13) //Enter
{
event.preventDefault();
-
+
if (document.getElementById('product-form').checkValidity() === false) //There is at least one validation error
{
return false;
}
else
{
- $('#save-product-button').click();
+ $scope('#save-product-button').click();
}
}
});
-
- $("#enable_tare_weight_handling").on("click", function()
+
+ $scope("#enable_tare_weight_handling").on("click", function()
{
if (this.checked)
{
- $("#tare_weight").removeAttr("disabled");
+ $scope("#tare_weight").removeAttr("disabled");
}
else
{
- $("#tare_weight").attr("disabled", "");
+ $scope("#tare_weight").attr("disabled", "");
}
-
+
Grocy.FrontendHelpers.ValidateForm("product-form");
});
-
- $("#product-picture").on("change", function(e)
+
+ $scope("#product-picture").on("change", function(e)
{
- $("#product-picture-label").removeClass("d-none");
- $("#product-picture-label-none").addClass("d-none");
- $("#delete-current-product-picture-on-save-hint").addClass("d-none");
- $("#current-product-picture").addClass("d-none");
+ $scope("#product-picture-label").removeClass("d-none");
+ $scope("#product-picture-label-none").addClass("d-none");
+ $scope("#delete-current-product-picture-on-save-hint").addClass("d-none");
+ $scope("#current-product-picture").addClass("d-none");
Grocy.DeleteProductPictureOnSave = false;
});
-
+
Grocy.DeleteProductPictureOnSave = false;
- $("#delete-current-product-picture-button").on("click", function(e)
+ $scope("#delete-current-product-picture-button").on("click", function(e)
{
Grocy.DeleteProductPictureOnSave = true;
- $("#current-product-picture").addClass("d-none");
- $("#delete-current-product-picture-on-save-hint").removeClass("d-none");
- $("#product-picture-label").addClass("d-none");
- $("#product-picture-label-none").removeClass("d-none");
+ $scope("#current-product-picture").addClass("d-none");
+ $scope("#delete-current-product-picture-on-save-hint").removeClass("d-none");
+ $scope("#product-picture-label").addClass("d-none");
+ $scope("#product-picture-label-none").removeClass("d-none");
});
-
- var quConversionsTable = $('#qu-conversions-table-products').DataTable({
+
+ var quConversionsTable = $scope('#qu-conversions-table-products').DataTable({
'order': [[1, 'asc']],
"orderFixed": [[4, 'asc']],
'columnDefs': [
@@ -293,10 +295,10 @@
dataSrc: 4
}
});
- $('#qu-conversions-table-products tbody').removeClass("d-none");
+ $scope('#qu-conversions-table-products tbody').removeClass("d-none");
quConversionsTable.columns.adjust().draw();
-
- var barcodeTable = $('#barcode-table').DataTable({
+
+ var barcodeTable = $scope('#barcode-table').DataTable({
'order': [[1, 'asc']],
"orderFixed": [[1, 'asc']],
'columnDefs': [
@@ -306,20 +308,20 @@
{ 'visible': false, 'targets': 6 }
].concat($.fn.dataTable.defaults.columnDefs)
});
- $('#barcode-table tbody').removeClass("d-none");
+ $scope('#barcode-table tbody').removeClass("d-none");
barcodeTable.columns.adjust().draw();
-
+
Grocy.Components.UserfieldsForm.Load();
- $("#name").trigger("keyup");
- $('#name').focus();
- $('.input-group-qu').trigger('change');
+ $scope("#name").trigger("keyup");
+ $scope('#name').focus();
+ $scope('.input-group-qu').trigger('change');
Grocy.FrontendHelpers.ValidateForm('product-form');
-
- $(document).on('click', '.stockentry-grocycode-product-label-print', function(e)
+
+ top.on('click', '.stockentry-grocycode-product-label-print', function(e)
{
e.preventDefault();
document.activeElement.blur();
-
+
var productId = $(e.currentTarget).attr('data-product-id');
Grocy.Api.Get('stock/products/' + productId + '/printlabel', function(labelData)
{
@@ -329,120 +331,72 @@
}
});
});
-
- $(document).on('click', '.qu-conversion-delete-button', function(e)
- {
- var objectId = $(e.currentTarget).attr('data-qu-conversion-id');
-
- bootbox.confirm({
- message: __t('Are you sure to remove this conversion?'),
- closeButton: false,
- buttons: {
- confirm: {
- label: __t('Yes'),
- className: 'btn-success'
- },
- cancel: {
- label: __t('No'),
- className: 'btn-danger'
- }
- },
- callback: function(result)
- {
- if (result === true)
- {
- Grocy.Api.Delete('objects/quantity_unit_conversions/' + objectId, {},
- function(result)
- {
- Grocy.ProductEditFormRedirectUri = "reload";
- $('#save-product-button').click();
- },
- function(xhr)
- {
- console.error(xhr);
- }
- );
- }
- }
- });
- });
-
- $(document).on('click', '.barcode-delete-button', function(e)
- {
- var objectId = $(e.currentTarget).attr('data-barcode-id');
-
- bootbox.confirm({
- message: __t('Are you sure to remove this barcode?'),
- closeButton: false,
- buttons: {
- confirm: {
- label: __t('Yes'),
- className: 'btn-success'
- },
- cancel: {
- label: __t('No'),
- className: 'btn-danger'
- }
- },
- callback: function(result)
- {
- if (result === true)
- {
- Grocy.Api.Delete('objects/product_barcodes/' + objectId, {},
- function(result)
- {
- Grocy.ProductEditFormRedirectUri = "reload";
- $('#save-product-button').click();
- },
- function(xhr)
- {
- console.error(xhr);
- }
- );
- }
- }
- });
- });
-
- $('#qu_id_stock').change(function(e)
+
+ Grocy.FrontendHelpers.MakeDeleteConfirmBox(
+ 'Are you sure to remove this conversion?',
+ '.qu-conversion-delete-button',
+ 'data-qu-conversion-id',
+ 'data-qu-conversion-id',
+ 'objects/quantity_unit_conversions/',
+ (result, id, name) =>
+ {
+ Grocy.ProductEditFormRedirectUri = "reload";
+ $scope('#save-product-button').click();
+ }
+ );
+
+ Grocy.FrontendHelpers.MakeDeleteConfirmBox(
+ 'Are you sure to remove this barcode?',
+ '.barcode-delete-button',
+ 'data-barcode-id',
+ 'data-barcode-id',
+ 'objects/product_barcodes/',
+ (result, id, name) =>
+ {
+ Grocy.ProductEditFormRedirectUri = "reload";
+ $scope('#save-product-button').click();
+ }
+ )
+
+ $scope('#qu_id_stock').change(function(e)
{
// Preset QU purchase with stock QU if unset
- var quIdStock = $('#qu_id_stock');
- var quIdPurchase = $('#qu_id_purchase');
-
+ var quIdStock = $scope('#qu_id_stock');
+ var quIdPurchase = $scope('#qu_id_purchase');
+
if (quIdPurchase[0].selectedIndex === 0 && quIdStock[0].selectedIndex !== 0)
{
quIdPurchase[0].selectedIndex = quIdStock[0].selectedIndex;
Grocy.FrontendHelpers.ValidateForm('product-form');
}
});
-
- $('#allow_label_per_unit').on('change', function()
+
+ $scope('#allow_label_per_unit').on('change', function()
{
if (this.checked)
{
- $('#label-option-per-unit').prop("disabled", false);
+ $scope('#label-option-per-unit').prop("disabled", false);
}
else
{
- if ($('#default_print_stock_label').val() == "2")
+ if ($scope('#default_print_stock_label').val() == "2")
{
- $("#default_print_stock_label").val("0");
+ $scope("#default_print_stock_label").val("0");
}
- $('#label-option-per-unit').prop("disabled", true);
+ $scope('#label-option-per-unit').prop("disabled", true);
}
});
-
+
$(window).on("message", function(e)
{
var data = e.originalEvent.data;
-
+
if (data.Message === "ProductBarcodesChanged" || data.Message === "ProductQUConversionChanged")
{
window.location.reload();
}
});
-
+
if (Grocy.EditMode == "create" && GetUriParam("copy-of") != undefined)
{
Grocy.Api.Get('objects/products/' + GetUriParam("copy-of"),
@@ -454,44 +408,44 @@
}
if (sourceProduct.description != null)
{
- $("#description").summernote("pasteHTML", sourceProduct.description);
+ $scope("#description").summernote("pasteHTML", sourceProduct.description);
}
- $("#location_id").val(sourceProduct.location_id);
+ $scope("#location_id").val(sourceProduct.location_id);
if (sourceProduct.shopping_location_id != null)
{
Grocy.Components.ShoppingLocationPicker.SetId(sourceProduct.shopping_location_id);
}
- $("#min_stock_amount").val(sourceProduct.min_stock_amount);
+ $scope("#min_stock_amount").val(sourceProduct.min_stock_amount);
if (BoolVal(sourceProduct.cumulate_min_stock_amount_of_sub_products))
{
- $("#cumulate_min_stock_amount_of_sub_products").prop("checked", true);
+ $scope("#cumulate_min_stock_amount_of_sub_products").prop("checked", true);
}
- $("#default_best_before_days").val(sourceProduct.default_best_before_days);
- $("#default_best_before_days_after_open").val(sourceProduct.default_best_before_days_after_open);
+ $scope("#default_best_before_days").val(sourceProduct.default_best_before_days);
+ $scope("#default_best_before_days_after_open").val(sourceProduct.default_best_before_days_after_open);
if (sourceProduct.product_group_id != null)
{
- $("#product_group_id").val(sourceProduct.product_group_id);
+ $scope("#product_group_id").val(sourceProduct.product_group_id);
}
- $("#qu_id_stock").val(sourceProduct.qu_id_stock);
- $("#qu_id_purchase").val(sourceProduct.qu_id_purchase);
- $("#qu_factor_purchase_to_stock").val(sourceProduct.qu_factor_purchase_to_stock);
+ $scope("#qu_id_stock").val(sourceProduct.qu_id_stock);
+ $scope("#qu_id_purchase").val(sourceProduct.qu_id_purchase);
+ $scope("#qu_factor_purchase_to_stock").val(sourceProduct.qu_factor_purchase_to_stock);
if (BoolVal(sourceProduct.enable_tare_weight_handling))
{
- $("#enable_tare_weight_handling").prop("checked", true);
+ $scope("#enable_tare_weight_handling").prop("checked", true);
}
- $("#tare_weight").val(sourceProduct.tare_weight);
+ $scope("#tare_weight").val(sourceProduct.tare_weight);
if (BoolVal(sourceProduct.not_check_stock_fulfillment_for_recipes))
{
- $("#not_check_stock_fulfillment_for_recipes").prop("checked", true);
+ $scope("#not_check_stock_fulfillment_for_recipes").prop("checked", true);
}
if (sourceProduct.calories != null)
{
- $("#calories").val(sourceProduct.calories);
+ $scope("#calories").val(sourceProduct.calories);
}
- $("#default_best_before_days_after_freezing").val(sourceProduct.default_best_before_days_after_freezing);
- $("#default_best_before_days_after_thawing").val(sourceProduct.default_best_before_days_after_thawing);
- $("#quick_consume_amount").val(sourceProduct.quick_consume_amount);
-
+ $scope("#default_best_before_days_after_freezing").val(sourceProduct.default_best_before_days_after_freezing);
+ $scope("#default_best_before_days_after_thawing").val(sourceProduct.default_best_before_days_after_thawing);
+ $scope("#quick_consume_amount").val(sourceProduct.quick_consume_amount);
+
Grocy.FrontendHelpers.ValidateForm('product-form');
},
function(xhr)
@@ -504,20 +458,22 @@
{
if (Grocy.UserSettings.product_presets_location_id.toString() !== '-1')
{
- $("#location_id").val(Grocy.UserSettings.product_presets_location_id);
+ $scope("#location_id").val(Grocy.UserSettings.product_presets_location_id);
}
-
+
if (Grocy.UserSettings.product_presets_product_group_id.toString() !== '-1')
{
- $("#product_group_id").val(Grocy.UserSettings.product_presets_product_group_id);
+ $scope("#product_group_id").val(Grocy.UserSettings.product_presets_product_group_id);
}
-
+
if (Grocy.UserSettings.product_presets_qu_id.toString() !== '-1')
{
- $("select.input-group-qu").val(Grocy.UserSettings.product_presets_qu_id);
+ $scope("select.input-group-qu").val(Grocy.UserSettings.product_presets_qu_id);
}
}
-
+
Grocy.FrontendHelpers.ValidateForm("product-form");
-
+
}
+
+window.productformView = productformView
\ No newline at end of file
diff --git a/js/viewjs/productgroupform.js b/js/viewjs/productgroupform.js
index eda94970..66fff19f 100644
--- a/js/viewjs/productgroupform.js
+++ b/js/viewjs/productgroupform.js
@@ -1,4 +1,6 @@
-function productgroupformView(Grocy, scope = null)
+import { WindowMessageBag } from '../helpers/messagebag';
+
+function productgroupformView(Grocy, scope = null)
{
var $scope = $;
if (scope != null)
@@ -6,22 +8,20 @@
$scope = $(scope).find;
}
- import { WindowMessageBag } from '../helpers/messagebag';
-
Grocy.Use("userfieldsform");
-
- $('#save-product-group-button').on('click', function(e)
+
+ $scope('#save-product-group-button').on('click', function(e)
{
e.preventDefault();
-
- if ($(".combobox-menu-visible").length)
+
+ if ($scope(".combobox-menu-visible").length)
{
return;
}
-
- var jsonData = $('#product-group-form').serializeJSON();
+
+ var jsonData = $scope('#product-group-form').serializeJSON();
Grocy.FrontendHelpers.BeginUiBusy("product-group-form");
-
+
if (Grocy.EditMode === 'create')
{
Grocy.Api.Post('objects/product_groups', jsonData,
@@ -58,31 +58,33 @@
);
}
});
-
- $('#product-group-form input').keyup(function(event)
+
+ $scope('#product-group-form input').keyup(function(event)
{
Grocy.FrontendHelpers.ValidateForm('product-group-form');
});
-
- $('#product-group-form input').keydown(function(event)
+
+ $scope('#product-group-form input').keydown(function(event)
{
if (event.keyCode === 13) //Enter
{
event.preventDefault();
-
+
if (document.getElementById('product-group-form').checkValidity() === false) //There is at least one validation error
{
return false;
}
else
{
- $('#save-product-group-button').click();
+ $scope('#save-product-group-button').click();
}
}
});
-
+
Grocy.Components.UserfieldsForm.Load();
- $('#name').focus();
+ $scope('#name').focus();
Grocy.FrontendHelpers.ValidateForm('product-group-form');
-
+
}
+
+window.productgroupformView = productgroupformView
\ No newline at end of file
diff --git a/js/viewjs/productgroups.js b/js/viewjs/productgroups.js
index e33dbde2..73b790e2 100644
--- a/js/viewjs/productgroups.js
+++ b/js/viewjs/productgroups.js
@@ -6,14 +6,14 @@
$scope = $(scope).find;
}
- var groupsTable = $('#productgroups-table').DataTable({
+ var groupsTable = $scope('#productgroups-table').DataTable({
'order': [[1, 'asc']],
'columnDefs': [
{ 'orderable': false, 'targets': 0 },
{ 'searchable': false, "targets": 0 }
].concat($.fn.dataTable.defaults.columnDefs)
});
- $('#productgroups-table tbody').removeClass("d-none");
+ $scope('#productgroups-table tbody').removeClass("d-none");
Grocy.FrontendHelpers.InitDataTable(groupsTable);
Grocy.FrontendHelpers.MakeDeleteConfirmBox(
'Are you sure to delete product group "%s"?',
@@ -23,15 +23,14 @@
'objects/product_groups/',
'/productgroups'
);
-
+
$(window).on("message", function(e)
{
var data = e.originalEvent.data;
-
+
if (data.Message === "CloseAllModals")
{
window.location.reload();
}
});
-
}
diff --git a/js/viewjs/products.js b/js/viewjs/products.js
index eb9e4252..6bf90e22 100644
--- a/js/viewjs/products.js
+++ b/js/viewjs/products.js
@@ -6,7 +6,7 @@
$scope = $(scope).find;
}
- var productsTable = $('#products-table').DataTable({
+ var productsTable = $scope('#products-table').DataTable({
'order': [[1, 'asc']],
'columnDefs': [
{ 'orderable': false, 'targets': 0 },
@@ -15,22 +15,22 @@
{ "type": "html-num-fmt", "targets": 3 }
].concat($.fn.dataTable.defaults.columnDefs)
});
- $('#products-table tbody').removeClass("d-none");
-
+ $scope('#products-table tbody').removeClass("d-none");
+
Grocy.FrontendHelpers.InitDataTable(productsTable, null, function()
{
- $("#search").val("");
+ $scope("#search").val("");
productsTable.search("").draw();
- $("#show-disabled").prop('checked', false);
+ $scope("#show-disabled").prop('checked', false);
})
-
+
Grocy.FrontendHelpers.MakeFilterForColumn("#product-group-filter", 6, productsTable);
if (typeof GetUriParam("product-group") !== "undefined")
{
- $("#product-group-filter").val(GetUriParam("product-group"));
- $("#product-group-filter").trigger("change");
+ $scope("#product-group-filter").val(GetUriParam("product-group"));
+ $scope("#product-group-filter").trigger("change");
}
-
+
Grocy.FrontendHelpers.MakeDeleteConfirmBox(
(objectId, objectName) =>
{
@@ -44,8 +44,8 @@
'objects/products/',
'/products'
);
-
- $("#show-disabled").change(function()
+
+ $scope("#show-disabled").change(function()
{
if (this.checked)
{
@@ -56,26 +56,26 @@
window.location.href = U('/products');
}
});
-
+
if (GetUriParam('include_disabled'))
{
- $("#show-disabled").prop('checked', true);
+ $scope("#show-disabled").prop('checked', true);
}
-
-
- $(".merge-products-button").on("click", function(e)
+
+
+ $scope(".merge-products-button").on("click", function(e)
{
- var productId = $(e.currentTarget).attr("data-product-id");
- $("#merge-products-keep").val(productId);
- $("#merge-products-remove").val("");
- $("#merge-products-modal").modal("show");
+ var productId = $scope(e.currentTarget).attr("data-product-id");
+ $scope("#merge-products-keep").val(productId);
+ $scope("#merge-products-remove").val("");
+ $scope("#merge-products-modal").modal("show");
});
-
- $("#merge-products-save-button").on("click", function()
+
+ $scope("#merge-products-save-button").on("click", function()
{
- var productIdToKeep = $("#merge-products-keep").val();
- var productIdToRemove = $("#merge-products-remove").val();
-
+ var productIdToKeep = $scope("#merge-products-keep").val();
+ var productIdToRemove = $scope("#merge-products-remove").val();
+
Grocy.Api.Post("stock/products/" + productIdToKeep.toString() + "/merge/" + productIdToRemove.toString(), {},
function(result)
{
@@ -87,5 +87,5 @@
}
);
});
-
+
}
diff --git a/js/viewjs/purchase.js b/js/viewjs/purchase.js
index 8aceb129..b2928b55 100644
--- a/js/viewjs/purchase.js
+++ b/js/viewjs/purchase.js
@@ -1,4 +1,7 @@
-function purchaseView(Grocy, scope = null)
+import { BoolVal } from '../helpers/extensions';
+import { WindowMessageBag } from '../helpers/messagebag';
+
+function purchaseView(Grocy, scope = null)
{
var $scope = $;
if (scope != null)
@@ -6,9 +9,6 @@
$scope = $(scope).find;
}
- import { BoolVal } from '../helpers/extensions';
- import { WindowMessageBag } from '../helpers/messagebag';
-
Grocy.Use("datetimepicker");
if (Grocy.UserSettings.show_purchased_date_on_purchase)
{
@@ -19,34 +19,34 @@
Grocy.Use("productamountpicker");
Grocy.Use("productcard");
Grocy.Use("shoppinglocationpicker");
-
+
var CurrentProductDetails;
-
- $('#save-purchase-button').on('click', function(e)
+
+ $scope('#save-purchase-button').on('click', function(e)
{
e.preventDefault();
-
- if ($(".combobox-menu-visible").length)
+
+ if ($scope(".combobox-menu-visible").length)
{
return;
}
-
- if ($(".combobox-menu-visible").length)
+
+ if ($scope(".combobox-menu-visible").length)
{
return;
}
-
- var jsonForm = $('#purchase-form').serializeJSON();
-
+
+ var jsonForm = $scope('#purchase-form').serializeJSON();
+
Grocy.FrontendHelpers.BeginUiBusy("purchase-form");
-
+
Grocy.Api.Get('stock/products/' + jsonForm.product_id,
function(productDetails)
{
var jsonData = {};
jsonData.amount = jsonForm.amount;
jsonData.print_stock_label = jsonForm.print_stock_label
-
+
if (!Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING)
{
jsonData.price = 0;
@@ -58,21 +58,21 @@
{
amount -= parseFloat(productDetails.product.tare_weight);
}
-
- var price = parseFloat(jsonForm.price * $("#qu_id option:selected").attr("data-qu-factor")).toFixed(Grocy.UserSettings.stock_decimal_places_prices);
- if ($("input[name='price-type']:checked").val() == "total-price")
+
+ var price = parseFloat(jsonForm.price * $scope("#qu_id option:selected").attr("data-qu-factor")).toFixed(Grocy.UserSettings.stock_decimal_places_prices);
+ if ($scope("input[name='price-type']:checked").val() == "total-price")
{
price = parseFloat(price / amount).toFixed(Grocy.UserSettings.stock_decimal_places_prices);
}
-
+
jsonData.price = price;
}
-
+
if (BoolVal(Grocy.UserSettings.show_purchased_date_on_purchase))
{
jsonData.purchased_date = Grocy.Components.DateTimePicker2.GetValue();
}
-
+
if (Grocy.Components.DateTimePicker)
{
jsonData.best_before_date = Grocy.Components.DateTimePicker.GetValue();
@@ -81,7 +81,7 @@
{
jsonData.best_before_date = null;
}
-
+
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING)
{
jsonData.shopping_location_id = Grocy.Components.ShoppingLocationPicker.GetValue();
@@ -90,38 +90,38 @@
{
jsonData.location_id = Grocy.Components.LocationPicker.GetValue();
}
-
+
Grocy.Api.Post('stock/products/' + jsonForm.product_id + '/add', jsonData,
function(result)
{
- if ($("#purchase-form").hasAttr("data-used-barcode"))
+ if ($scope("#purchase-form").hasAttr("data-used-barcode"))
{
- Grocy.Api.Put('objects/product_barcodes/' + $("#purchase-form").attr("data-used-barcode"), { last_price: $("#price").val() },
+ Grocy.Api.Put('objects/product_barcodes/' + $scope("#purchase-form").attr("data-used-barcode"), { last_price: $scope("#price").val() },
function(result)
{ },
function(xhr)
{ }
);
}
-
+
if (BoolVal(Grocy.UserSettings.scan_mode_purchase_enabled))
{
Grocy.UISound.Success();
}
-
+
if (GetUriParam("flow") == "InplaceAddBarcodeToExistingProduct")
{
var jsonDataBarcode = {};
jsonDataBarcode.barcode = GetUriParam("barcode");
jsonDataBarcode.product_id = jsonForm.product_id;
jsonDataBarcode.shopping_location_id = jsonForm.shopping_location_id;
-
+
Grocy.Api.Post('objects/product_barcodes', jsonDataBarcode,
function(result)
{
- $("#flow-info-InplaceAddBarcodeToExistingProduct").addClass("d-none");
- $('#barcode-lookup-disabled-hint').addClass('d-none');
- $('#barcode-lookup-hint').removeClass('d-none');
+ $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"));
},
function(xhr)
@@ -131,14 +131,14 @@
}
);
}
-
+
var amountMessage = parseFloat(jsonForm.amount).toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_amounts });
if (BoolVal(productDetails.product.enable_tare_weight_handling))
{
amountMessage = parseFloat(jsonForm.amount) - parseFloat(productDetails.stock_amount) - parseFloat(productDetails.product.tare_weight);
}
var successMessage = __t('Added %1$s of %2$s to stock', amountMessage + " " + __n(amountMessage, productDetails.quantity_unit_stock.name, productDetails.quantity_unit_stock.name_plural), productDetails.product.name) + '
' + __t("Undo") + '';
-
+
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_LABELPRINTER)
{
if (Grocy.Webhooks.labelprinter !== undefined)
@@ -150,7 +150,7 @@
{
post_data.duedate = __t('DD') + ': ' + result[0].best_before_date
}
-
+
if (jsonForm.print_stock_label > 0)
{
var reps = 1;
@@ -162,7 +162,7 @@
}
}
}
-
+
if (GetUriParam("embedded") !== undefined)
{
window.parent.postMessage(WindowMessageBag("ProductChanged", jsonForm.product_id), Grocy.BaseUrl);
@@ -176,7 +176,7 @@
Grocy.FrontendHelpers.EndUiBusy("purchase-form");
toastr.success(successMessage);
Grocy.Components.ProductPicker.FinishFlow();
-
+
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_BEST_BEFORE_DATE_TRACKING && BoolVal(Grocy.UserSettings.show_warning_on_purchase_when_due_date_is_earlier_than_next))
{
if (moment(jsonData.best_before_date).isBefore(CurrentProductDetails.next_due_date))
@@ -184,14 +184,14 @@
toastr.warning(__t("This is due earlier than already in-stock items"));
}
}
-
+
Grocy.Components.ProductAmountPicker.Reset();
- $("#purchase-form").removeAttr("data-used-barcode");
- $("#display_amount").attr("min", Grocy.DefaultMinAmount);
- $('#display_amount').val(parseFloat(Grocy.UserSettings.stock_default_purchase_amount));
- $(".input-group-productamountpicker").trigger("change");
- $('#price').val('');
- $("#tare-weight-handling-info").addClass("d-none");
+ $scope("#purchase-form").removeAttr("data-used-barcode");
+ $scope("#display_amount").attr("min", Grocy.DefaultMinAmount);
+ $scope('#display_amount').val(parseFloat(Grocy.UserSettings.stock_default_purchase_amount));
+ $scope(".input-group-productamountpicker").trigger("change");
+ $scope('#price').val('');
+ $scope("#tare-weight-handling-info").addClass("d-none");
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_LOCATION_TRACKING)
{
Grocy.Components.LocationPicker.Clear();
@@ -207,12 +207,12 @@
}
Grocy.Components.ProductPicker.GetInputElement().focus();
Grocy.Components.ProductCard.Refresh(jsonForm.product_id);
-
- $('#price-hint').text("");
- var priceTypeUnitPrice = $("#price-type-unit-price");
- var priceTypeUnitPriceLabel = $("[for=" + priceTypeUnitPrice.attr("id") + "]");
+
+ $scope('#price-hint').text("");
+ var priceTypeUnitPrice = $scope("#price-type-unit-price");
+ var priceTypeUnitPriceLabel = $scope("[for=" + priceTypeUnitPrice.attr("id") + "]");
priceTypeUnitPriceLabel.text(__t("Unit price"));
-
+
Grocy.FrontendHelpers.ValidateForm('purchase-form');
}
},
@@ -230,7 +230,7 @@
}
);
});
-
+
if (Grocy.Components.ProductPicker !== undefined)
{
Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
@@ -239,31 +239,31 @@
{
Grocy.UISound.BarcodeScannerBeep();
}
-
- var productId = $(e.target).val();
-
+
+ var productId = $scope(e.target).val();
+
if (productId)
{
Grocy.Components.ProductCard.Refresh(productId);
-
+
Grocy.Api.Get('stock/products/' + productId,
function(productDetails)
{
CurrentProductDetails = productDetails;
-
+
Grocy.Components.ProductAmountPicker.Reload(productDetails.product.id, productDetails.quantity_unit_stock.id);
Grocy.Components.ProductAmountPicker.SetQuantityUnit(productDetails.default_quantity_unit_purchase.id);
- $('#display_amount').val(parseFloat(Grocy.UserSettings.stock_default_purchase_amount));
- $(".input-group-productamountpicker").trigger("change");
-
+ $scope('#display_amount').val(parseFloat(Grocy.UserSettings.stock_default_purchase_amount));
+ $scope(".input-group-productamountpicker").trigger("change");
+
if (GetUriParam("flow") === "shoppinglistitemtostock")
{
Grocy.Components.ProductAmountPicker.SetQuantityUnit(GetUriParam("quId"));
- $('#display_amount').val(parseFloat(GetUriParam("amount") * $("#qu_id option:selected").attr("data-qu-factor")));
+ $scope('#display_amount').val(parseFloat(GetUriParam("amount") * $scope("#qu_id option:selected").attr("data-qu-factor")));
}
-
- $(".input-group-productamountpicker").trigger("change");
-
+
+ $scope(".input-group-productamountpicker").trigger("change");
+
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING)
{
if (productDetails.last_shopping_location_id != null)
@@ -275,48 +275,48 @@
Grocy.Components.ShoppingLocationPicker.SetId(productDetails.default_shopping_location_id);
}
}
-
+
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_LOCATION_TRACKING)
{
Grocy.Components.LocationPicker.SetId(productDetails.location.id);
}
-
+
if (productDetails.last_price == null || productDetails.last_price == 0)
{
- $("#price").val("")
+ $scope("#price").val("")
}
else
{
- $('#price').val(parseFloat(productDetails.last_price / $("#qu_id option:selected").attr("data-qu-factor")));
+ $scope('#price').val(parseFloat(productDetails.last_price / $scope("#qu_id option:selected").attr("data-qu-factor")));
}
-
- var priceTypeUnitPrice = $("#price-type-unit-price");
- var priceTypeUnitPriceLabel = $("[for=" + priceTypeUnitPrice.attr("id") + "]");
- priceTypeUnitPriceLabel.text($("#qu_id option:selected").text() + " " + __t("price"));
-
+
+ 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) / $("#qu_id option:selected").attr("data-qu-factor") + parseFloat(productDetails.stock_amount);
- $("#display_amount").attr("min", minAmount);
- $("#tare-weight-handling-info").removeClass("d-none");
+ 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
{
- $("#display_amount").attr("min", Grocy.DefaultMinAmount);
- $("#tare-weight-handling-info").addClass("d-none");
+ $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 (!$("#datetimepicker-shortcut").is(":checked"))
+ if (!$scope("#datetimepicker-shortcut").is(":checked"))
{
- $("#datetimepicker-shortcut").click();
+ $scope("#datetimepicker-shortcut").click();
}
}
else
@@ -325,32 +325,32 @@
}
}
}
-
+
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_LABELPRINTER)
{
- $("#print_stock_label").val(productDetails.product.default_print_stock_label);
+ $scope("#print_stock_label").val(productDetails.product.default_print_stock_label);
if (productDetails.product.allow_label_per_unit)
{
- if ($('#default_print_stock_label').val() == "2")
+ if ($scope('#default_print_stock_label').val() == "2")
{
- $("#default_print_stock_label").val("0");
+ $scope("#default_print_stock_label").val("0");
}
- $('#label-option-per-unit').prop("disabled", true);
+ $scope('#label-option-per-unit').prop("disabled", true);
}
else
{
- $('#label-option-per-unit').prop("disabled", false);
+ $scope('#label-option-per-unit').prop("disabled", false);
}
}
-
- $("#display_amount").focus();
-
+
+ $scope("#display_amount").focus();
+
Grocy.FrontendHelpers.ValidateForm('purchase-form');
if (GetUriParam("flow") === "shoppinglistitemtostock" && BoolVal(Grocy.UserSettings.shopping_list_to_stock_workflow_auto_submit_when_prefilled) && document.getElementById("purchase-form").checkValidity() === true)
{
- $("#save-purchase-button").click();
+ $scope("#save-purchase-button").click();
}
-
+
RefreshLocaleNumberInput();
var elem = document.getElementById("product_id");
if (elem.getAttribute("barcode") != "null" && !elem.getAttribute("barcode").startsWith("grcy"))
@@ -361,38 +361,38 @@
if (barcodeResult != null)
{
var barcode = barcodeResult[0];
- $("#purchase-form").attr("data-used-barcode", barcode.id);
-
+ $scope("#purchase-form").attr("data-used-barcode", barcode.id);
+
if (barcode != null)
{
if (barcode.amount != null && !barcode.amount.isEmpty())
{
- $("#display_amount").val(barcode.amount);
- $("#display_amount").select();
+ $scope("#display_amount").val(barcode.amount);
+ $scope("#display_amount").select();
}
-
+
if (barcode.qu_id != null)
{
Grocy.Components.ProductAmountPicker.SetQuantityUnit(barcode.qu_id);
}
-
+
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING && barcode.shopping_location_id != null)
{
Grocy.Components.ShoppingLocationPicker.SetId(barcode.shopping_location_id);
}
-
+
if (barcode.last_price != null && !barcode.last_price.isEmpty())
{
- $("#price").val(barcode.last_price);
- $("#price-type-total-price").click();
+ $scope("#price").val(barcode.last_price);
+ $scope("#price-type-total-price").click();
}
-
- $(".input-group-productamountpicker").trigger("change");
+
+ $scope(".input-group-productamountpicker").trigger("change");
Grocy.FrontendHelpers.ValidateForm('purchase-form');
RefreshLocaleNumberInput();
}
}
-
+
Grocy.ScanModeSubmit(false);
},
function(xhr)
@@ -403,11 +403,11 @@
}
else
{
- $("#purchase-form").removeAttr("data-used-barcode");
+ $scope("#purchase-form").removeAttr("data-used-barcode");
Grocy.ScanModeSubmit();
}
-
- $('#display_amount').trigger("keyup");
+
+ $scope('#display_amount').trigger("keyup");
},
function(xhr)
{
@@ -417,12 +417,12 @@
}
});
}
-
- $('#display_amount').val(parseFloat(Grocy.UserSettings.stock_default_purchase_amount));
+
+ $scope('#display_amount').val(parseFloat(Grocy.UserSettings.stock_default_purchase_amount));
RefreshLocaleNumberInput();
- $(".input-group-productamountpicker").trigger("change");
+ $scope(".input-group-productamountpicker").trigger("change");
Grocy.FrontendHelpers.ValidateForm('purchase-form');
-
+
if (Grocy.Components.ProductPicker)
{
if (Grocy.Components.ProductPicker.InAnyFlow() === false && GetUriParam("embedded") === undefined)
@@ -432,15 +432,15 @@
else
{
Grocy.Components.ProductPicker.GetPicker().trigger('change');
-
+
if (Grocy.Components.ProductPicker.InProductModifyWorkflow())
{
Grocy.Components.ProductPicker.GetInputElement().focus();
}
}
}
-
- $('#display_amount').on('focus', function(e)
+
+ $scope('#display_amount').on('focus', function(e)
{
if (Grocy.Components.ProductPicker.GetValue().length === 0)
{
@@ -448,145 +448,147 @@
}
else
{
- $(this).select();
+ $scope(this).select();
}
});
-
- $('#price').on('focus', function(e)
+
+ $scope('#price').on('focus', function(e)
{
- $(this).select();
+ $scope(this).select();
});
-
- $('#purchase-form input').keyup(function(event)
+
+ $scope('#purchase-form input').keyup(function(event)
{
Grocy.FrontendHelpers.ValidateForm('purchase-form');
});
-
- $('#purchase-form input').keydown(function(event)
+
+ $scope('#purchase-form input').keydown(function(event)
{
if (event.keyCode === 13) //Enter
{
event.preventDefault();
-
+
if (document.getElementById('purchase-form').checkValidity() === false) //There is at least one validation error
{
return false;
}
else
{
- $('#save-purchase-button').click();
+ $scope('#save-purchase-button').click();
}
}
});
-
+
if (Grocy.Components.DateTimePicker)
{
Grocy.Components.DateTimePicker.GetInputElement().on('change', function(e)
{
Grocy.FrontendHelpers.ValidateForm('purchase-form');
});
-
+
Grocy.Components.DateTimePicker.GetInputElement().on('keypress', function(e)
{
Grocy.FrontendHelpers.ValidateForm('purchase-form');
});
}
-
+
if (Grocy.Components.DateTimePicker2)
{
Grocy.Components.DateTimePicker2.GetInputElement().on('change', function(e)
{
Grocy.FrontendHelpers.ValidateForm('purchase-form');
});
-
+
Grocy.Components.DateTimePicker2.GetInputElement().on('keypress', function(e)
{
Grocy.FrontendHelpers.ValidateForm('purchase-form');
});
-
+
Grocy.Components.DateTimePicker2.GetInputElement().trigger("input");
}
-
- $('#price').on('keyup', function(e)
+
+ $scope('#price').on('keyup', function(e)
{
refreshPriceHint();
});
-
- $('#price-type-unit-price').on('change', function(e)
+
+ $scope('#price-type-unit-price').on('change', function(e)
{
refreshPriceHint();
});
-
- $('#price-type-total-price').on('change', function(e)
+
+ $scope('#price-type-total-price').on('change', function(e)
{
refreshPriceHint();
});
-
- $('#display_amount').on('change', function(e)
+
+ $scope('#display_amount').on('change', function(e)
{
refreshPriceHint();
Grocy.FrontendHelpers.ValidateForm('purchase-form');
});
-
+
function refreshPriceHint()
{
- if ($('#amount').val() == 0 || $('#price').val() == 0)
+ if ($scope('#amount').val() == 0 || $scope('#price').val() == 0)
{
- $('#price-hint').text("");
+ $scope('#price-hint').text("");
return;
}
-
- if ($("input[name='price-type']:checked").val() == "total-price" || $("#qu_id").attr("data-destination-qu-name") != $("#qu_id option:selected").text())
+
+ if ($scope("input[name='price-type']:checked").val() == "total-price" || $scope("#qu_id").attr("data-destination-qu-name") != $scope("#qu_id option:selected").text())
{
- var amount = $('#display_amount').val();
+ var amount = $scope('#display_amount').val();
if (BoolVal(CurrentProductDetails.product.enable_tare_weight_handling))
{
amount -= parseFloat(CurrentProductDetails.product.tare_weight);
}
-
- var price = parseFloat($('#price').val() * $("#qu_id option:selected").attr("data-qu-factor")).toFixed(Grocy.UserSettings.stock_decimal_places_prices);
- if ($("input[name='price-type']:checked").val() == "total-price")
+
+ var price = parseFloat($scope('#price').val() * $scope("#qu_id option:selected").attr("data-qu-factor")).toFixed(Grocy.UserSettings.stock_decimal_places_prices);
+ if ($scope("input[name='price-type']:checked").val() == "total-price")
{
price = parseFloat(price / amount).toFixed(Grocy.UserSettings.stock_decimal_places_prices);
}
-
- $('#price-hint').text(__t('means %1$s per %2$s', price.toLocaleString(undefined, { style: "currency", currency: Grocy.Currency, minimumFractionDigits: Grocy.UserSettings.stock_decimal_places_prices, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_prices }), $("#qu_id").attr("data-destination-qu-name")));
+
+ $scope('#price-hint').text(__t('means %1$s per %2$s', price.toLocaleString(undefined, { style: "currency", currency: Grocy.Currency, minimumFractionDigits: Grocy.UserSettings.stock_decimal_places_prices, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_prices }), $scope("#qu_id").attr("data-destination-qu-name")));
}
else
{
- $('#price-hint').text("");
+ $scope('#price-hint').text("");
}
}
-
- $("#scan-mode").on("change", function(e)
+
+ $scope("#scan-mode").on("change", function(e)
{
if ($(this).prop("checked"))
{
Grocy.UISound.AskForPermission();
}
});
-
- $("#scan-mode-button").on("click", function(e)
+
+ $scope("#scan-mode-button").on("click", function(e)
{
document.activeElement.blur();
- $("#scan-mode").click();
- $("#scan-mode-button").toggleClass("btn-success").toggleClass("btn-danger");
- if ($("#scan-mode").prop("checked"))
+ $scope("#scan-mode").click();
+ $scope("#scan-mode-button").toggleClass("btn-success").toggleClass("btn-danger");
+ if ($scope("#scan-mode").prop("checked"))
{
- $("#scan-mode-status").text(__t("on"));
+ $scope("#scan-mode-status").text(__t("on"));
}
else
{
- $("#scan-mode-status").text(__t("off"));
+ $scope("#scan-mode-status").text(__t("off"));
}
});
-
- $('#qu_id').on('change', function(e)
+
+ $scope('#qu_id').on('change', function(e)
{
- var priceTypeUnitPrice = $("#price-type-unit-price");
- var priceTypeUnitPriceLabel = $("[for=" + priceTypeUnitPrice.attr("id") + "]");
- priceTypeUnitPriceLabel.text($("#qu_id option:selected").text() + " " + __t("price"));
+ 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();
});
-
+
}
+
+window.purchaseView = purchaseView
\ No newline at end of file
diff --git a/js/viewjs/quantityunitconversionform.js b/js/viewjs/quantityunitconversionform.js
index 083d3cff..0340bfa3 100644
--- a/js/viewjs/quantityunitconversionform.js
+++ b/js/viewjs/quantityunitconversionform.js
@@ -1,4 +1,6 @@
-function quantityunitconversionformView(Grocy, scope = null)
+import { WindowMessageBag } from '../helpers/messagebag';
+
+function quantityunitconversionformView(Grocy, scope = null)
{
var $scope = $;
if (scope != null)
@@ -6,29 +8,27 @@
$scope = $(scope).find;
}
- import { WindowMessageBag } from '../helpers/messagebag';
-
Grocy.Use("numberpicker");
Grocy.Use("userfieldsform");
-
- $('#save-quconversion-button').on('click', function(e)
+
+ $scope('#save-quconversion-button').on('click', function(e)
{
e.preventDefault();
-
- if ($(".combobox-menu-visible").length)
+
+ if ($scope(".combobox-menu-visible").length)
{
return;
}
-
- var jsonData = $('#quconversion-form').serializeJSON();
- jsonData.from_qu_id = $("#from_qu_id").val();
+
+ var jsonData = $scope('#quconversion-form').serializeJSON();
+ jsonData.from_qu_id = $scope("#from_qu_id").val();
Grocy.FrontendHelpers.BeginUiBusy("quconversion-form");
- if ($("#create_inverse").is(":checked"))
+ if ($scope("#create_inverse").is(":checked"))
{
- var inverse_to_qu_id = $("#from_qu_id").val();
- var inverse_from_qu_id = $("#to_qu_id").val();
+ var inverse_to_qu_id = $scope("#from_qu_id").val();
+ var inverse_from_qu_id = $scope("#to_qu_id").val();
}
-
+
if (Grocy.EditMode === 'create')
{
Grocy.Api.Post('objects/quantity_unit_conversions', jsonData,
@@ -37,12 +37,12 @@
Grocy.EditObjectId = result.created_object_id;
Grocy.Components.UserfieldsForm.Save(function()
{
- if ($("#create_inverse").is(":checked"))
+ if ($scope("#create_inverse").is(":checked"))
{
jsonData.to_qu_id = inverse_to_qu_id;
jsonData.from_qu_id = inverse_from_qu_id;
jsonData.factor = 1 / jsonData.factor;
-
+
//Create Inverse
Grocy.Api.Post('objects/quantity_unit_conversions', jsonData,
function(result)
@@ -136,88 +136,90 @@
);
}
});
-
- $('#quconversion-form input').keyup(function(event)
+
+ $scope('#quconversion-form input').keyup(function(event)
{
- $('.input-group-qu').trigger('change');
+ $scope('.input-group-qu').trigger('change');
Grocy.FrontendHelpers.ValidateForm('quconversion-form');
});
-
- $('#quconversion-form input').keydown(function(event)
+
+ $scope('#quconversion-form input').keydown(function(event)
{
if (event.keyCode === 13) //Enter
{
event.preventDefault();
-
+
if (document.getElementById('quconversion-form').checkValidity() === false) //There is at least one validation error
{
return false;
}
else
{
- $('#save-quconversion-button').click();
+ $scope('#save-quconversion-button').click();
}
}
});
-
- $("#create_inverse").on("change", function()
+
+ $scope("#create_inverse").on("change", function()
{
var value = $(this).is(":checked");
-
+
if (value)
{
- $('#qu-conversion-inverse-info').removeClass('d-none');
+ $scope('#qu-conversion-inverse-info').removeClass('d-none');
}
else
{
- $('#qu-conversion-inverse-info').addClass('d-none');
+ $scope('#qu-conversion-inverse-info').addClass('d-none');
}
});
-
- $('.input-group-qu').on('change', function(e)
+
+ $scope('.input-group-qu').on('change', function(e)
{
- var fromQuId = $("#from_qu_id").val();
- var toQuId = $("#to_qu_id").val();
- var factor = $('#factor').val();
-
+ var fromQuId = $scope("#from_qu_id").val();
+ var toQuId = $scope("#to_qu_id").val();
+ var factor = $scope('#factor').val();
+
if (fromQuId == toQuId)
{
- $("#to_qu_id").parent().find(".invalid-feedback").text(__t('This cannot be equal to %s', $("#from_qu_id option:selected").text()));
- $("#to_qu_id")[0].setCustomValidity("error");
+ $scope("#to_qu_id").parent().find(".invalid-feedback").text(__t('This cannot be equal to %s', $scope("#from_qu_id option:selected").text()));
+ $scope("#to_qu_id")[0].setCustomValidity("error");
}
else
{
- $("#to_qu_id")[0].setCustomValidity("");
+ $scope("#to_qu_id")[0].setCustomValidity("");
}
-
+
if (fromQuId && toQuId)
{
- $('#qu-conversion-info').text(__t('This means 1 %1$s is the same as %2$s %3$s', $("#from_qu_id option:selected").text(), parseFloat((1 * factor)).toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_amounts }), __n((1 * factor).toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_amounts }), $("#to_qu_id option:selected").text(), $("#to_qu_id option:selected").data("plural-form"))));
- $('#qu-conversion-info').removeClass('d-none');
-
+ $scope('#qu-conversion-info').text(__t('This means 1 %1$s is the same as %2$s %3$s', $scope("#from_qu_id option:selected").text(), parseFloat((1 * factor)).toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_amounts }), __n((1 * factor).toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_amounts }), $scope("#to_qu_id option:selected").text(), $scope("#to_qu_id option:selected").data("plural-form"))));
+ $scope('#qu-conversion-info').removeClass('d-none');
+
if (Grocy.EditMode === 'create')
{
- $('#qu-conversion-inverse-info').text(__t('This means 1 %1$s is the same as %2$s %3$s', $("#to_qu_id option:selected").text(), parseFloat((1 / factor)).toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_amounts }), __n((1 / factor).toString(), $("#from_qu_id option:selected").text(), $("#from_qu_id option:selected").data("plural-form"))));
- $('#qu-conversion-inverse-info').removeClass('d-none');
+ $scope('#qu-conversion-inverse-info').text(__t('This means 1 %1$s is the same as %2$s %3$s', $scope("#to_qu_id option:selected").text(), parseFloat((1 / factor)).toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_amounts }), __n((1 / factor).toString(), $scope("#from_qu_id option:selected").text(), $scope("#from_qu_id option:selected").data("plural-form"))));
+ $scope('#qu-conversion-inverse-info').removeClass('d-none');
}
}
else
{
- $('#qu-conversion-info').addClass('d-none');
- $('#qu-conversion-inverse-info').addClass('d-none');
+ $scope('#qu-conversion-info').addClass('d-none');
+ $scope('#qu-conversion-inverse-info').addClass('d-none');
}
-
+
Grocy.FrontendHelpers.ValidateForm('quconversion-form');
});
-
+
Grocy.Components.UserfieldsForm.Load();
- $('.input-group-qu').trigger('change');
- $('#from_qu_id').focus();
+ $scope('.input-group-qu').trigger('change');
+ $scope('#from_qu_id').focus();
Grocy.FrontendHelpers.ValidateForm('quconversion-form');
-
+
if (GetUriParam("qu-unit") !== undefined)
{
- $("#from_qu_id").attr("disabled", "");
+ $scope("#from_qu_id").attr("disabled", "");
}
-
+
}
+
+window.quantityunitconversionformView = quantityunitconversionformView
diff --git a/js/viewjs/quantityunitform.js b/js/viewjs/quantityunitform.js
index 9a478ea6..688023b4 100644
--- a/js/viewjs/quantityunitform.js
+++ b/js/viewjs/quantityunitform.js
@@ -7,27 +7,27 @@
}
import { WindowMessageBag } from '../helpers/messagebag';
-
+
Grocy.Use("userfieldsform");
-
- $('.save-quantityunit-button').on('click', function(e)
+
+ $scope('.save-quantityunit-button').on('click', function(e)
{
e.preventDefault();
-
- var jsonData = $('#quantityunit-form').serializeJSON();
+
+ var jsonData = $scope('#quantityunit-form').serializeJSON();
Grocy.FrontendHelpers.BeginUiBusy("quantityunit-form");
-
+
var redirectDestination = U('/quantityunits');
if (Grocy.QuantityUnitEditFormRedirectUri !== undefined)
{
redirectDestination = Grocy.QuantityUnitEditFormRedirectUri;
}
-
- if ($(e.currentTarget).attr('data-location') == "continue")
+
+ if ($scope(e.currentTarget).attr('data-location') == "continue")
{
redirectDestination = "reload";
}
-
+
if (Grocy.EditMode === 'create')
{
Grocy.Api.Post('objects/quantity_units', jsonData,
@@ -42,7 +42,7 @@
}
else
{
-
+
if (redirectDestination == "reload")
{
window.location.href = U("/quantityunit/" + result.created_object_id.toString());
@@ -78,7 +78,7 @@
}
else
{
-
+
if (redirectDestination == "reload")
{
window.location.reload();
@@ -102,62 +102,62 @@
);
}
});
-
- $('#quantityunit-form input').keyup(function(event)
+
+ $scope('#quantityunit-form input').keyup(function(event)
{
- if (!$("#name").val().isEmpty())
+ if (!$scope("#name").val().isEmpty())
{
- $("#qu-conversion-headline-info").text(__t('1 %s is the same as...', $("#name").val()));
+ $scope("#qu-conversion-headline-info").text(__t('1 %s is the same as...', $scope("#name").val()));
}
else
{
- $("#qu-conversion-headline-info").text("");
+ $scope("#qu-conversion-headline-info").text("");
}
-
- if (document.getElementById('quantityunit-form').checkValidity() === false) //There is at least one validation error
+
+ if ($scope('quantityunit-form')[0].checkValidity() === false) //There is at least one validation error
{
- $("#qu-conversion-add-button").addClass("disabled");
+ $scope("#qu-conversion-add-button").addClass("disabled");
}
else
{
- $("#qu-conversion-add-button").removeClass("disabled");
+ $scope("#qu-conversion-add-button").removeClass("disabled");
}
-
+
Grocy.FrontendHelpers.ValidateForm('quantityunit-form');
});
-
- $('#quantityunit-form input').keydown(function(event)
+
+ $scope('#quantityunit-form input').keydown(function(event)
{
if (event.keyCode === 13) //Enter
{
event.preventDefault();
-
- if (document.getElementById('quantityunit-form').checkValidity() === false) //There is at least one validation error
+
+ if ($scope('quantityunit-form')[0].checkValidity() === false) //There is at least one validation error
{
return false;
}
else
{
- $('#save-quantityunit-button').click();
+ $scope('#save-quantityunit-button').click();
}
}
});
-
- var quConversionsTable = $('#qu-conversions-table').DataTable({
+
+ var quConversionsTable = $scope('#qu-conversions-table').DataTable({
'order': [[1, 'asc']],
'columnDefs': [
{ 'orderable': false, 'targets': 0 },
{ 'searchable': false, "targets": 0 }
].concat($.fn.dataTable.defaults.columnDefs)
});
- $('#qu-conversions-table tbody').removeClass("d-none");
+ $scope('#qu-conversions-table tbody').removeClass("d-none");
quConversionsTable.columns.adjust().draw();
-
+
Grocy.Components.UserfieldsForm.Load();
- $("#name").trigger("keyup");
- $('#name').focus();
+ $scope("#name").trigger("keyup");
+ $scope('#name').focus();
Grocy.FrontendHelpers.ValidateForm('quantityunit-form');
-
+
Grocy.FrontendHelpers.MakeDeleteConfirmBox(
'Are you sure to remove this conversion?',
'.qu-conversion-delete-button',
@@ -166,14 +166,15 @@
'objects/quantity_unit_conversions/',
() => window.location.reload(),
);
-
- $("#test-quantityunit-plural-forms-button").on("click", function(e)
+
+ // TODO: LoadSubView
+ $scope("#test-quantityunit-plural-forms-button").on("click", function(e)
{
e.preventDefault();
-
+
Grocy.QuantityUnitEditFormRedirectUri = "stay";
- $("#save-quantityunit-button").click();
-
+ $scope("#save-quantityunit-button").click();
+
bootbox.alert({
message: '',
closeButton: false,
@@ -185,5 +186,5 @@
}
});
});
-
+
}
diff --git a/js/viewjs/quantityunitpluraltesting.js b/js/viewjs/quantityunitpluraltesting.js
index cc8338b4..87b4d892 100644
--- a/js/viewjs/quantityunitpluraltesting.js
+++ b/js/viewjs/quantityunitpluraltesting.js
@@ -7,43 +7,43 @@
}
Grocy.Use("numberpicker");
-
- $("#qu_id").change(function(event)
+
+ $scope("#qu_id").change(function(event)
{
RefreshQuPluralTestingResult();
});
-
- $("#amount").keyup(function(event)
+
+ $scope("#amount").keyup(function(event)
{
RefreshQuPluralTestingResult();
});
-
- $("#amount").change(function(event)
+
+ $scope("#amount").change(function(event)
{
RefreshQuPluralTestingResult();
});
-
+
function RefreshQuPluralTestingResult()
{
- var singularForm = $("#qu_id option:selected").data("singular-form");
- var pluralForm = $("#qu_id option:selected").data("plural-form");
- var amount = $("#amount").val();
-
+ var singularForm = $scope("#qu_id option:selected").data("singular-form");
+ var pluralForm = $scope("#qu_id option:selected").data("plural-form");
+ var amount = $scope("#amount").val();
+
if (singularForm.toString().isEmpty() || amount.toString().isEmpty())
{
return;
}
-
+
animateCSS("h2", "shake");
- $("#result").text(__n(amount, singularForm, pluralForm));
+ $scope("#result").text(__n(amount, singularForm, pluralForm));
}
-
+
if (GetUriParam("qu") !== undefined)
{
- $("#qu_id").val(GetUriParam("qu"));
- $("#qu_id").trigger("change");
+ $scope("#qu_id").val(GetUriParam("qu"));
+ $scope("#qu_id").trigger("change");
}
-
- $("#amount").focus();
-
+
+ $scope("#amount").focus();
+
}
diff --git a/js/viewjs/quantityunits.js b/js/viewjs/quantityunits.js
index 8002722a..6ae1abc9 100644
--- a/js/viewjs/quantityunits.js
+++ b/js/viewjs/quantityunits.js
@@ -6,14 +6,14 @@
$scope = $(scope).find;
}
- var quantityUnitsTable = $('#quantityunits-table').DataTable({
+ var quantityUnitsTable = $scope('#quantityunits-table').DataTable({
'order': [[1, 'asc']],
'columnDefs': [
{ 'orderable': false, 'targets': 0 },
{ 'searchable': false, "targets": 0 }
].concat($.fn.dataTable.defaults.columnDefs)
});
- $('#quantityunits-table tbody').removeClass("d-none");
+ $scope('#quantityunits-table tbody').removeClass("d-none");
Grocy.FrontendHelpers.InitDataTable(quantityUnitsTable);
Grocy.FrontendHelpers.MakeDeleteConfirmBox(
'Are you sure to delete quantity unit "%s"?',
diff --git a/js/viewjs/recipeform.js b/js/viewjs/recipeform.js
index ddc08cbd..dda303c3 100644
--- a/js/viewjs/recipeform.js
+++ b/js/viewjs/recipeform.js
@@ -1,17 +1,18 @@
-function recipeformView(Grocy, scope = null)
+import { WindowMessageBag } from '../helpers/messagebag';
+
+function recipeformView(Grocy, scope = null)
{
var $scope = $;
+ var top = scope != null ? $(scope) : $(document);
if (scope != null)
{
$scope = $(scope).find;
}
- import { WindowMessageBag } from '../helpers/messagebag';
-
Grocy.Use("numberpicker");
Grocy.Use("recipepicker");
Grocy.Use("userfieldsform");
-
+
function saveRecipePicture(result, location, jsonData)
{
var recipeId = Grocy.EditObjectId || result.created_object_id;
@@ -19,7 +20,7 @@
{
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($scope("#recipe-picture")[0].files[0], 'recipepictures', jsonData.picture_file_name,
(result) =>
{
window.location.href = U(location + recipeId);
@@ -37,33 +38,33 @@
}
});
}
-
- $('.save-recipe').on('click', function(e)
+
+ $scope('.save-recipe').on('click', function(e)
{
e.preventDefault();
-
- var jsonData = $('#recipe-form').serializeJSON();
+
+ var jsonData = $scope('#recipe-form').serializeJSON();
Grocy.FrontendHelpers.BeginUiBusy("recipe-form");
-
- if ($("#recipe-picture")[0].files.length > 0)
+
+ if ($scope("#recipe-picture")[0].files.length > 0)
{
var someRandomStuff = Math.random().toString(36).substring(2, 100) + Math.random().toString(36).substring(2, 100);
- jsonData.picture_file_name = someRandomStuff + $("#recipe-picture")[0].files[0].name;
+ jsonData.picture_file_name = someRandomStuff + $scope("#recipe-picture")[0].files[0].name;
}
-
- const location = $(e.currentTarget).attr('data-location') == 'return' ? '/recipes?recipe=' : '/recipe/';
-
+
+ const location = $scope(e.currentTarget).attr('data-location') == 'return' ? '/recipes?recipe=' : '/recipe/';
+
if (Grocy.EditMode == 'create')
{
Grocy.Api.Post('objects/recipes', jsonData,
(result) => saveRecipePicture(result, location, jsonData));
return;
}
-
+
if (Grocy.DeleteRecipePictureOnSave)
{
jsonData.picture_file_name = null;
-
+
Grocy.Api.DeleteFile(Grocy.RecipePictureFileName, 'recipepictures', {},
function(result)
{
@@ -76,7 +77,7 @@
}
);
}
-
+
Grocy.Api.Put('objects/recipes/' + Grocy.EditObjectId, jsonData,
(result) => saveRecipePicture(result, location, jsonData),
function(xhr)
@@ -86,8 +87,8 @@
}
);
});
-
- var recipesPosTables = $('#recipes-pos-table').DataTable({
+
+ var recipesPosTables = $scope('#recipes-pos-table').DataTable({
'order': [[1, 'asc']],
"orderFixed": [[4, 'asc']],
'columnDefs': [
@@ -100,44 +101,44 @@
dataSrc: 4
}
});
- $('#recipes-pos-table tbody').removeClass("d-none");
+ $scope('#recipes-pos-table tbody').removeClass("d-none");
recipesPosTables.columns.adjust().draw();
-
- var recipesIncludesTables = $('#recipes-includes-table').DataTable({
+
+ var recipesIncludesTables = $scope('#recipes-includes-table').DataTable({
'order': [[1, 'asc']],
'columnDefs': [
{ 'orderable': false, 'targets': 0 },
{ 'searchable': false, "targets": 0 }
].concat($.fn.dataTable.defaults.columnDefs)
});
- $('#recipes-includes-table tbody').removeClass("d-none");
+ $scope('#recipes-includes-table tbody').removeClass("d-none");
recipesIncludesTables.columns.adjust().draw();
-
+
Grocy.FrontendHelpers.ValidateForm('recipe-form');
- $("#name").focus();
-
- $('#recipe-form input').keyup(function(event)
+ $scope("#name").focus();
+
+ $scope('#recipe-form input').keyup(function(event)
{
Grocy.FrontendHelpers.ValidateForm('recipe-form');
});
-
- $('#recipe-form input').keydown(function(event)
+
+ $scope('#recipe-form input').keydown(function(event)
{
if (event.keyCode === 13) //Enter
{
event.preventDefault();
-
+
if (document.getElementById('recipe-form').checkValidity() === false) //There is at least one validation error
{
return false;
}
else
{
- $('#save-recipe-button').click();
+ $scope('#save-recipe-button').click();
}
}
});
-
+
Grocy.FrontendHelpers.MakeDeleteConfirmBox(
'Are you sure to delete recipe ingredient "%s"?',
'.recipe-pos-delete-button',
@@ -146,7 +147,7 @@
'objects/recipes_pos/',
() => window.postMessage(WindowMessageBag("IngredientsChanged"), Grocy.BaseUrl)
);
-
+
Grocy.FrontendHelpers.MakeDeleteConfirmBox(
'Are you sure to remove the included recipe "%s"?',
'.recipe-include-delete-button',
@@ -155,21 +156,22 @@
'objects/recipes_nesting/',
() => window.postMessage(WindowMessageBag("IngredientsChanged"), Grocy.BaseUrl)
);
-
- $(document).on('click', '.recipe-pos-show-note-button', function(e)
+
+ top.on('click', '.recipe-pos-show-note-button', function(e)
{
var note = $(e.currentTarget).attr('data-recipe-pos-note');
-
+
bootbox.alert(note);
});
-
- $(document).on('click', '.recipe-pos-edit-button', function(e)
+
+ // TODO: LoadSubView
+ top.on('click', '.recipe-pos-edit-button', function(e)
{
e.preventDefault();
-
+
var productId = $(e.currentTarget).attr("data-product-id");
var recipePosId = $(e.currentTarget).attr('data-recipe-pos-id');
-
+
bootbox.dialog({
message: '',
size: 'large',
@@ -187,22 +189,22 @@
}
});
});
-
- $(document).on('click', '.recipe-include-edit-button', function(e)
+
+ top.on('click', '.recipe-include-edit-button', function(e)
{
var id = $(e.currentTarget).attr('data-recipe-include-id');
var recipeId = $(e.currentTarget).attr('data-recipe-included-recipe-id');
var recipeServings = $(e.currentTarget).attr('data-recipe-included-recipe-servings');
-
- Grocy.Api.Put('objects/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(),
+
+ Grocy.Api.Put('objects/recipes/' + Grocy.EditObjectId, $scope('#recipe-form').serializeJSON(),
function(result)
{
- $("#recipe-include-editform-title").text(__t("Edit included recipe"));
- $("#recipe-include-form").data("edit-mode", "edit");
- $("#recipe-include-form").data("recipe-nesting-id", id);
+ $scope("#recipe-include-editform-title").text(__t("Edit included recipe"));
+ $scope("#recipe-include-form").data("edit-mode", "edit");
+ $scope("#recipe-include-form").data("recipe-nesting-id", id);
Grocy.Components.RecipePicker.SetId(recipeId);
- $("#includes_servings").val(recipeServings);
- $("#recipe-include-editform-modal").modal("show");
+ $scope("#includes_servings").val(recipeServings);
+ $scope("#recipe-include-editform-modal").modal("show");
Grocy.FrontendHelpers.ValidateForm("recipe-include-form");
},
function(xhr)
@@ -211,11 +213,11 @@
}
);
});
-
- $("#recipe-pos-add-button").on("click", function(e)
+
+ $scope("#recipe-pos-add-button").on("click", function(e)
{
e.preventDefault();
-
+
bootbox.dialog({
message: '',
size: 'large',
@@ -233,17 +235,17 @@
}
});
});
-
- $("#recipe-include-add-button").on("click", function(e)
+
+ $scope("#recipe-include-add-button").on("click", function(e)
{
- Grocy.Api.Put('objects/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(),
+ Grocy.Api.Put('objects/recipes/' + Grocy.EditObjectId, $scope('#recipe-form').serializeJSON(),
function(result)
{
- $("#recipe-include-editform-title").text(__t("Add included recipe"));
- $("#recipe-include-form").data("edit-mode", "create");
+ $scope("#recipe-include-editform-title").text(__t("Add included recipe"));
+ $scope("#recipe-include-form").data("edit-mode", "create");
Grocy.Components.RecipePicker.Clear();
Grocy.Components.RecipePicker.GetInputElement().focus();
- $("#recipe-include-editform-modal").modal("show");
+ $scope("#recipe-include-editform-modal").modal("show");
Grocy.FrontendHelpers.ValidateForm("recipe-include-form");
},
function(xhr)
@@ -252,29 +254,29 @@
}
);
});
-
- $('#save-recipe-include-button').on('click', function(e)
+
+ $scope('#save-recipe-include-button').on('click', function(e)
{
e.preventDefault();
-
- if ($(".combobox-menu-visible").length)
+
+ if ($scope(".combobox-menu-visible").length)
{
return;
}
-
+
if (document.getElementById("recipe-include-form").checkValidity() === false) //There is at least one validation error
{
return false;
}
-
- var nestingId = $("#recipe-include-form").data("recipe-nesting-id");
- var editMode = $("#recipe-include-form").data("edit-mode");
-
+
+ var nestingId = $scope("#recipe-include-form").data("recipe-nesting-id");
+ var editMode = $scope("#recipe-include-form").data("edit-mode");
+
var jsonData = {};
jsonData.includes_recipe_id = Grocy.Components.RecipePicker.GetValue();
- jsonData.servings = $("#includes_servings").val();
+ jsonData.servings = $scope("#includes_servings").val();
jsonData.recipe_id = Grocy.EditObjectId;
-
+
if (editMode === 'create')
{
Grocy.Api.Post('objects/recipes_nestings', jsonData,
@@ -302,32 +304,32 @@
);
}
});
-
- $("#recipe-picture").on("change", function(e)
+
+ $scope("#recipe-picture").on("change", function(e)
{
- $("#recipe-picture-label").removeClass("d-none");
- $("#recipe-picture-label-none").addClass("d-none");
- $("#delete-current-recipe-picture-on-save-hint").addClass("d-none");
- $("#current-recipe-picture").addClass("d-none");
+ $scope("#recipe-picture-label").removeClass("d-none");
+ $scope("#recipe-picture-label-none").addClass("d-none");
+ $scope("#delete-current-recipe-picture-on-save-hint").addClass("d-none");
+ $scope("#current-recipe-picture").addClass("d-none");
Grocy.DeleteRecipePictureOnSave = false;
});
-
+
Grocy.DeleteRecipePictureOnSave = false;
- $("#delete-current-recipe-picture-button").on("click", function(e)
+ $scope("#delete-current-recipe-picture-button").on("click", function(e)
{
Grocy.DeleteRecipePictureOnSave = true;
- $("#current-recipe-picture").addClass("d-none");
- $("#delete-current-recipe-picture-on-save-hint").removeClass("d-none");
- $("#recipe-picture-label").addClass("d-none");
- $("#recipe-picture-label-none").removeClass("d-none");
+ $scope("#current-recipe-picture").addClass("d-none");
+ $scope("#delete-current-recipe-picture-on-save-hint").removeClass("d-none");
+ $scope("#recipe-picture-label").addClass("d-none");
+ $scope("#recipe-picture-label-none").removeClass("d-none");
});
-
+
Grocy.Components.UserfieldsForm.Load();
-
+
$(window).on("message", function(e)
{
var data = e.originalEvent.data;
-
+
if (data.Message === "IngredientsChanged")
{
Grocy.Api.Put('objects/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(),
@@ -342,5 +344,7 @@
);
}
});
-
+
}
+
+window.recipeformView = recipeformView
\ No newline at end of file
diff --git a/js/viewjs/recipeposform.js b/js/viewjs/recipeposform.js
index 53e67555..6e06144d 100644
--- a/js/viewjs/recipeposform.js
+++ b/js/viewjs/recipeposform.js
@@ -1,4 +1,6 @@
-function recipeposformView(Grocy, scope = null)
+import { WindowMessageBag } from '../helpers/messagebag';
+
+function recipeposformView(Grocy, scope = null)
{
var $scope = $;
if (scope != null)
@@ -6,29 +8,27 @@
$scope = $(scope).find;
}
- import { WindowMessageBag } from '../helpers/messagebag';
-
Grocy.Use("numberpicker");
Grocy.Use("productamountpicker");
Grocy.Use("productcard");
-
+
Grocy.RecipePosFormInitialLoadDone = false;
-
- $('#save-recipe-pos-button').on('click', function(e)
+
+ $scope('#save-recipe-pos-button').on('click', function(e)
{
e.preventDefault();
-
- if ($(".combobox-menu-visible").length)
+
+ if ($scope(".combobox-menu-visible").length)
{
return;
}
-
- var jsonData = $('#recipe-pos-form').serializeJSON();
+
+ var jsonData = $scope('#recipe-pos-form').serializeJSON();
jsonData.recipe_id = Grocy.EditObjectParentId;
delete jsonData.display_amount;
-
+
Grocy.FrontendHelpers.BeginUiBusy("recipe-pos-form");
-
+
if (Grocy.EditMode === 'create')
{
Grocy.Api.Post('objects/recipes_pos', jsonData,
@@ -60,15 +60,15 @@
);
}
});
-
+
Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
{
- var productId = $(e.target).val();
-
+ var productId = $scope(e.target).val();
+
if (productId)
{
Grocy.Components.ProductCard.Refresh(productId);
-
+
Grocy.Api.Get('stock/products/' + productId,
function(productDetails)
{
@@ -80,18 +80,18 @@
{
Grocy.Components.ProductAmountPicker.Reload(productDetails.product.id, productDetails.quantity_unit_stock.id);
}
-
+
if (Grocy.Mode == "create")
{
- $("#not_check_stock_fulfillment").prop("checked", productDetails.product.not_check_stock_fulfillment_for_recipes == 1);
+ $scope("#not_check_stock_fulfillment").prop("checked", productDetails.product.not_check_stock_fulfillment_for_recipes == 1);
}
-
- if (!$("#only_check_single_unit_in_stock").prop("checked") && Grocy.RecipePosFormInitialLoadDone)
+
+ if (!$scope("#only_check_single_unit_in_stock").prop("checked") && Grocy.RecipePosFormInitialLoadDone)
{
Grocy.Components.ProductAmountPicker.SetQuantityUnit(productDetails.quantity_unit_stock.id);
}
-
- $('#display_amount').focus();
+
+ $scope('#display_amount').focus();
Grocy.FrontendHelpers.ValidateForm('recipe-pos-form');
Grocy.RecipePosFormInitialLoadDone = true;
},
@@ -102,21 +102,21 @@
);
}
});
-
+
Grocy.FrontendHelpers.ValidateForm('recipe-pos-form');
-
+
if (Grocy.Components.ProductPicker.InProductAddWorkflow() === false)
{
Grocy.Components.ProductPicker.GetInputElement().focus();
}
Grocy.Components.ProductPicker.GetPicker().trigger('change');
-
+
if (Grocy.EditMode == "create")
{
Grocy.RecipePosFormInitialLoadDone = true;
}
-
- $('#display_amount').on('focus', function(e)
+
+ $scope('#display_amount').on('focus', function(e)
{
if (Grocy.Components.ProductPicker.GetValue().length === 0)
{
@@ -127,54 +127,56 @@
$(this).select();
}
});
-
- $('#recipe-pos-form input').keyup(function(event)
+
+ $scope('#recipe-pos-form input').keyup(function(event)
{
Grocy.FrontendHelpers.ValidateForm('recipe-pos-form');
});
-
- $('#qu_id').change(function(event)
+
+ $scope('#qu_id').change(function(event)
{
Grocy.FrontendHelpers.ValidateForm('recipe-pos-form');
});
-
- $('#recipe-pos-form input').keydown(function(event)
+
+ $scope('#recipe-pos-form input').keydown(function(event)
{
if (event.keyCode === 13) //Enter
{
event.preventDefault();
-
+
if (document.getElementById('recipe-pos-form').checkValidity() === false) //There is at least one validation error
{
return false;
}
else
{
- $('#save-recipe-pos-button').click();
+ $scope('#save-recipe-pos-button').click();
}
}
});
-
- $("#only_check_single_unit_in_stock").on("change", function()
+
+ $scope("#only_check_single_unit_in_stock").on("change", function()
{
if (this.checked)
{
- $("#display_amount").attr("min", Grocy.DefaultMinAmount);
+ $scope("#display_amount").attr("min", Grocy.DefaultMinAmount);
Grocy.Components.ProductAmountPicker.AllowAnyQu(true);
Grocy.FrontendHelpers.ValidateForm("recipe-pos-form");
}
else
{
- $("#display_amount").attr("min", "0");
+ $scope("#display_amount").attr("min", "0");
Grocy.Components.ProductPicker.GetPicker().trigger("change"); // Selects the default quantity unit of the selected product
Grocy.Components.ProductAmountPicker.AllowAnyQuEnabled = false;
Grocy.FrontendHelpers.ValidateForm("recipe-pos-form");
}
});
-
- if ($("#only_check_single_unit_in_stock").prop("checked"))
+
+ if ($scope("#only_check_single_unit_in_stock").prop("checked"))
{
Grocy.Components.ProductAmountPicker.AllowAnyQu(true);
}
-
+
}
+
+window.recipeposformView = recipeposformView
\ No newline at end of file
diff --git a/js/viewjs/recipes.js b/js/viewjs/recipes.js
index ebd242d5..b2d64467 100644
--- a/js/viewjs/recipes.js
+++ b/js/viewjs/recipes.js
@@ -1,14 +1,16 @@
function recipesView(Grocy, scope = null)
{
var $scope = $;
+ var viewport = scope != null ? $(scope) : $(window);
+ var top = scope != null ? $(scope) : $(document)
if (scope != null)
{
$scope = $(scope).find;
}
Grocy.Use("numberpicker");
-
- var recipesTables = $('#recipes-table').DataTable({
+
+ var recipesTables = $scope('#recipes-table').DataTable({
'order': [[1, 'asc']],
'columnDefs': [
{ 'orderable': false, 'targets': 0 },
@@ -24,91 +26,91 @@
this.api().row({ order: 'current' }, 0).select();
}
});
- $('#recipes-table tbody').removeClass("d-none");
- Grocy.FrontendHelpers.InitDataTable(recipesTables,
+ $scope('#recipes-table tbody').removeClass("d-none");
+ Grocy.FrontendHelpers.InitDataTable(recipesTables, $scope,
function()
{
var value = $(this).val();
-
+
recipesTables.search(value).draw();
-
- $(".recipe-gallery-item").removeClass("d-none");
-
- $(".recipe-gallery-item .card-title:not(:contains_case_insensitive(" + value + "))").parent().parent().parent().addClass("d-none");
+
+ $scope(".recipe-gallery-item").removeClass("d-none");
+
+ $scope(".recipe-gallery-item .card-title:not(:contains_case_insensitive(" + value + "))").parent().parent().parent().addClass("d-none");
},
function() // custom status filter below
{
- $("#search").val("");
- $("#status-filter").val("all");
- $("#search").trigger("keyup");
- $("#status-filter").trigger("change");
+ $scope("#search").val("");
+ $scope("#status-filter").val("all");
+ $scope("#search").trigger("keyup");
+ $scope("#status-filter").trigger("change");
})
-
+
if ((typeof GetUriParam("tab") !== "undefined" && GetUriParam("tab") === "gallery") || window.localStorage.getItem("recipes_last_tab_id") == "gallery-tab")
{
- $(".nav-tabs a[href='#gallery']").tab("show");
+ $scope(".nav-tabs a[href='#gallery']").tab("show");
}
-
+
var recipe = GetUriParam("recipe");
if (typeof recipe !== "undefined")
{
- $("#recipes-table tr").removeClass("selected");
+ $scope("#recipes-table tr").removeClass("selected");
var rowId = "#recipe-row-" + recipe;
- $(rowId).addClass("selected")
-
+ $scope(rowId).addClass("selected")
+
var cardId = "#RecipeGalleryCard-" + recipe;
- $(cardId).addClass("border-primary");
-
- if ($(window).width() < 768)
+ $scope(cardId).addClass("border-primary");
+
+ if (viewport.width() < 768)
{
// Scroll to recipe card on mobile
- $("#selectedRecipeCard")[0].scrollIntoView();
+ $scope("#selectedRecipeCard")[0].scrollIntoView();
}
}
-
+
if (GetUriParam("search") !== undefined)
{
- $("#search").val(GetUriParam("search"));
+ $scope("#search").val(GetUriParam("search"));
setTimeout(function()
{
- $("#search").keyup();
+ $scope("#search").keyup();
}, 50);
}
-
- $("a[data-toggle='tab']").on("shown.bs.tab", function(e)
+
+ $scope("a[data-toggle='tab']").on("shown.bs.tab", function(e)
{
var tabId = $(e.target).attr("id");
window.localStorage.setItem("recipes_last_tab_id", tabId);
});
-
- $("#status-filter").on("change", function()
+
+ $scope("#status-filter").on("change", function()
{
var value = $(this).val();
if (value === "all")
{
value = "";
}
-
+
recipesTables.column(5).search(value).draw();
-
- $('.recipe-gallery-item').removeClass('d-none');
+
+ $scope('.recipe-gallery-item').removeClass('d-none');
if (value !== "")
{
if (value === 'Xenoughinstock')
{
- $('.recipe-gallery-item').not('.recipe-enoughinstock').addClass('d-none');
+ $scope('.recipe-gallery-item').not('.recipe-enoughinstock').addClass('d-none');
}
else if (value === 'enoughinstockwithshoppinglist')
{
- $('.recipe-gallery-item').not('.recipe-enoughinstockwithshoppinglist').addClass('d-none');
+ $scope('.recipe-gallery-item').not('.recipe-enoughinstockwithshoppinglist').addClass('d-none');
}
if (value === 'notenoughinstock')
{
- $('.recipe-gallery-item').not('.recipe-notenoughinstock').addClass('d-none');
+ $scope('.recipe-gallery-item').not('.recipe-notenoughinstock').addClass('d-none');
}
}
});
-
+
Grocy.FrontendHelpers.MakeDeleteConfirmBox(
'Are you sure to delete recipe "%s"?',
'.recipe-delete',
@@ -117,7 +119,7 @@
'objects/recipes/',
'/recipes'
);
-
+
Grocy.FrontendHelpers.MakeYesNoBox(
(e) =>
{
@@ -126,7 +128,7 @@
"
" +
__t("Uncheck ingredients to not put them on the shopping list") +
":" +
- $("#missing-recipe-pos-list")[0].outerHTML.replace("d-none", "");
+ $scope("#missing-recipe-pos-list")[0].outerHTML.replace("d-none", "");
},
'.recipe-shopping-list',
(result, e) =>
@@ -135,13 +137,13 @@
if (result === true)
{
Grocy.FrontendHelpers.BeginUiBusy();
-
+
var excludedProductIds = new Array();
- $(".missing-recipe-pos-product-checkbox:checkbox:not(:checked)").each(function()
+ $scope(".missing-recipe-pos-product-checkbox:checkbox:not(:checked)").each(function()
{
excludedProductIds.push($(this).data("product-id"));
});
-
+
Grocy.Api.Post('recipes/' + objectId + '/add-not-fulfilled-products-to-shoppinglist', { "excludedProductIds": excludedProductIds },
function(result)
{
@@ -156,7 +158,7 @@
}
}
);
-
+
Grocy.FrontendHelpers.MakeYesNoBox(
(e) =>
{
@@ -172,7 +174,7 @@
if (result === true)
{
Grocy.FrontendHelpers.BeginUiBusy();
-
+
Grocy.Api.Post('recipes/' + objectId + '/consume', {},
function(result)
{
@@ -189,12 +191,12 @@
}
}
);
-
+
recipesTables.on('select', function(e, dt, type, indexes)
{
if (type === 'row')
{
- var selectedRecipeId = $(recipesTables.row(indexes[0]).node()).data("recipe-id");
+ var selectedRecipeId = $scope(recipesTables.row(indexes[0]).node()).data("recipe-id");
var currentRecipeId = window.location.search.split('recipe=')[1];
if (selectedRecipeId.toString() !== currentRecipeId)
{
@@ -202,24 +204,24 @@
}
}
});
-
- $(".recipe-gallery-item").on("click", function(e)
+
+ $scope(".recipe-gallery-item").on("click", function(e)
{
e.preventDefault();
-
+
window.location.href = U('/recipes?tab=gallery&recipe=' + $(this).data("recipe-id"));
});
-
- $(".recipe-fullscreen").on('click', function(e)
+
+ $scope(".recipe-fullscreen").on('click', function(e)
{
e.preventDefault();
-
- $("#selectedRecipeCard").toggleClass("fullscreen");
- $("body").toggleClass("fullscreen-card");
- $("#selectedRecipeCard .card-header").toggleClass("fixed-top");
- $("#selectedRecipeCard .card-body").toggleClass("mt-5");
-
- if ($("body").hasClass("fullscreen-card"))
+
+ $scope("#selectedRecipeCard").toggleClass("fullscreen");
+ $scope("body").toggleClass("fullscreen-card");
+ $scope("#selectedRecipeCard .card-header").toggleClass("fixed-top");
+ $scope("#selectedRecipeCard .card-body").toggleClass("mt-5");
+
+ if ($scope("body").hasClass("fullscreen-card"))
{
window.location.hash = "#fullscreen";
}
@@ -228,25 +230,25 @@
window.history.replaceState(null, null, " ");
}
});
-
- $(".recipe-print").on('click', function(e)
+
+ $scope(".recipe-print").on('click', function(e)
{
e.preventDefault();
-
- $("#selectedRecipeCard").removeClass("fullscreen");
- $("body").removeClass("fullscreen-card");
- $("#selectedRecipeCard .card-header").removeClass("fixed-top");
- $("#selectedRecipeCard .card-body").removeClass("mt-5");
-
+
+ $scope("#selectedRecipeCard").removeClass("fullscreen");
+ $scope("body").removeClass("fullscreen-card");
+ $scope("#selectedRecipeCard .card-header").removeClass("fixed-top");
+ $scope("#selectedRecipeCard .card-body").removeClass("mt-5");
+
window.history.replaceState(null, null, " ");
window.print();
});
-
- $('#servings-scale').keyup(function(event)
+
+ $scope('#servings-scale').keyup(function(event)
{
var data = {};
data.desired_servings = $(this).val();
-
+
Grocy.Api.Put('objects/recipes/' + $(this).data("recipe-id"), data,
function(result)
{
@@ -258,20 +260,20 @@
}
);
});
-
- $(document).on("click", ".missing-recipe-pos-select-button", function(e)
+
+ top.on("click", ".missing-recipe-pos-select-button", function(e)
{
e.preventDefault();
-
+
var checkbox = $(this).find(".form-check-input");
checkbox.prop("checked", !checkbox.prop("checked"));
-
+
$(this).toggleClass("list-group-item-primary");
});
-
+
if (window.location.hash === "#fullscreen")
{
- $("#selectedRecipeToggleFullscreenButton").click();
+ $scope("#selectedRecipeToggleFullscreenButton").click();
}
-
+
}
diff --git a/js/viewjs/recipessettings.js b/js/viewjs/recipessettings.js
index 435d78c6..540b7ec8 100644
--- a/js/viewjs/recipessettings.js
+++ b/js/viewjs/recipessettings.js
@@ -1,4 +1,6 @@
-function recipessettingsView(Grocy, scope = null)
+import { BoolVal } from '../helpers/extensions';
+
+function recipessettingsView(Grocy, scope = null)
{
var $scope = $;
if (scope != null)
@@ -6,13 +8,13 @@
$scope = $(scope).find;
}
- import { BoolVal } from '../helpers/extensions';
-
if (BoolVal(Grocy.UserSettings.recipe_ingredients_group_by_product_group))
{
- $("#recipe_ingredients_group_by_product_group").prop("checked", true);
+ $scope("#recipe_ingredients_group_by_product_group").prop("checked", true);
}
-
+
RefreshLocaleNumberInput();
-
+
}
+
+window.recipessettingsView = recipessettingsView
\ No newline at end of file
diff --git a/js/viewjs/shoppinglist.js b/js/viewjs/shoppinglist.js
index d0f67acb..2340b1de 100644
--- a/js/viewjs/shoppinglist.js
+++ b/js/viewjs/shoppinglist.js
@@ -1,20 +1,24 @@
-function shoppinglistView(Grocy, scope = null)
+
+// this needs to be explicitly imported for some reason,
+// otherwise rollup complains.
+import bwipjs from '../../node_modules/bwip-js/dist/bwip-js.mjs';
+import { WindowMessageBag } from '../helpers/messagebag';
+
+function shoppinglistView(Grocy, scope = null)
{
var $scope = $;
+ var top = scope != null ? $(scope) : top;
+ var viewport = scope != null ? $(scope) : $(window);
+
if (scope != null)
{
$scope = $(scope).find;
}
- // this needs to be explicitly imported for some reason,
- // otherwise rollup complains.
- import bwipjs from '../../node_modules/bwip-js/dist/bwip-js.mjs';
- import { WindowMessageBag } from '../helpers/messagebag';
-
Grocy.Use("calendarcard");
Grocy.Use("productcard");
-
- var shoppingListTable = $('#shoppinglist-table').DataTable({
+
+ var shoppingListTable = $scope('#shoppinglist-table').DataTable({
'order': [[1, 'asc']],
"orderFixed": [[3, 'asc']],
'columnDefs': [
@@ -34,11 +38,11 @@
dataSrc: 3
}
});
- $('#shoppinglist-table tbody').removeClass("d-none");
+ $scope('#shoppinglist-table tbody').removeClass("d-none");
Grocy.FrontendHelpers.InitDataTable(shoppingListTable);
Grocy.FrontendHelpers.MakeStatusFilter(shoppingListTable, 4);
-
- var shoppingListPrintShadowTable = $('#shopping-list-print-shadow-table').DataTable({
+
+ var shoppingListPrintShadowTable = $scope('#shopping-list-print-shadow-table').DataTable({
'order': [[1, 'asc']],
"orderFixed": [[2, 'asc']],
'columnDefs': [
@@ -51,41 +55,41 @@
}
});
Grocy.FrontendHelpers.InitDataTable(shoppingListPrintShadowTable);
-
-
- $("#selected-shopping-list").on("change", function()
+
+
+ $scope("#selected-shopping-list").on("change", function()
{
var value = $(this).val();
window.location.href = U('/shoppinglist?list=' + value);
});
-
+
Grocy.FrontendHelpers.MakeDeleteConfirmBox(
'Are you sure to delete shopping list "%s"?',
'#delete-selected-shopping-list',
- () => $("#selected-shopping-list option:selected").text(),
- () => $("#selected-shopping-list").val(),
+ () => $scope("#selected-shopping-list option:selected").text(),
+ () => $scope("#selected-shopping-list").val(),
'objects/shopping_lists/',
'/shoppinglist'
);
-
- $(document).on('click', '.shoppinglist-delete-button', function(e)
+
+ top.on('click', '.shoppinglist-delete-button', function(e)
{
e.preventDefault();
-
+
// Remove the focus from the current button
// to prevent that the tooltip stays until clicked anywhere else
document.activeElement.blur();
-
+
var shoppingListItemId = $(e.currentTarget).attr('data-shoppinglist-id');
Grocy.FrontendHelpers.BeginUiBusy();
-
+
Grocy.Api.Delete('objects/shopping_list/' + shoppingListItemId, {},
function(result)
{
animateCSS("#shoppinglistitem-" + shoppingListItemId + "-row", "fadeOut", function()
{
Grocy.FrontendHelpers.EndUiBusy();
- $("#shoppinglistitem-" + shoppingListItemId + "-row").remove();
+ $scope("#shoppinglistitem-" + shoppingListItemId + "-row").remove();
OnListItemRemoved();
});
},
@@ -96,22 +100,22 @@
}
);
});
-
- $(document).on("click", ".product-name-cell", function(e)
+
+ top.on("click", ".product-name-cell", function(e)
{
if ($(e.currentTarget).attr("data-product-id") != "")
{
Grocy.Components.ProductCard.Refresh($(e.currentTarget).attr("data-product-id"));
- $("#shoppinglist-productcard-modal").modal("show");
+ $scope("#shoppinglist-productcard-modal").modal("show");
}
});
-
- $(document).on('click', '#add-products-below-min-stock-amount', function(e)
+
+ top.on('click', '#add-products-below-min-stock-amount', function(e)
{
- Grocy.Api.Post('stock/shoppinglist/add-missing-products', { "list_id": $("#selected-shopping-list").val() },
+ Grocy.Api.Post('stock/shoppinglist/add-missing-products', { "list_id": $scope("#selected-shopping-list").val() },
function(result)
{
- window.location.href = U('/shoppinglist?list=' + $("#selected-shopping-list").val());
+ window.location.href = U('/shoppinglist?list=' + $scope("#selected-shopping-list").val());
},
function(xhr)
{
@@ -119,8 +123,8 @@
}
);
});
-
- $(document).on('click', '#add-overdue-expired-products', function(e)
+
+ top.on('click', '#add-overdue-expired-products', function(e)
{
Grocy.Api.Post('stock/shoppinglist/add-overdue-products', { "list_id": $("#selected-shopping-list").val() },
function(result)
@@ -142,23 +146,23 @@
}
);
});
-
+
Grocy.FrontendHelpers.MakeYesNoBox(
- () => __t('Are you sure to empty shopping list "%s"?', $("#selected-shopping-list option:selected").text()),
+ () => __t('Are you sure to empty shopping list "%s"?', $scope("#selected-shopping-list option:selected").text()),
'#clear-shopping-list',
(result) =>
{
if (result === true)
{
Grocy.FrontendHelpers.BeginUiBusy();
-
- Grocy.Api.Post('stock/shoppinglist/clear', { "list_id": $("#selected-shopping-list").val() },
+
+ Grocy.Api.Post('stock/shoppinglist/clear', { "list_id": $scope("#selected-shopping-list").val() },
function(result)
{
animateCSS("#shoppinglist-table tbody tr", "fadeOut", function()
{
Grocy.FrontendHelpers.EndUiBusy();
- $("#shoppinglist-table tbody tr").remove();
+ $scope("#shoppinglist-table tbody tr").remove();
OnListItemRemoved();
});
},
@@ -171,120 +175,120 @@
}
}
);
-
- $(document).on('click', '.shopping-list-stock-add-workflow-list-item-button', function(e)
+
+ top.on('click', '.shopping-list-stock-add-workflow-list-item-button', function(e)
{
e.preventDefault();
-
+
// Remove the focus from the current button
// to prevent that the tooltip stays until clicked anywhere else
document.activeElement.blur();
-
- var href = $(e.currentTarget).attr('href');
-
- $("#shopping-list-stock-add-workflow-purchase-form-frame").attr("src", href);
- $("#shopping-list-stock-add-workflow-modal").modal("show");
-
+
+ var href = $scope(e.currentTarget).attr('href');
+
+ $scope("#shopping-list-stock-add-workflow-purchase-form-frame").attr("src", href);
+ $scope("#shopping-list-stock-add-workflow-modal").modal("show");
+
if (Grocy.ShoppingListToStockWorkflowAll)
{
- $("#shopping-list-stock-add-workflow-purchase-item-count").removeClass("d-none");
- $("#shopping-list-stock-add-workflow-purchase-item-count").text(__t("Adding shopping list item %1$s of %2$s", Grocy.ShoppingListToStockWorkflowCurrent, Grocy.ShoppingListToStockWorkflowCount));
- $("#shopping-list-stock-add-workflow-skip-button").removeClass("d-none");
+ $scope("#shopping-list-stock-add-workflow-purchase-item-count").removeClass("d-none");
+ $scope("#shopping-list-stock-add-workflow-purchase-item-count").text(__t("Adding shopping list item %1$s of %2$s", Grocy.ShoppingListToStockWorkflowCurrent, Grocy.ShoppingListToStockWorkflowCount));
+ $scope("#shopping-list-stock-add-workflow-skip-button").removeClass("d-none");
}
else
{
- $("#shopping-list-stock-add-workflow-skip-button").addClass("d-none");
+ $scope("#shopping-list-stock-add-workflow-skip-button").addClass("d-none");
}
});
-
+
Grocy.ShoppingListToStockWorkflowAll = false;
Grocy.ShoppingListToStockWorkflowCount = 0;
Grocy.ShoppingListToStockWorkflowCurrent = 0;
- $(document).on('click', '#add-all-items-to-stock-button', function(e)
+ top.on('click', '#add-all-items-to-stock-button', function(e)
{
Grocy.ShoppingListToStockWorkflowAll = true;
- Grocy.ShoppingListToStockWorkflowCount = $(".shopping-list-stock-add-workflow-list-item-button").length;
+ Grocy.ShoppingListToStockWorkflowCount = $scope(".shopping-list-stock-add-workflow-list-item-button").length;
Grocy.ShoppingListToStockWorkflowCurrent++;
- $(".shopping-list-stock-add-workflow-list-item-button").first().click();
+ $scope(".shopping-list-stock-add-workflow-list-item-button").first().click();
});
-
- $("#shopping-list-stock-add-workflow-modal").on("hidden.bs.modal", function(e)
+
+ $scope("#shopping-list-stock-add-workflow-modal").on("hidden.bs.modal", function(e)
{
Grocy.ShoppingListToStockWorkflowAll = false;
Grocy.ShoppingListToStockWorkflowCount = 0;
Grocy.ShoppingListToStockWorkflowCurrent = 0;
})
-
+
$(window).on("message", function(e)
{
var data = e.originalEvent.data;
-
+
if (data.Message === "AfterItemAdded")
{
- $(".shoppinglist-delete-button[data-shoppinglist-id='" + data.Payload + "']").click();
+ $scope(".shoppinglist-delete-button[data-shoppinglist-id='" + data.Payload + "']").click();
}
else if (data.Message === "Ready")
{
if (!Grocy.ShoppingListToStockWorkflowAll)
{
- $("#shopping-list-stock-add-workflow-modal").modal("hide");
+ $scope("#shopping-list-stock-add-workflow-modal").modal("hide");
}
else
{
Grocy.ShoppingListToStockWorkflowCurrent++;
if (Grocy.ShoppingListToStockWorkflowCurrent <= Grocy.ShoppingListToStockWorkflowCount)
{
- $(".shopping-list-stock-add-workflow-list-item-button")[Grocy.ShoppingListToStockWorkflowCurrent - 1].click();
+ $scope(".shopping-list-stock-add-workflow-list-item-button")[Grocy.ShoppingListToStockWorkflowCurrent - 1].click();
}
else
{
- $("#shopping-list-stock-add-workflow-modal").modal("hide");
+ $scope("#shopping-list-stock-add-workflow-modal").modal("hide");
}
}
}
});
-
- $(document).on('click', '#shopping-list-stock-add-workflow-skip-button', function(e)
+
+ top.on('click', '#shopping-list-stock-add-workflow-skip-button', function(e)
{
e.preventDefault();
-
+
window.postMessage(WindowMessageBag("Ready"), Grocy.BaseUrl);
});
-
- $(document).on('click', '.order-listitem-button', function(e)
+
+ top.on('click', '.order-listitem-button', function(e)
{
e.preventDefault();
-
+
// Remove the focus from the current button
// to prevent that the tooltip stays until clicked anywhere else
document.activeElement.blur();
-
+
Grocy.FrontendHelpers.BeginUiBusy();
-
+
var listItemId = $(e.currentTarget).attr('data-item-id');
-
+
var done = 1;
if ($(e.currentTarget).attr('data-item-done') == 1)
{
done = 0;
}
-
+
$(e.currentTarget).attr('data-item-done', done);
-
+
Grocy.Api.Put('objects/shopping_list/' + listItemId, { 'done': done },
function()
{
if (done == 1)
{
- $('#shoppinglistitem-' + listItemId + '-row').addClass("text-muted");
- $('#shoppinglistitem-' + listItemId + '-row').addClass("text-strike-through");
+ $scope('#shoppinglistitem-' + listItemId + '-row').addClass("text-muted");
+ $scope('#shoppinglistitem-' + listItemId + '-row').addClass("text-strike-through");
}
else
{
- $('#shoppinglistitem-' + listItemId + '-row').removeClass("text-muted");
- $('#shoppinglistitem-' + listItemId + '-row').removeClass("text-strike-through");
+ $scope('#shoppinglistitem-' + listItemId + '-row').removeClass("text-muted");
+ $scope('#shoppinglistitem-' + listItemId + '-row').removeClass("text-strike-through");
}
-
+
Grocy.FrontendHelpers.EndUiBusy();
},
function(xhr)
@@ -293,9 +297,9 @@
console.error(xhr);
}
);
-
-
- var statusInfoCell = $("#shoppinglistitem-" + listItemId + "-status-info");
+
+
+ var statusInfoCell = $scope("#shoppinglistitem-" + listItemId + "-status-info");
if (done == 1)
{
statusInfoCell.text(statusInfoCell.text().replace("xxUNDONExx", ""));
@@ -305,20 +309,20 @@
statusInfoCell.text(statusInfoCell.text() + " xxUNDONExx");
}
shoppingListTable.rows().invalidate().draw(false);
-
- $("#status-filter").trigger("change");
+
+ $scope("#status-filter").trigger("change");
});
-
+
function OnListItemRemoved()
{
- if ($(".shopping-list-stock-add-workflow-list-item-button").length === 0)
+ if ($scope(".shopping-list-stock-add-workflow-list-item-button").length === 0)
{
- $("#add-all-items-to-stock-button").addClass("disabled");
+ $scope("#add-all-items-to-stock-button").addClass("disabled");
}
}
OnListItemRemoved();
-
- $(document).on("click", "#print-shopping-list-button", function(e)
+
+ top.on("click", "#print-shopping-list-button", function(e)
{
var dialogHtml = ' \
' + __t('Print options') + '
\
@@ -364,7 +368,7 @@
for="print-layout-type-list">' + __t('List') + ' \
\
';
-
+
var sizePrintDialog = 'medium';
var printButtons = {
cancel: {
@@ -381,7 +385,7 @@
callback: function()
{
bootbox.hideAll();
- var printHeader = $("#print-show-header").prop("checked");
+ var printHeader = $scope("#print-show-header").prop("checked");
var thermalPrintDialog = bootbox.dialog({
title: __t('Printing'),
message: '