mirror of
https://github.com/grocy/grocy.git
synced 2026-04-10 06:26:16 +02:00
Only show thermal print button when Feature Flag is set
This commit is contained in:
parent
c58620f898
commit
8e0b995808
|
|
@ -428,72 +428,79 @@ $(document).on("click", "#print-shopping-list-button", function(e)
|
||||||
</label> \
|
</label> \
|
||||||
</div>';
|
</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({
|
bootbox.dialog({
|
||||||
message: dialogHtml,
|
message: dialogHtml,
|
||||||
size: 'medium',
|
size: 'medium',
|
||||||
backdrop: true,
|
backdrop: true,
|
||||||
closeButton: false,
|
closeButton: false,
|
||||||
className: "d-print-none",
|
className: "d-print-none",
|
||||||
buttons: {
|
buttons: 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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,8 @@ class PrintService extends BaseService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialises the printer
|
* Initialises the printer
|
||||||
* @return Printer handle
|
* @return Printer Printer handle
|
||||||
* @throws Exception if unable to connect to printer
|
* @throws Exception If unable to connect to printer, an exception is thrown
|
||||||
*/
|
*/
|
||||||
private static function getPrinterHandle()
|
private static function getPrinterHandle()
|
||||||
{
|
{
|
||||||
|
|
@ -29,8 +29,8 @@ class PrintService extends BaseService
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prints a grocy logo
|
* Prints the grocy logo and date
|
||||||
* @param $printer
|
* @param Printer $printer Printer handle
|
||||||
*/
|
*/
|
||||||
private static function printHeader(Printer $printer)
|
private static function printHeader(Printer $printer)
|
||||||
{
|
{
|
||||||
|
|
@ -48,17 +48,16 @@ class PrintService extends BaseService
|
||||||
$printer->feed(2);
|
$printer->feed(2);
|
||||||
$printer->text($dateFormatted);
|
$printer->text($dateFormatted);
|
||||||
$printer->selectPrintMode();
|
$printer->selectPrintMode();
|
||||||
$printer->feed(3);
|
$printer->feed(2);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param bool $printHeader Printing of Grocy logo
|
* @param bool $printHeader Printing of Grocy logo
|
||||||
* @param string[] $items Items to print
|
* @param string[] $lines Items to print
|
||||||
* @return string[]
|
* @return string[] Returns array with result OK if no exception
|
||||||
* @throws 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();
|
$printer = self::getPrinterHandle();
|
||||||
if ($printer === false)
|
if ($printer === false)
|
||||||
|
|
@ -69,9 +68,9 @@ class PrintService extends BaseService
|
||||||
self::printHeader($printer);
|
self::printHeader($printer);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($items as $item)
|
foreach ($lines as $line)
|
||||||
{
|
{
|
||||||
$printer->text($item);
|
$printer->text($line);
|
||||||
$printer->feed();
|
$printer->feed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user