mirror of
https://github.com/grocy/grocy.git
synced 2025-08-20 12:20:22 +00:00
This commit is contained in:
55
public/viewjs/components/recipepicker.js
Normal file
55
public/viewjs/components/recipepicker.js
Normal file
@@ -0,0 +1,55 @@
|
||||
Grocy.Components.RecipePicker = { };
|
||||
|
||||
Grocy.Components.RecipePicker.GetPicker = function()
|
||||
{
|
||||
return $('#recipe_id');
|
||||
}
|
||||
|
||||
Grocy.Components.RecipePicker.GetInputElement = function()
|
||||
{
|
||||
return $('#recipe_id_text_input');
|
||||
}
|
||||
|
||||
Grocy.Components.RecipePicker.GetValue = function()
|
||||
{
|
||||
return $('#recipe_id').val();
|
||||
}
|
||||
|
||||
Grocy.Components.RecipePicker.SetValue = function(value)
|
||||
{
|
||||
Grocy.Components.RecipePicker.GetInputElement().val(value);
|
||||
Grocy.Components.RecipePicker.GetInputElement().trigger('change');
|
||||
}
|
||||
|
||||
$('.recipe-combobox').combobox({
|
||||
appendId: '_text_input',
|
||||
bsVersion: '4',
|
||||
clearIfNoMatch: true
|
||||
});
|
||||
|
||||
var prefillByName = Grocy.Components.RecipePicker.GetPicker().parent().data('prefill-by-name').toString();
|
||||
if (typeof prefillByName !== "undefined")
|
||||
{
|
||||
possibleOptionElement = $("#recipe_id option:contains('" + prefillByName + "')").first();
|
||||
|
||||
if (possibleOptionElement.length > 0)
|
||||
{
|
||||
$('#recipe_id').val(possibleOptionElement.val());
|
||||
$('#recipe_id').data('combobox').refresh();
|
||||
$('#recipe_id').trigger('change');
|
||||
|
||||
var nextInputElement = $(Grocy.Components.RecipePicker.GetPicker().parent().data('next-input-selector').toString());
|
||||
nextInputElement.focus();
|
||||
}
|
||||
}
|
||||
|
||||
var prefillById = Grocy.Components.RecipePicker.GetPicker().parent().data('prefill-by-id').toString();
|
||||
if (typeof prefillById !== "undefined")
|
||||
{
|
||||
$('#recipe_id').val(prefillById);
|
||||
$('#recipe_id').data('combobox').refresh();
|
||||
$('#recipe_id').trigger('change');
|
||||
|
||||
var nextInputElement = $(Grocy.Components.RecipePicker.GetPicker().parent().data('next-input-selector').toString());
|
||||
nextInputElement.focus();
|
||||
}
|
@@ -21,6 +21,11 @@
|
||||
jsonData.stock_entry_id = jsonForm.specific_stock_entry;
|
||||
}
|
||||
|
||||
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_RECIPES && Grocy.Components.RecipePicker.GetValue().toString().length > 0)
|
||||
{
|
||||
jsonData.recipe_id = Grocy.Components.RecipePicker.GetValue();
|
||||
}
|
||||
|
||||
Grocy.Api.Get('stock/products/' + jsonForm.product_id,
|
||||
function(productDetails)
|
||||
{
|
||||
@@ -38,6 +43,10 @@
|
||||
|
||||
$('#amount').val(1);
|
||||
Grocy.Components.ProductPicker.SetValue('');
|
||||
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_RECIPES)
|
||||
{
|
||||
Grocy.Components.RecipePicker.SetValue('');
|
||||
}
|
||||
Grocy.Components.ProductPicker.GetInputElement().focus();
|
||||
Grocy.FrontendHelpers.ValidateForm('consume-form');
|
||||
},
|
||||
|
Reference in New Issue
Block a user