2018-07-09 19:27:22 +02:00
var productsTable = $ ( '#products-table' ) . DataTable ( {
'order' : [ [ 1 , 'asc' ] ] ,
'columnDefs' : [
2020-01-03 14:18:56 +01:00
{ 'orderable' : false , 'targets' : 0 } ,
{ 'searchable' : false , "targets" : 0 }
2020-12-07 19:48:33 +01:00
] . concat ( $ . fn . dataTable . defaults . columnDefs )
2018-07-09 19:27:22 +02:00
} ) ;
2019-01-05 20:06:35 +01:00
$ ( '#products-table tbody' ) . removeClass ( "d-none" ) ;
2019-03-04 17:43:12 +01:00
productsTable . columns . adjust ( ) . draw ( ) ;
2018-07-09 19:27:22 +02:00
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
productsTable . search ( value ) . draw ( ) ;
2019-10-15 19:59:14 +02:00
} , 200 ) ) ;
2018-07-09 19:27:22 +02:00
2019-04-05 21:08:30 +02:00
$ ( "#product-group-filter" ) . on ( "change" , function ( )
{
var value = $ ( "#product-group-filter option:selected" ) . text ( ) ;
2019-05-01 20:19:18 +02:00
if ( value === _ _t ( "All" ) )
2019-04-05 21:08:30 +02:00
{
value = "" ;
}
2020-11-15 09:21:54 +01:00
productsTable . column ( 6 ) . search ( value ) . draw ( ) ;
2019-04-05 21:08:30 +02:00
} ) ;
2020-11-07 14:53:45 +01:00
$ ( "#clear-filter-button" ) . on ( "click" , function ( )
{
$ ( "#search" ) . val ( "" ) ;
$ ( "#product-group-filter" ) . val ( "all" ) ;
productsTable . column ( 7 ) . search ( "" ) . draw ( ) ;
productsTable . search ( "" ) . draw ( ) ;
2020-12-07 19:48:33 +01:00
$ ( "#show-disabled-products" ) . prop ( 'checked' , false ) ;
2020-11-07 14:53:45 +01:00
} ) ;
2019-04-05 21:08:30 +02:00
if ( typeof GetUriParam ( "product-group" ) !== "undefined" )
{
$ ( "#product-group-filter" ) . val ( GetUriParam ( "product-group" ) ) ;
$ ( "#product-group-filter" ) . trigger ( "change" ) ;
}
2020-08-30 12:18:16 +02:00
$ ( document ) . on ( 'click' , '.product-delete-button' , function ( e )
2017-04-15 23:16:20 +02:00
{
2020-10-14 22:58:26 +02:00
var objectName = $ ( e . currentTarget ) . attr ( 'data-product-name' ) ;
2018-04-21 19:18:00 +02:00
var objectId = $ ( e . currentTarget ) . attr ( 'data-product-id' ) ;
2020-12-07 19:48:33 +01:00
bootbox . confirm ( {
2020-12-07 19:55:31 +01:00
message : _ _t ( 'Are you sure to delete product "%s"?' , objectName ) + '<br><br>' + _ _t ( 'This also removes any stock amount, the journal and all other references of this product - consider disabling it instead, if you want to keep that and just hide the product.' ) ,
2020-12-07 19:48:33 +01:00
closeButton : false ,
buttons : {
confirm : {
label : _ _t ( 'Yes' ) ,
className : 'btn-success'
} ,
cancel : {
label : _ _t ( 'No' ) ,
className : 'btn-danger'
}
} ,
callback : function ( result )
2017-04-15 23:16:20 +02:00
{
2020-12-07 19:48:33 +01:00
if ( result === true )
2017-04-15 23:16:20 +02:00
{
2020-12-07 19:48:33 +01:00
jsonData = { } ;
jsonData . active = 0 ;
Grocy . Api . Delete ( 'objects/products/' + objectId , { } ,
function ( result )
{
window . location . href = U ( '/products' ) ;
2017-04-15 23:16:20 +02:00
} ,
2020-12-07 19:48:33 +01:00
function ( xhr )
2017-04-15 23:16:20 +02:00
{
2020-12-07 19:48:33 +01:00
console . error ( xhr ) ;
2017-04-15 23:16:20 +02:00
}
2020-12-07 19:48:33 +01:00
) ;
2017-04-15 23:16:20 +02:00
}
}
2020-12-07 19:48:33 +01:00
} ) ;
} ) ;
$ ( "#show-disabled-products" ) . change ( function ( )
{
if ( this . checked )
{
window . location . href = U ( '/products?include_disabled' ) ;
}
else
{
window . location . href = U ( '/products' ) ;
}
2017-04-15 23:16:20 +02:00
} ) ;
2020-12-07 19:48:33 +01:00
if ( GetUriParam ( 'include_disabled' ) )
{
$ ( "#show-disabled-products" ) . prop ( 'checked' , true ) ;
}