diff --git a/public/viewjs/shoppinglist.js b/public/viewjs/shoppinglist.js index 142d16bb..98c63e52 100644 --- a/public/viewjs/shoppinglist.js +++ b/public/viewjs/shoppinglist.js @@ -428,72 +428,79 @@ $(document).on("click", "#print-shopping-list-button", function(e) \ '; + var printButtons = { + cancel: { + label: __t('Cancel'), + className: 'btn-secondary', + callback: function() + { + bootbox.hideAll(); + } + }, + printtp: { + label: __t('Thermal printer'), + className: 'btn-secondary', + callback: function() + { + Grocy.Api.Get('print/shoppinglist/thermal', { "list": $("#selected-shopping-list").val(), + "printHeader": $("#print-show-header").prop("checked") }, + function(result) + { + bootbox.hideAll(); + }, + function(xhr) + { + console.error(xhr); + } + ); + } + }, + ok: { + label: __t('Print'), + className: 'btn-primary responsive-button', + callback: function() + { + bootbox.hideAll(); + + $(".print-timestamp").text(moment().format("l LT")); + + $("#description-for-print").html($("#description").val()); + if ($("#description").text().isEmpty()) + { + $("#description-for-print").parent().addClass("d-print-none"); + } + + if (!$("#print-show-header").prop("checked")) + { + $("#print-header").addClass("d-none"); + } + + if (!$("#print-group-by-product-group").prop("checked")) + { + shoppingListPrintShadowTable.rowGroup().enable(false); + shoppingListPrintShadowTable.order.fixed({}); + shoppingListPrintShadowTable.draw(); + } + + $("." + $("input[name='print-layout-type']:checked").val()).removeClass("d-none"); + + window.print(); + } + } + } + + if (!Grocy.FeatureFlags["GROCY_FEATURE_FLAG_THERMAL_PRINTER"]) + { + delete printButtons['printtp']; + } + bootbox.dialog({ message: dialogHtml, size: 'medium', backdrop: true, closeButton: false, className: "d-print-none", - buttons: { - cancel: { - label: __t('Cancel'), - className: 'btn-secondary', - callback: function() - { - bootbox.hideAll(); - } - }, - printtp: { - label: __t('Thermal printer'), - className: 'btn-secondary', - callback: function() - { - Grocy.Api.Get('print/shoppinglist/thermal', { "list": $("#selected-shopping-list").val(), - "printHeader": $("#print-show-header").prop("checked") }, - function(result) - { - bootbox.hideAll(); - }, - function(xhr) - { - console.error(xhr); - } - ); - } - }, - ok: { - label: __t('Print'), - className: 'btn-primary responsive-button', - callback: function() - { - bootbox.hideAll(); - - $(".print-timestamp").text(moment().format("l LT")); - - $("#description-for-print").html($("#description").val()); - if ($("#description").text().isEmpty()) - { - $("#description-for-print").parent().addClass("d-print-none"); - } - - if (!$("#print-show-header").prop("checked")) - { - $("#print-header").addClass("d-none"); - } - - if (!$("#print-group-by-product-group").prop("checked")) - { - shoppingListPrintShadowTable.rowGroup().enable(false); - shoppingListPrintShadowTable.order.fixed({}); - shoppingListPrintShadowTable.draw(); - } - - $("." + $("input[name='print-layout-type']:checked").val()).removeClass("d-none"); - - window.print(); - } - } - } + buttons: printButtons }); }); diff --git a/services/PrintService.php b/services/PrintService.php index 57cae05d..e06183d2 100644 --- a/services/PrintService.php +++ b/services/PrintService.php @@ -14,8 +14,8 @@ class PrintService extends BaseService /** * Initialises the printer - * @return Printer handle - * @throws Exception if unable to connect to printer + * @return Printer Printer handle + * @throws Exception If unable to connect to printer, an exception is thrown */ private static function getPrinterHandle() { @@ -29,8 +29,8 @@ class PrintService extends BaseService /** - * Prints a grocy logo - * @param $printer + * Prints the grocy logo and date + * @param Printer $printer Printer handle */ private static function printHeader(Printer $printer) { @@ -48,17 +48,16 @@ class PrintService extends BaseService $printer->feed(2); $printer->text($dateFormatted); $printer->selectPrintMode(); - $printer->feed(3); - + $printer->feed(2); } /** * @param bool $printHeader Printing of Grocy logo - * @param string[] $items Items to print - * @return string[] - * @throws Exception + * @param string[] $lines Items to print + * @return string[] Returns array with result OK if no exception + * @throws Exception If unable to print, an exception is thrown */ - public function printShoppingList(bool $printHeader, array $items): array + public function printShoppingList(bool $printHeader, array $lines): array { $printer = self::getPrinterHandle(); if ($printer === false) @@ -69,9 +68,9 @@ class PrintService extends BaseService self::printHeader($printer); } - foreach ($items as $item) + foreach ($lines as $line) { - $printer->text($item); + $printer->text($line); $printer->feed(); }