2017-07-25 20:03:31 +02:00
$ ( '#save-habit-button' ) . on ( 'click' , function ( e )
{
e . preventDefault ( ) ;
if ( Grocy . EditMode === 'create' )
{
2018-04-18 19:03:39 +02:00
Grocy . Api . Post ( 'add-object/habits' , $ ( '#habit-form' ) . serializeJSON ( ) ,
2017-07-25 20:03:31 +02:00
function ( result )
{
2018-04-18 19:03:39 +02:00
window . location . href = U ( '/habits' ) ;
2017-07-25 20:03:31 +02:00
} ,
function ( xhr )
{
console . error ( xhr ) ;
}
) ;
}
else
{
2018-04-18 19:03:39 +02:00
Grocy . Api . Post ( 'edit-object/habits/' + Grocy . EditObjectId , $ ( '#habit-form' ) . serializeJSON ( ) ,
2017-07-25 20:03:31 +02:00
function ( result )
{
2018-04-18 19:03:39 +02:00
window . location . href = U ( '/habits' ) ;
2017-07-25 20:03:31 +02:00
} ,
function ( xhr )
{
console . error ( xhr ) ;
}
) ;
}
} ) ;
2018-04-16 19:11:32 +02:00
$ ( '#name' ) . focus ( ) ;
$ ( '#habit-form' ) . validator ( ) ;
$ ( '#habit-form' ) . validator ( 'validate' ) ;
2017-07-25 20:03:31 +02:00
$ ( '.input-group-habit-period-type' ) . on ( 'change' , function ( e )
{
var periodType = $ ( '#period_type' ) . val ( ) ;
var periodDays = $ ( '#period_days' ) . val ( ) ;
if ( periodType === 'dynamic-regular' )
{
$ ( '#habit-period-type-info' ) . text ( 'This means it is estimated that a new "execution" of this habit is tracked ' + periodDays . toString ( ) + ' days after the last was tracked.' ) ;
$ ( '#habit-period-type-info' ) . show ( ) ;
}
else
{
$ ( '#habit-period-type-info' ) . hide ( ) ;
}
} ) ;