@@ -87,18 +87,18 @@ function showMainMenu(scroll, group, scrollback) {
8787 } ;
8888 const getGroups = settings . showGroup && ! group ;
8989 const groups = getGroups ? { } : undefined ;
90- var showAlarm ;
9190 const getIcon = ( e ) => { return e . on ? ( e . timer ? iconTimerOn : iconAlarmOn ) : ( e . timer ? iconTimerOff : iconAlarmOff ) ; } ;
9291
9392 alarms . forEach ( ( e , index ) => {
94- showAlarm = ! settings . showGroup || ( group ? e . group === group : ! e . group ) ;
93+ const showAlarm = ! settings . showGroup || ( group ? e . group === group : ! e . group ) ;
9594 if ( showAlarm ) {
9695 const label = trimLabel ( getLabel ( e ) , 40 ) ;
9796 menu [ label ] = {
9897 value : e . on ,
9998 onchange : ( v , touch ) => {
10099 if ( touch && ( 2 == touch . type || 145 < touch . x ) ) { // Long touch or touched icon.
101100 e . on = v ;
101+ if ( e . on ) prepareForSave ( e , index ) ;
102102 saveAndReload ( ) ;
103103 } else {
104104 setTimeout ( e . timer ? showEditTimerMenu : showEditAlarmMenu , 10 , e , index , undefined , scroller ?scroller . scroll :undefined , group ) ;
@@ -328,6 +328,14 @@ function prepareAlarmForSave(alarm, alarmIndex, time, date, temp) {
328328 }
329329}
330330
331+ function prepareForSave ( alarm , alarmIndex ) {
332+ if ( alarm . timer ) {
333+ prepareTimerForSave ( alarm , alarmIndex , require ( "time_utils" ) . decodeTime ( alarm . timer ) ) ;
334+ } else {
335+ prepareAlarmForSave ( alarm , alarmIndex , require ( "time_utils" ) . decodeTime ( alarm . t ) ) ;
336+ }
337+ }
338+
331339function saveAndReload ( ) {
332340 // Before saving revert the dow to the standard format (alarms only!)
333341 alarms . filter ( e => e . timer === undefined ) . forEach ( a => a . dow = handleFirstDayOfWeek ( a . dow ) ) ;
@@ -574,13 +582,7 @@ function enableAll(on) {
574582 if ( confirm ) {
575583 alarms . forEach ( ( alarm , i ) => {
576584 alarm . on = on ;
577- if ( on ) {
578- if ( alarm . timer ) {
579- prepareTimerForSave ( alarm , i , require ( "time_utils" ) . decodeTime ( alarm . timer ) ) ;
580- } else {
581- prepareAlarmForSave ( alarm , i , require ( "time_utils" ) . decodeTime ( alarm . t ) ) ;
582- }
583- }
585+ if ( on ) prepareForSave ( alarm , i ) ;
584586 } ) ;
585587 saveAndReload ( ) ;
586588 showMainMenu ( ) ;
0 commit comments