Only show thermal print button when Feature Flag is set

This commit is contained in:
Marc Ole Bulling 2021-01-15 11:12:30 +01:00
parent c58620f898
commit 8e0b995808
No known key found for this signature in database
GPG Key ID: C126AFC2A47B06FF
2 changed files with 78 additions and 72 deletions

View File

@ -428,72 +428,79 @@ $(document).on("click", "#print-shopping-list-button", function(e)
</label> \
</div>';
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
});
});

View File

@ -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();
}