From d883474f035e9d8c6ad79e50593ac4726f35b59a Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Thu, 25 Aug 2022 18:46:49 +0200 Subject: [PATCH] Fixed LABEL_PRINTER_HOOK_JSON check was missing when running label printer WebHooks client side (fixes #1978) --- changelog/69_UNRELEASED_xxxx-xx-xx.md | 1 + public/js/grocy.js | 26 ++++++++++++++++++++------ views/layout/default.blade.php | 5 +++-- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/changelog/69_UNRELEASED_xxxx-xx-xx.md b/changelog/69_UNRELEASED_xxxx-xx-xx.md index c529c3ae..a885ce33 100644 --- a/changelog/69_UNRELEASED_xxxx-xx-xx.md +++ b/changelog/69_UNRELEASED_xxxx-xx-xx.md @@ -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 ) diff --git a/public/js/grocy.js b/public/js/grocy.js index 5dc6551c..db4ebbd1 100644 --- a/public/js/grocy.js +++ b/public/js/grocy.js @@ -505,14 +505,28 @@ Grocy.FrontendHelpers.RunWebhook = function(webhook, data, repetitions = 1) for (i = 0; i < repetitions; i++) { - $.post(webhook.hook, data).fail(function(req, status, errorThrown) + if (webhook.json) { - if (!hasAlreadyFailed) + $.ajax(webhook.hook, { "data": JSON.stringify(data), "contentType": "application/json", "type": "POST" }).fail(function(req, status, errorThrown) { - hasAlreadyFailed = true; - Grocy.FrontendHelpers.ShowGenericError(__t("Error while executing WebHook", { "status": status, "errorThrown": 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) + { + if (!hasAlreadyFailed) + { + hasAlreadyFailed = true; + Grocy.FrontendHelpers.ShowGenericError(__t("Error while executing WebHook", { "status": status, "errorThrown": errorThrown })); + } + }); + } } } diff --git a/views/layout/default.blade.php b/views/layout/default.blade.php index 9aa078a0..8dd87de3 100644 --- a/views/layout/default.blade.php +++ b/views/layout/default.blade.php @@ -103,8 +103,9 @@ Grocy.Webhooks = { @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) !!} + "hook": "{{ GROCY_LABEL_PRINTER_WEBHOOK }}", + "extra_data": {!! json_encode(GROCY_LABEL_PRINTER_PARAMS) !!}, + "json": {{ BoolToString(GROCY_LABEL_PRINTER_HOOK_JSON) }} } @endif };