2021-06-18 20:45:42 +02:00
var shoppingListTable = $ ( '#shoppinglist-table' ) . DataTable ( {
2018-07-09 19:27:22 +02:00
'order' : [ [ 1 , 'asc' ] ] ,
'columnDefs' : [
2018-09-24 13:02:52 +02:00
{ 'orderable' : false , 'targets' : 0 } ,
2020-01-03 14:18:56 +01:00
{ 'searchable' : false , "targets" : 0 } ,
2020-12-17 17:33:24 +01:00
{ 'visible' : false , 'targets' : 3 } ,
2020-12-19 17:55:49 +01:00
{ 'visible' : false , 'targets' : 5 } ,
{ 'visible' : false , 'targets' : 6 } ,
2020-12-20 10:26:02 +01:00
{ 'visible' : false , 'targets' : 7 } ,
2020-12-20 19:31:12 +01:00
{ 'visible' : false , 'targets' : 8 } ,
2022-11-12 18:10:32 +01:00
{ "type" : "custom-sort" , "targets" : 2 } ,
2020-12-19 17:55:49 +01:00
{ "type" : "html-num-fmt" , "targets" : 5 } ,
{ "type" : "html-num-fmt" , "targets" : 6 }
2020-12-07 19:48:33 +01:00
] . concat ( $ . fn . dataTable . defaults . columnDefs ) ,
2018-09-24 13:02:52 +02:00
'rowGroup' : {
2020-12-16 18:18:03 +01:00
enable : true ,
2020-12-17 17:41:31 +01:00
dataSrc : 3
2018-09-08 08:56:32 +02:00
}
2018-07-09 19:27:22 +02:00
} ) ;
2019-01-05 20:06:35 +01:00
$ ( '#shoppinglist-table tbody' ) . removeClass ( "d-none" ) ;
2019-03-04 17:43:12 +01:00
shoppingListTable . columns . adjust ( ) . draw ( ) ;
2018-07-09 19:27:22 +02:00
2020-12-19 23:57:33 +01:00
var shoppingListPrintShadowTable = $ ( '#shopping-list-print-shadow-table' ) . DataTable ( {
'order' : [ [ 1 , 'asc' ] ] ,
"orderFixed" : [ [ 2 , 'asc' ] ] ,
'columnDefs' : [
{ 'visible' : false , 'targets' : 2 } ,
{ 'orderable' : false , 'targets' : '_all' }
] . concat ( $ . fn . dataTable . defaults . columnDefs ) ,
'rowGroup' : {
enable : true ,
dataSrc : 2
}
} ) ;
shoppingListPrintShadowTable . columns . adjust ( ) . draw ( ) ;
2019-10-15 19:59:14 +02:00
$ ( "#search" ) . on ( "keyup" , Delay ( function ( )
2018-07-09 19:27:22 +02:00
{
var value = $ ( this ) . val ( ) ;
if ( value === "all" )
{
value = "" ;
}
2019-01-19 00:37:21 -07:00
2018-07-09 19:27:22 +02:00
shoppingListTable . search ( value ) . draw ( ) ;
2019-10-15 19:59:14 +02:00
} , 200 ) ) ;
2018-07-09 19:27:22 +02:00
2020-11-07 14:53:45 +01:00
$ ( "#clear-filter-button" ) . on ( "click" , function ( )
{
$ ( "#search" ) . val ( "" ) ;
$ ( "#status-filter" ) . val ( "all" ) ;
$ ( "#search" ) . trigger ( "keyup" ) ;
$ ( "#status-filter" ) . trigger ( "change" ) ;
} ) ;
2018-09-24 19:13:53 +02:00
$ ( "#status-filter" ) . on ( "change" , function ( )
{
var value = $ ( this ) . val ( ) ;
if ( value === "all" )
{
value = "" ;
}
// Transfer CSS classes of selected element to dropdown element (for background)
$ ( this ) . attr ( "class" , $ ( "#" + $ ( this ) . attr ( "id" ) + " option[value='" + value + "']" ) . attr ( "class" ) + " form-control" ) ;
2019-01-19 00:37:21 -07:00
2021-11-12 18:26:19 +01:00
shoppingListTable . column ( shoppingListTable . colReorder . transpose ( 4 ) ) . search ( value ) . draw ( ) ;
2018-09-24 19:13:53 +02:00
} ) ;
2019-04-20 17:04:40 +02:00
$ ( "#selected-shopping-list" ) . on ( "change" , function ( )
{
var value = $ ( this ) . val ( ) ;
window . location . href = U ( '/shoppinglist?list=' + value ) ;
} ) ;
2020-04-19 08:51:02 -04:00
$ ( ".status-filter-message" ) . on ( "click" , function ( )
2018-09-24 19:13:53 +02:00
{
var value = $ ( this ) . data ( "status-filter" ) ;
$ ( "#status-filter" ) . val ( value ) ;
$ ( "#status-filter" ) . trigger ( "change" ) ;
} ) ;
2019-04-20 17:04:40 +02:00
$ ( "#delete-selected-shopping-list" ) . on ( "click" , function ( )
{
2020-10-14 22:58:26 +02:00
var objectName = $ ( "#selected-shopping-list option:selected" ) . text ( ) ;
2019-04-20 17:04:40 +02:00
var objectId = $ ( "#selected-shopping-list" ) . val ( ) ;
bootbox . confirm ( {
2019-05-01 20:19:18 +02:00
message : _ _t ( 'Are you sure to delete shopping list "%s"?' , objectName ) ,
2019-09-24 10:24:47 +02:00
closeButton : false ,
2019-04-20 17:04:40 +02:00
buttons : {
confirm : {
2019-05-01 20:19:18 +02:00
label : _ _t ( 'Yes' ) ,
2019-04-20 17:04:40 +02:00
className : 'btn-success'
} ,
cancel : {
2019-05-01 20:19:18 +02:00
label : _ _t ( 'No' ) ,
2019-04-20 17:04:40 +02:00
className : 'btn-danger'
}
} ,
2020-08-30 12:18:16 +02:00
callback : function ( result )
2019-04-20 17:04:40 +02:00
{
if ( result === true )
{
Grocy . Api . Delete ( 'objects/shopping_lists/' + objectId , { } ,
2020-08-30 12:18:16 +02:00
function ( result )
2019-04-20 17:04:40 +02:00
{
window . location . href = U ( '/shoppinglist' ) ;
} ,
2020-08-30 12:18:16 +02:00
function ( xhr )
2019-04-20 17:04:40 +02:00
{
console . error ( xhr ) ;
}
) ;
}
}
} ) ;
} ) ;
$ ( document ) . on ( 'click' , '.shoppinglist-delete-button' , function ( e )
2017-04-21 15:36:04 +02:00
{
2018-09-24 09:30:26 +02:00
e . preventDefault ( ) ;
2019-01-19 00:37:21 -07:00
2023-05-03 08:32:49 +02:00
$ ( ".tooltip" ) . tooltip ( "hide" ) ;
2020-04-13 18:26:53 +02:00
2018-08-11 14:07:44 +02:00
var shoppingListItemId = $ ( e . currentTarget ) . attr ( 'data-shoppinglist-id' ) ;
2018-11-24 19:40:50 +01:00
Grocy . FrontendHelpers . BeginUiBusy ( ) ;
2018-08-11 14:07:44 +02:00
2020-08-30 12:18:16 +02:00
Grocy . Api . Delete ( 'objects/shopping_list/' + shoppingListItemId , { } ,
2017-04-21 15:36:04 +02:00
function ( result )
{
2020-01-28 19:27:18 +01:00
animateCSS ( "#shoppinglistitem-" + shoppingListItemId + "-row" , "fadeOut" , function ( )
2018-08-11 14:07:44 +02:00
{
2018-11-24 19:40:50 +01:00
Grocy . FrontendHelpers . EndUiBusy ( ) ;
2020-01-28 19:27:18 +01:00
$ ( "#shoppinglistitem-" + shoppingListItemId + "-row" ) . remove ( ) ;
2018-11-17 14:50:52 +01:00
OnListItemRemoved ( ) ;
2018-08-11 14:07:44 +02:00
} ) ;
2017-04-21 15:36:04 +02:00
} ,
function ( xhr )
{
2018-11-24 19:40:50 +01:00
Grocy . FrontendHelpers . EndUiBusy ( ) ;
2017-04-21 15:36:04 +02:00
console . error ( xhr ) ;
}
) ;
} ) ;
2020-10-20 13:14:11 -05:00
$ ( document ) . on ( "click" , ".product-name-cell" , function ( e )
{
if ( $ ( e . currentTarget ) . attr ( "data-product-id" ) != "" )
{
Grocy . Components . ProductCard . Refresh ( $ ( e . currentTarget ) . attr ( "data-product-id" ) ) ;
$ ( "#shoppinglist-productcard-modal" ) . modal ( "show" ) ;
}
} ) ;
2017-04-21 15:36:04 +02:00
$ ( document ) . on ( 'click' , '#add-products-below-min-stock-amount' , function ( e )
{
2019-04-20 17:04:40 +02:00
Grocy . Api . Post ( 'stock/shoppinglist/add-missing-products' , { "list_id" : $ ( "#selected-shopping-list" ) . val ( ) } ,
2017-04-21 15:36:04 +02:00
function ( result )
{
2019-04-20 17:04:40 +02:00
window . location . href = U ( '/shoppinglist?list=' + $ ( "#selected-shopping-list" ) . val ( ) ) ;
2017-04-21 15:36:04 +02:00
} ,
function ( xhr )
{
console . error ( xhr ) ;
}
) ;
} ) ;
2018-07-15 08:29:26 +02:00
2020-11-15 22:38:21 +01:00
$ ( document ) . on ( 'click' , '#add-overdue-expired-products' , function ( e )
2020-10-04 15:20:34 +02:00
{
2020-11-15 19:53:44 +01:00
Grocy . Api . Post ( 'stock/shoppinglist/add-overdue-products' , { "list_id" : $ ( "#selected-shopping-list" ) . val ( ) } ,
2020-10-04 15:20:34 +02:00
function ( result )
{
2020-11-15 22:38:21 +01:00
Grocy . Api . Post ( 'stock/shoppinglist/add-expired-products' , { "list_id" : $ ( "#selected-shopping-list" ) . val ( ) } ,
function ( result )
{
window . location . href = U ( '/shoppinglist?list=' + $ ( "#selected-shopping-list" ) . val ( ) ) ;
} ,
function ( xhr )
{
console . error ( xhr ) ;
}
) ;
2020-10-04 15:20:34 +02:00
} ,
function ( xhr )
{
console . error ( xhr ) ;
}
) ;
} ) ;
2018-07-15 08:29:26 +02:00
$ ( document ) . on ( 'click' , '#clear-shopping-list' , function ( e )
{
2021-08-17 18:05:32 +02:00
var confirmMessage = _ _t ( 'Are you sure to empty shopping list "%s"?' , $ ( "#selected-shopping-list option:selected" ) . text ( ) ) ;
if ( ! BoolVal ( Grocy . FeatureFlags . GROCY _FEATURE _FLAG _SHOPPINGLIST _MULTIPLE _LISTS ) )
{
confirmMessage = _ _t ( 'Are you sure to empty the shopping list?' ) ;
}
2018-07-15 08:29:26 +02:00
bootbox . confirm ( {
2021-08-17 18:05:32 +02:00
message : confirmMessage ,
2019-09-24 10:24:47 +02:00
closeButton : false ,
2018-07-15 08:29:26 +02:00
buttons : {
confirm : {
2019-05-01 20:19:18 +02:00
label : _ _t ( 'Yes' ) ,
2018-07-15 08:29:26 +02:00
className : 'btn-success'
} ,
cancel : {
2019-05-01 20:19:18 +02:00
label : _ _t ( 'No' ) ,
2018-07-15 08:29:26 +02:00
className : 'btn-danger'
}
} ,
callback : function ( result )
{
if ( result === true )
{
2018-11-24 19:40:50 +01:00
Grocy . FrontendHelpers . BeginUiBusy ( ) ;
2019-04-20 17:04:40 +02:00
Grocy . Api . Post ( 'stock/shoppinglist/clear' , { "list_id" : $ ( "#selected-shopping-list" ) . val ( ) } ,
2018-07-15 08:29:26 +02:00
function ( result )
{
2021-08-27 20:39:47 +02:00
window . location . reload ( ) ;
2018-07-15 08:29:26 +02:00
} ,
function ( xhr )
{
2018-11-24 19:40:50 +01:00
Grocy . FrontendHelpers . EndUiBusy ( ) ;
2018-07-15 08:29:26 +02:00
console . error ( xhr ) ;
}
) ;
}
}
} ) ;
} ) ;
2018-11-14 21:40:17 +01:00
2022-11-19 19:45:00 +01:00
$ ( document ) . on ( "click" , "#clear-done-items" , function ( e )
{
Grocy . Api . Post ( 'stock/shoppinglist/clear' , { "list_id" : $ ( "#selected-shopping-list" ) . val ( ) , "done_only" : true } ,
function ( result )
{
window . location . reload ( ) ;
} ,
function ( xhr )
{
console . error ( xhr ) ;
}
) ;
} ) ;
2018-11-17 14:50:52 +01:00
$ ( document ) . on ( 'click' , '.shopping-list-stock-add-workflow-list-item-button' , function ( e )
2018-11-14 21:40:17 +01:00
{
2018-11-17 14:50:52 +01:00
e . preventDefault ( ) ;
2019-01-19 00:37:21 -07:00
2023-05-03 08:32:49 +02:00
$ ( ".tooltip" ) . tooltip ( "hide" ) ;
2020-04-13 18:26:53 +02:00
2018-11-17 14:50:52 +01:00
var href = $ ( e . currentTarget ) . attr ( 'href' ) ;
$ ( "#shopping-list-stock-add-workflow-purchase-form-frame" ) . attr ( "src" , href ) ;
$ ( "#shopping-list-stock-add-workflow-modal" ) . modal ( "show" ) ;
if ( Grocy . ShoppingListToStockWorkflowAll )
{
2018-11-18 14:19:50 +01:00
$ ( "#shopping-list-stock-add-workflow-purchase-item-count" ) . removeClass ( "d-none" ) ;
2019-05-05 14:13:50 +02:00
$ ( "#shopping-list-stock-add-workflow-purchase-item-count" ) . text ( _ _t ( "Adding shopping list item %1$s of %2$s" , Grocy . ShoppingListToStockWorkflowCurrent , Grocy . ShoppingListToStockWorkflowCount ) ) ;
2018-11-26 20:02:01 +01:00
$ ( "#shopping-list-stock-add-workflow-skip-button" ) . removeClass ( "d-none" ) ;
}
else
{
$ ( "#shopping-list-stock-add-workflow-skip-button" ) . addClass ( "d-none" ) ;
2018-11-17 14:50:52 +01:00
}
} ) ;
Grocy . ShoppingListToStockWorkflowAll = false ;
Grocy . ShoppingListToStockWorkflowCount = 0 ;
Grocy . ShoppingListToStockWorkflowCurrent = 0 ;
2021-09-15 22:08:23 +10:00
Grocy . ShoppingListAddToStockButtonList = [ ] ;
2018-11-17 14:50:52 +01:00
$ ( document ) . on ( 'click' , '#add-all-items-to-stock-button' , function ( e )
{
Grocy . ShoppingListToStockWorkflowAll = true ;
2021-09-15 22:08:23 +10:00
Grocy . ShoppingListAddToStockButtonList = $ ( ".shopping-list-stock-add-workflow-list-item-button" ) ;
Grocy . ShoppingListToStockWorkflowCount = Grocy . ShoppingListAddToStockButtonList . length ;
2018-11-17 14:50:52 +01:00
Grocy . ShoppingListToStockWorkflowCurrent ++ ;
$ ( ".shopping-list-stock-add-workflow-list-item-button" ) . first ( ) . click ( ) ;
} ) ;
2018-11-26 20:02:01 +01:00
$ ( "#shopping-list-stock-add-workflow-modal" ) . on ( "hidden.bs.modal" , function ( e )
{
Grocy . ShoppingListToStockWorkflowAll = false ;
Grocy . ShoppingListToStockWorkflowCount = 0 ;
Grocy . ShoppingListToStockWorkflowCurrent = 0 ;
2021-09-15 22:08:23 +10:00
Grocy . ShoppingListAddToStockButtonList = [ ] ;
2018-11-26 20:02:01 +01:00
} )
2018-11-17 14:50:52 +01:00
$ ( window ) . on ( "message" , function ( e )
{
var data = e . originalEvent . data ;
2019-01-19 00:37:21 -07:00
2018-11-17 14:50:52 +01:00
if ( data . Message === "AfterItemAdded" )
{
$ ( ".shoppinglist-delete-button[data-shoppinglist-id='" + data . Payload + "']" ) . click ( ) ;
}
else if ( data . Message === "Ready" )
{
if ( ! Grocy . ShoppingListToStockWorkflowAll )
{
$ ( "#shopping-list-stock-add-workflow-modal" ) . modal ( "hide" ) ;
}
else
{
Grocy . ShoppingListToStockWorkflowCurrent ++ ;
if ( Grocy . ShoppingListToStockWorkflowCurrent <= Grocy . ShoppingListToStockWorkflowCount )
{
2021-09-15 22:08:23 +10:00
Grocy . ShoppingListAddToStockButtonList [ Grocy . ShoppingListToStockWorkflowCurrent - 1 ] . click ( ) ;
2018-11-17 14:50:52 +01:00
}
else
{
$ ( "#shopping-list-stock-add-workflow-modal" ) . modal ( "hide" ) ;
}
}
}
} ) ;
2018-11-26 20:02:01 +01:00
$ ( document ) . on ( 'click' , '#shopping-list-stock-add-workflow-skip-button' , function ( e )
{
e . preventDefault ( ) ;
2019-01-19 00:37:21 -07:00
2018-11-26 20:02:01 +01:00
window . postMessage ( WindowMessageBag ( "Ready" ) , Grocy . BaseUrl ) ;
} ) ;
2019-07-06 17:56:59 +02:00
$ ( document ) . on ( 'click' , '.order-listitem-button' , function ( e )
{
e . preventDefault ( ) ;
2023-05-03 08:32:49 +02:00
$ ( ".tooltip" ) . tooltip ( "hide" ) ;
2020-04-13 18:26:53 +02:00
2019-07-06 17:56:59 +02:00
Grocy . FrontendHelpers . BeginUiBusy ( ) ;
var listItemId = $ ( e . currentTarget ) . attr ( 'data-item-id' ) ;
2020-08-29 16:41:27 +02:00
2019-07-06 17:56:59 +02:00
var done = 1 ;
if ( $ ( e . currentTarget ) . attr ( 'data-item-done' ) == 1 )
{
done = 0 ;
}
$ ( e . currentTarget ) . attr ( 'data-item-done' , done ) ;
Grocy . Api . Put ( 'objects/shopping_list/' + listItemId , { 'done' : done } ,
function ( )
{
2023-03-16 18:47:01 +01:00
var statusInfoCell = $ ( "#shoppinglistitem-" + listItemId + "-status-info" ) ;
2019-07-06 17:56:59 +02:00
if ( done == 1 )
{
$ ( '#shoppinglistitem-' + listItemId + '-row' ) . addClass ( "text-muted" ) ;
$ ( '#shoppinglistitem-' + listItemId + '-row' ) . addClass ( "text-strike-through" ) ;
2023-03-16 18:47:01 +01:00
statusInfoCell . text ( statusInfoCell . text ( ) . replace ( "xxUNDONExx" , "xxDONExx" ) ) ;
2019-07-06 17:56:59 +02:00
}
else
{
$ ( '#shoppinglistitem-' + listItemId + '-row' ) . removeClass ( "text-muted" ) ;
$ ( '#shoppinglistitem-' + listItemId + '-row' ) . removeClass ( "text-strike-through" ) ;
2023-03-16 18:47:01 +01:00
statusInfoCell . text ( statusInfoCell . text ( ) . replace ( "xxDONExx" , "xxUNDONExx" ) ) ;
2019-07-06 17:56:59 +02:00
}
2023-03-16 18:47:01 +01:00
shoppingListTable . rows ( ) . invalidate ( ) . draw ( false ) ;
$ ( "#status-filter" ) . trigger ( "change" ) ;
2019-07-06 17:56:59 +02:00
Grocy . FrontendHelpers . EndUiBusy ( ) ;
} ,
function ( xhr )
{
Grocy . FrontendHelpers . EndUiBusy ( ) ;
console . error ( xhr ) ;
}
) ;
} ) ;
2018-11-17 14:50:52 +01:00
function OnListItemRemoved ( )
{
if ( $ ( ".shopping-list-stock-add-workflow-list-item-button" ) . length === 0 )
{
$ ( "#add-all-items-to-stock-button" ) . addClass ( "disabled" ) ;
}
2018-11-14 21:40:17 +01:00
}
2018-11-17 14:50:52 +01:00
OnListItemRemoved ( ) ;
2019-09-20 17:40:45 +02:00
$ ( document ) . on ( "click" , "#print-shopping-list-button" , function ( e )
{
2020-12-19 23:57:33 +01:00
var dialogHtml = ' \
2020-12-21 21:42:21 +01:00
< div class = "text-center" > < h5 > ' + __t(' Print options ') + ' < / h 5 > < h r > < / d i v > \
2020-12-19 23:57:33 +01:00
< div class = "custom-control custom-checkbox" > \
< input id = "print-show-header" \
checked \
class = "form-check-input custom-control-input" \
type = "checkbox" \
value = "1" > \
< label class = "form-check-label custom-control-label" \
for = "print-show-header" > ' + __t(' Show header ') + ' \
< / l a b e l > \
< / d i v > \
< div class = "custom-control custom-checkbox" > \
< input id = "print-group-by-product-group" \
checked \
class = "form-check-input custom-control-input" \
type = "checkbox" \
value = "1" > \
< label class = "form-check-label custom-control-label" \
for = "print-group-by-product-group" > ' + __t(' Group by product group ') + ' \
< / l a b e l > \
< / d i v > \
< h5 class = "pt-3 pb-0" > ' + __t(' Layout type ') + ' < / h 5 > \
< div class = "custom-control custom-radio" > \
< input id = "print-layout-type-table" \
checked \
class = "custom-control-input" \
type = "radio" \
name = "print-layout-type" \
value = "print-layout-type-table" > \
< label class = "custom-control-label" \
for = "print-layout-type-table" > ' + __t(' Table ') + ' \
< / l a b e l > \
< / d i v > \
< div class = "custom-control custom-radio" > \
< input id = "print-layout-type-list" \
class = "custom-control-input" \
type = "radio" \
name = "print-layout-type" \
value = "print-layout-type-list" > \
< label class = "custom-control-label" \
for = "print-layout-type-list" > ' + __t(' List ') + ' \
< / l a b e l > \
< / d i v > ' ;
2021-06-18 20:45:42 +02:00
var sizePrintDialog = 'medium' ;
var printButtons = {
cancel : {
label : _ _t ( 'Cancel' ) ,
className : 'btn-secondary' ,
callback : function ( )
{
bootbox . hideAll ( ) ;
}
} ,
printtp : {
label : _ _t ( 'Thermal printer' ) ,
className : 'btn-secondary' ,
callback : function ( )
{
bootbox . hideAll ( ) ;
var printHeader = $ ( "#print-show-header" ) . prop ( "checked" ) ;
var thermalPrintDialog = bootbox . dialog ( {
title : _ _t ( 'Printing' ) ,
message : '<p><i class="fa fa-spin fa-spinner"></i> ' + _ _t ( 'Connecting to printer...' ) + '</p>'
} ) ;
//Delaying for one second so that the alert can be closed
setTimeout ( function ( )
2020-12-19 23:57:33 +01:00
{
2021-06-18 20:45:42 +02:00
Grocy . Api . Get ( 'print/shoppinglist/thermal?list=' + $ ( "#selected-shopping-list" ) . val ( ) + '&printHeader=' + printHeader ,
function ( result )
{
bootbox . hideAll ( ) ;
} ,
function ( xhr )
{
console . error ( xhr ) ;
var validResponse = true ;
try
{
var jsonError = JSON . parse ( xhr . responseText ) ;
} catch ( e )
{
validResponse = false ;
}
if ( validResponse )
{
thermalPrintDialog . find ( '.bootbox-body' ) . html ( _ _t ( 'Unable to print' ) + '<br><pre><code>' + jsonError . error _message + '</pre></code>' ) ;
} else
{
thermalPrintDialog . find ( '.bootbox-body' ) . html ( _ _t ( 'Unable to print' ) + '<br><pre><code>' + xhr . responseText + '</pre></code>' ) ;
}
}
) ;
} , 1000 ) ;
}
} ,
ok : {
label : _ _t ( 'Print' ) ,
className : 'btn-primary responsive-button' ,
callback : function ( )
{
bootbox . hideAll ( ) ;
$ ( '.modal-backdrop' ) . remove ( ) ;
$ ( ".print-timestamp" ) . text ( moment ( ) . format ( "l LT" ) ) ;
2020-12-19 23:57:33 +01:00
2021-06-18 20:45:42 +02:00
$ ( "#description-for-print" ) . html ( $ ( "#description" ) . val ( ) ) ;
2023-02-06 20:22:10 +01:00
if ( ! $ ( "#description" ) . text ( ) )
2021-06-18 20:45:42 +02:00
{
$ ( "#description-for-print" ) . parent ( ) . addClass ( "d-print-none" ) ;
}
2020-12-19 23:57:33 +01:00
2021-06-18 20:45:42 +02:00
if ( ! $ ( "#print-show-header" ) . prop ( "checked" ) )
{
$ ( "#print-header" ) . addClass ( "d-none" ) ;
}
2020-12-19 23:57:33 +01:00
2021-06-18 20:45:42 +02:00
if ( ! $ ( "#print-group-by-product-group" ) . prop ( "checked" ) )
{
shoppingListPrintShadowTable . rowGroup ( ) . enable ( false ) ;
shoppingListPrintShadowTable . order . fixed ( { } ) ;
shoppingListPrintShadowTable . draw ( ) ;
}
2020-12-19 23:57:33 +01:00
2021-06-18 20:45:42 +02:00
$ ( ".print-layout-container" ) . addClass ( "d-none" ) ;
$ ( "." + $ ( "input[name='print-layout-type']:checked" ) . val ( ) ) . removeClass ( "d-none" ) ;
2020-12-19 23:57:33 +01:00
2021-06-18 20:45:42 +02:00
window . print ( ) ;
2020-12-19 23:57:33 +01:00
}
}
2021-06-18 20:45:42 +02:00
}
if ( ! Grocy . FeatureFlags [ "GROCY_FEATURE_FLAG_THERMAL_PRINTER" ] )
{
delete printButtons [ 'printtp' ] ;
sizePrintDialog = 'small' ;
}
bootbox . dialog ( {
message : dialogHtml ,
size : sizePrintDialog ,
backdrop : true ,
closeButton : false ,
className : "d-print-none" ,
buttons : printButtons
2020-12-19 23:57:33 +01:00
} ) ;
2019-09-20 17:40:45 +02:00
} ) ;
2019-09-20 18:08:38 +02:00
2021-07-06 19:48:55 +02:00
$ ( document ) . on ( "change" , "input[name='print-layout-type']" , function ( e )
{
if ( this . value == "print-layout-type-list" )
{
$ ( "#print-group-by-product-group" ) . prop ( "checked" , false ) ;
$ ( "#print-group-by-product-group" ) . attr ( "disabled" , "" ) ;
}
else
{
$ ( "#print-group-by-product-group" ) . removeAttr ( "disabled" ) ;
}
} ) ;
2019-09-20 18:08:38 +02:00
$ ( "#description" ) . on ( "summernote.change" , function ( )
{
$ ( "#save-description-button" ) . removeClass ( "disabled" ) ;
2019-09-28 08:48:58 +02:00
if ( $ ( "#description" ) . summernote ( "isEmpty" ) )
{
$ ( "#clear-description-button" ) . addClass ( "disabled" ) ;
}
else
{
$ ( "#clear-description-button" ) . removeClass ( "disabled" ) ;
}
2019-09-20 18:08:38 +02:00
} ) ;
$ ( document ) . on ( "click" , "#save-description-button" , function ( e )
{
e . preventDefault ( ) ;
document . activeElement . blur ( ) ;
Grocy . Api . Put ( 'objects/shopping_lists/' + $ ( "#selected-shopping-list" ) . val ( ) , { description : $ ( "#description" ) . val ( ) } ,
function ( result )
{
$ ( "#save-description-button" ) . addClass ( "disabled" ) ;
} ,
function ( xhr )
{
2019-09-27 14:08:24 +02:00
console . error ( xhr ) ;
2019-09-20 18:08:38 +02:00
}
) ;
} ) ;
2019-09-28 08:48:58 +02:00
$ ( document ) . on ( "click" , "#clear-description-button" , function ( e )
{
e . preventDefault ( ) ;
document . activeElement . blur ( ) ;
$ ( "#description" ) . summernote ( "reset" ) ;
$ ( "#save-description-button" ) . click ( ) ;
} ) ;
$ ( "#description" ) . trigger ( "summernote.change" ) ;
$ ( "#save-description-button" ) . addClass ( "disabled" ) ;
2020-01-24 22:05:08 +01:00
2020-10-29 11:09:35 -05:00
$ ( window ) . on ( "message" , function ( e )
{
var data = e . originalEvent . data ;
if ( data . Message === "ShoppingListChanged" )
{
window . location . href = U ( '/shoppinglist?list=' + data . Payload ) ;
}
} ) ;
2020-12-20 19:31:12 +01:00
var dummyCanvas = document . createElement ( "canvas" ) ;
$ ( "img.barcode" ) . each ( function ( )
{
var img = $ ( this ) ;
2020-12-22 10:20:31 +01:00
var barcode = img . attr ( "data-barcode" ) . replace ( /\D/g , "" ) ;
var barcodeType = "code128" ;
if ( barcode . length == 8 )
{
barcodeType = "ean8" ;
}
else if ( barcode . length == 13 )
{
barcodeType = "ean13" ;
}
2020-12-20 19:31:12 +01:00
bwipjs . toCanvas ( dummyCanvas , {
2020-12-22 10:20:31 +01:00
bcid : barcodeType ,
text : barcode ,
2020-12-20 19:31:12 +01:00
height : 5 ,
includetext : false
} ) ;
img . attr ( "src" , dummyCanvas . toDataURL ( "image/png" ) ) ;
} ) ;
2020-12-21 16:29:39 +01:00
2020-12-21 20:13:49 +01:00
if ( $ ( window ) . width ( ) < 768 || ! Grocy . FeatureFlags . GROCY _FEATURE _FLAG _STOCK )
2020-12-21 16:29:39 +01:00
{
$ ( "#filter-container" ) . removeClass ( "border-bottom" ) ;
}