@@ -24,16 +24,28 @@ $(document).ready(function () {
24
24
25
25
toggleVisibility ( '#time_schedule_limit-enabled, #requests-time_schedule_limit-enabled' , '#schedule-day-limits-wrapper' , true )
26
26
27
+ setInterval ( ( ) => {
28
+ let success = true ;
29
+ try {
30
+ // Show the current local time according to either placeholder or entered TZ name
31
+ if ( timezone_text_widget . val ( ) . length ) {
32
+ $ ( '#local-time-in-tz' ) . text ( getTimeInTimezone ( timezone_text_widget . val ( ) ) ) ;
33
+ } else {
34
+ // So maybe use what is in the placeholder (which will be the default settings)
35
+ $ ( '#local-time-in-tz' ) . text ( getTimeInTimezone ( timezone_text_widget . attr ( 'placeholder' ) ) ) ;
36
+ }
37
+ } catch ( error ) {
38
+ success = false ;
39
+ $ ( '#local-time-in-tz' ) . text ( "" ) ;
40
+ console . error ( timezone_text_widget . val ( ) )
41
+ }
42
+
43
+ $ ( timezone_text_widget ) . toggleClass ( 'error' , ! success ) ;
44
+
45
+ } , 500 ) ;
46
+
27
47
$ ( '#schedule-day-limits-wrapper' ) . on ( 'change click blur' , 'input, checkbox, select' , function ( ) {
28
48
29
- if ( timezone_text_widget . val ( ) . length ) {
30
- document . getElementById ( 'local-time-in-tz' ) . textContent =
31
- getTimeInTimezone ( timezone_text_widget . val ( ) ) ;
32
- } else {
33
- // So maybe use what is in the placeholder (which will be the default settings)
34
- document . getElementById ( 'local-time-in-tz' ) . textContent =
35
- getTimeInTimezone ( timezone_text_widget . attr ( 'placeholder' ) ) ;
36
- }
37
49
let allOk = true ;
38
50
39
51
// Controls setting the warning that the time could overlap into the next day
@@ -63,14 +75,13 @@ $(document).ready(function () {
63
75
} ) ;
64
76
65
77
warning_text . toggle ( ! allOk )
66
- } , 500 ) ;
78
+ } ) ;
67
79
68
80
$ ( 'table[id*="time_schedule_limit-saturday"], table[id*="time_schedule_limit-sunday"]' ) . addClass ( "weekend-day" )
69
81
70
82
// Presets [weekend] [business hours] etc
71
83
$ ( document ) . on ( 'click' , '[data-template].set-schedule' , function ( ) {
72
84
// Get the value of the 'data-template' attribute
73
-
74
85
switch ( $ ( this ) . attr ( 'data-template' ) ) {
75
86
case 'business-hours' :
76
87
$ ( '.day-schedule table:not(.weekend-day) input[type="time"]' ) . val ( '09:00' )
@@ -87,16 +98,11 @@ $(document).ready(function () {
87
98
$ ( '.day-schedule .weekend-day input[id*="-enabled"]' ) . prop ( 'checked' , true ) ;
88
99
break ;
89
100
case 'reset' :
90
- $ ( '.day-schedule .day-schedule input[type="time"]' ) . val ( '00:00' )
91
- $ ( '.day-schedule .day-schedule select[id*="-duration-hours"]' ) . val ( '24' ) ;
92
- $ ( '.day-schedule .day-schedule select[id*="-duration-minutes"]' ) . val ( '0' ) ;
93
- $ ( '.day-schedule .day-schedule input[id*="-enabled"]' ) . prop ( 'checked' , true ) ;
94
- break ;
95
- case 'once-per-day' :
96
- $ ( '.day-schedule .day-schedule input[type="time"]' ) . val ( '00:00' )
97
- $ ( '.day-schedule .day-schedule select[id*="-duration-hours"]' ) . val ( '24' ) ;
98
- $ ( '.day-schedule .day-schedule select[id*="-duration-minutes"]' ) . val ( '0' ) ;
99
- $ ( '.day-schedule .day-schedule input[id*="-enabled"]' ) . prop ( 'checked' , true ) ;
101
+
102
+ $ ( '.day-schedule input[type="time"]' ) . val ( '00:00' )
103
+ $ ( '.day-schedule select[id*="-duration-hours"]' ) . val ( '24' ) ;
104
+ $ ( '.day-schedule select[id*="-duration-minutes"]' ) . val ( '0' ) ;
105
+ $ ( '.day-schedule input[id*="-enabled"]' ) . prop ( 'checked' , true ) ;
100
106
break ;
101
107
}
102
108
} ) ;
0 commit comments