Fixed LABEL_PRINTER_HOOK_JSON check was missing when running label printer WebHooks client side (fixes #1978)

This commit is contained in:
Bernd Bestel 2022-08-25 18:46:49 +02:00
parent c396c2a84c
commit d883474f03
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
3 changed files with 24 additions and 8 deletions

View File

@ -57,6 +57,7 @@
### General
- Fixed that when running label printer WebHooks client side (so when `LABEL_PRINTER_RUN_SERVER` = `false`), the setting `LABEL_PRINTER_HOOK_JSON` was ignored (the WebHook data was always sent as form data)
- New translations: (thanks all the translators)
- Lithuanian (demo available at <https://lt.demo.grocy.info>)

View File

@ -504,6 +504,19 @@ Grocy.FrontendHelpers.RunWebhook = function(webhook, data, repetitions = 1)
var hasAlreadyFailed = false;
for (i = 0; i < repetitions; i++)
{
if (webhook.json)
{
$.ajax(webhook.hook, { "data": JSON.stringify(data), "contentType": "application/json", "type": "POST" }).fail(function(req, status, errorThrown)
{
if (!hasAlreadyFailed)
{
hasAlreadyFailed = true;
Grocy.FrontendHelpers.ShowGenericError(__t("Error while executing WebHook", { "status": status, "errorThrown": errorThrown }));
}
});
}
else
{
$.post(webhook.hook, data).fail(function(req, status, errorThrown)
{
@ -515,6 +528,7 @@ Grocy.FrontendHelpers.RunWebhook = function(webhook, data, repetitions = 1)
});
}
}
}
$(document).on("keyup paste change", "input, textarea", function()
{

View File

@ -104,7 +104,8 @@
@if(GROCY_FEATURE_FLAG_LABEL_PRINTER && !GROCY_LABEL_PRINTER_RUN_SERVER)
"labelprinter" : {
"hook": "{{ GROCY_LABEL_PRINTER_WEBHOOK }}",
"extra_data" : {!! json_encode(GROCY_LABEL_PRINTER_PARAMS) !!}
"extra_data": {!! json_encode(GROCY_LABEL_PRINTER_PARAMS) !!},
"json": {{ BoolToString(GROCY_LABEL_PRINTER_HOOK_JSON) }}
}
@endif
};