2018-07-14 18:23:41 +02:00
var recipesTables = $ ( '#recipes-table' ) . DataTable ( {
'paginate' : false ,
2018-08-11 14:38:17 +02:00
'order' : [ [ 0 , 'asc' ] ] ,
2018-07-14 18:23:41 +02:00
'language' : JSON . parse ( L ( 'datatables_localization' ) ) ,
'scrollY' : false ,
'colReorder' : true ,
2018-07-14 22:49:42 +02:00
'stateSave' : true ,
2018-09-08 08:56:32 +02:00
'stateSaveParams' : function ( settings , data )
{
data . search . search = "" ;
2018-09-25 08:50:28 +02:00
data . columns . forEach ( column =>
{
column . search . search = "" ;
} ) ;
2018-09-08 08:56:32 +02:00
} ,
2018-07-15 10:16:36 +02:00
'select' : 'single' ,
'initComplete' : function ( )
{
this . api ( ) . row ( { order : 'current' } , 0 ) . select ( ) ;
}
2018-07-14 18:23:41 +02:00
} ) ;
2018-07-15 09:56:10 +02:00
var rowSelect = GetUriParam ( "row" ) ;
if ( typeof rowSelect !== "undefined" )
{
recipesTables . row ( rowSelect ) . select ( ) ;
}
2018-07-14 18:23:41 +02:00
$ ( "#search" ) . on ( "keyup" , function ( )
{
var value = $ ( this ) . val ( ) ;
if ( value === "all" )
{
value = "" ;
}
recipesTables . search ( value ) . draw ( ) ;
} ) ;
2018-08-11 14:38:17 +02:00
$ ( "#selectedRecipeDeleteButton" ) . on ( 'click' , function ( e )
2018-07-14 18:23:41 +02:00
{
var objectName = $ ( e . currentTarget ) . attr ( 'data-recipe-name' ) ;
var objectId = $ ( e . currentTarget ) . attr ( 'data-recipe-id' ) ;
bootbox . confirm ( {
message : L ( 'Are you sure to delete recipe "#1"?' , objectName ) ,
buttons : {
confirm : {
label : L ( 'Yes' ) ,
className : 'btn-success'
} ,
cancel : {
label : L ( 'No' ) ,
className : 'btn-danger'
}
} ,
callback : function ( result )
{
if ( result === true )
{
Grocy . Api . Get ( 'delete-object/recipes/' + objectId ,
function ( result )
{
window . location . href = U ( '/recipes' ) ;
} ,
function ( xhr )
{
console . error ( xhr ) ;
}
) ;
}
}
} ) ;
} ) ;
2018-07-14 22:49:42 +02:00
$ ( document ) . on ( 'click' , '.recipe-order-missing-button' , function ( e )
{
var objectName = $ ( e . currentTarget ) . attr ( 'data-recipe-name' ) ;
var objectId = $ ( e . currentTarget ) . attr ( 'data-recipe-id' ) ;
bootbox . confirm ( {
message : L ( 'Are you sure to put all missing ingredients for recipe "#1" on the shopping list?' , objectName ) ,
buttons : {
confirm : {
label : L ( 'Yes' ) ,
className : 'btn-success'
} ,
cancel : {
label : L ( 'No' ) ,
className : 'btn-danger'
}
} ,
callback : function ( result )
{
if ( result === true )
{
Grocy . Api . Get ( 'recipes/add-not-fulfilled-products-to-shopping-list/' + objectId ,
function ( result )
{
window . location . href = U ( '/recipes' ) ;
} ,
function ( xhr )
{
console . error ( xhr ) ;
}
) ;
}
}
} ) ;
} ) ;
2018-07-15 09:56:10 +02:00
2018-08-11 11:48:25 +02:00
$ ( "#selectedRecipeConsumeButton" ) . on ( 'click' , function ( e )
{
var objectName = $ ( e . currentTarget ) . attr ( 'data-recipe-name' ) ;
var objectId = $ ( e . currentTarget ) . attr ( 'data-recipe-id' ) ;
bootbox . confirm ( {
message : L ( 'Are you sure to consume all ingredients needed by recipe "#1" (ingredients marked with "check only if a single unit is in stock" will be ignored)?' , objectName ) ,
buttons : {
confirm : {
label : L ( 'Yes' ) ,
className : 'btn-success'
} ,
cancel : {
label : L ( 'No' ) ,
className : 'btn-danger'
}
} ,
callback : function ( result )
{
if ( result === true )
{
Grocy . Api . Get ( 'recipes/consume-recipe/' + objectId ,
function ( result )
{
toastr . success ( L ( 'Removed all ingredients of recipe "#1" from stock' , objectName ) ) ;
} ,
function ( xhr )
{
console . error ( xhr ) ;
}
) ;
}
}
} ) ;
} ) ;
2018-07-15 09:56:10 +02:00
recipesTables . on ( 'select' , function ( e , dt , type , indexes )
{
if ( type === 'row' )
{
var selectedRecipeId = $ ( recipesTables . row ( indexes [ 0 ] ) . node ( ) ) . data ( "recipe-id" ) ;
window . location . href = U ( '/recipes?recipe=' + selectedRecipeId . toString ( ) + "&row=" + indexes [ 0 ] . toString ( ) ) ;
}
} ) ;
$ ( "#selectedRecipeToggleFullscreenButton" ) . on ( 'click' , function ( e )
{
$ ( "#selectedRecipeCard" ) . toggleClass ( "fullscreen" ) ;
2018-10-13 09:18:16 +02:00
$ ( "body" ) . toggleClass ( "fullscreen-card" ) ;
2018-09-30 09:41:22 +02:00
$ ( "#selectedRecipeCard .card-header" ) . toggleClass ( "fixed-top" ) ;
2018-10-03 16:41:21 +02:00
$ ( "#selectedRecipeCard .card-body" ) . toggleClass ( "mt-5" ) ;
2018-07-15 09:56:10 +02:00
} ) ;