1
1
function toggleOpacity ( checkboxSelector , fieldSelector , inverted ) {
2
2
const checkbox = document . querySelector ( checkboxSelector ) ;
3
3
const fields = document . querySelectorAll ( fieldSelector ) ;
4
+
4
5
function updateOpacity ( ) {
5
6
const opacityValue = ! checkbox . checked ? ( inverted ? 0.6 : 1 ) : ( inverted ? 1 : 0.6 ) ;
6
7
fields . forEach ( field => {
7
8
field . style . opacity = opacityValue ;
8
9
} ) ;
9
10
}
11
+
10
12
// Initial setup
11
13
updateOpacity ( ) ;
12
14
checkbox . addEventListener ( 'change' , updateOpacity ) ;
@@ -15,12 +17,14 @@ function toggleOpacity(checkboxSelector, fieldSelector, inverted) {
15
17
function toggleVisibility ( checkboxSelector , fieldSelector , inverted ) {
16
18
const checkbox = document . querySelector ( checkboxSelector ) ;
17
19
const fields = document . querySelectorAll ( fieldSelector ) ;
20
+
18
21
function updateOpacity ( ) {
19
22
const opacityValue = ! checkbox . checked ? ( inverted ? 'none' : 'block' ) : ( inverted ? 'block' : 'none' ) ;
20
23
fields . forEach ( field => {
21
24
field . style . display = opacityValue ;
22
25
} ) ;
23
26
}
27
+
24
28
// Initial setup
25
29
updateOpacity ( ) ;
26
30
checkbox . addEventListener ( 'change' , updateOpacity ) ;
@@ -45,7 +49,6 @@ function getTimeInTimezone(timezone) {
45
49
}
46
50
47
51
48
-
49
52
function request_textpreview_update ( ) {
50
53
if ( ! $ ( 'body' ) . hasClass ( 'preview-text-enabled' ) ) {
51
54
console . error ( "Preview text was requested but body tag was not setup" )
@@ -92,6 +95,8 @@ function request_textpreview_update() {
92
95
93
96
94
97
$ ( document ) . ready ( function ( ) {
98
+ let exceedsLimit = false ;
99
+ const warning_text = $ ( "#timespan-warning" )
95
100
96
101
window . setInterval ( function ( ) {
97
102
if ( $ ( "#time_schedule_limit-timezone" ) . val ( ) . length ) {
@@ -102,12 +107,39 @@ $(document).ready(function () {
102
107
document . getElementById ( 'local-time-in-tz' ) . textContent =
103
108
getTimeInTimezone ( $ ( "#time_schedule_limit-timezone" ) . attr ( 'placeholder' ) ) ;
104
109
}
110
+ let allOk = true ;
111
+
112
+ $ ( "li.day-schedule" ) . each ( function ( ) {
113
+ const $schedule = $ ( this ) ;
114
+ const $checkbox = $schedule . find ( "input[type='checkbox']" ) ;
115
+
116
+ if ( $checkbox . is ( ":checked" ) ) {
117
+ const timeValue = $schedule . find ( "input[type='time']" ) . val ( ) ;
118
+ const durationHours = parseInt ( $schedule . find ( "select[name*='-duration-hours']" ) . val ( ) , 10 ) || 0 ;
119
+ const durationMinutes = parseInt ( $schedule . find ( "select[name*='-duration-minutes']" ) . val ( ) , 10 ) || 0 ;
120
+
121
+ if ( timeValue ) {
122
+ const [ startHours , startMinutes ] = timeValue . split ( ":" ) . map ( Number ) ;
123
+ const totalMinutes = ( startHours * 60 + startMinutes ) + ( durationHours * 60 + durationMinutes ) ;
124
+
125
+ exceedsLimit = totalMinutes > 1440
126
+ if ( exceedsLimit ) {
127
+ allOk = false
128
+ }
129
+ $schedule . toggleClass ( "warning" , exceedsLimit ) ;
130
+ }
131
+ } else {
132
+ $schedule . toggleClass ( "warning" , false ) ;
133
+ }
134
+ } ) ;
135
+
136
+ warning_text . toggle ( ! allOk )
105
137
} , 500 ) ;
106
138
107
139
$ ( '#time_schedule_limit-saturday, #time_schedule_limit-sunday' ) . addClass ( "weekend-day" )
108
140
109
- $ ( document ) . on ( 'click' , '[data-template].set-schedule' , function ( ) {
110
- // Get the value of the 'data-template' attribute
141
+ $ ( document ) . on ( 'click' , '[data-template].set-schedule' , function ( ) {
142
+ // Get the value of the 'data-template' attribute
111
143
112
144
switch ( $ ( this ) . attr ( 'data-template' ) ) {
113
145
case 'business-hours' :
@@ -138,7 +170,7 @@ $(document).ready(function () {
138
170
break ;
139
171
}
140
172
} ) ;
141
-
173
+
142
174
$ ( '#notification-setting-reset-to-default' ) . click ( function ( e ) {
143
175
$ ( '#notification_title' ) . val ( '' ) ;
144
176
$ ( '#notification_body' ) . val ( '' ) ;
@@ -155,8 +187,8 @@ $(document).ready(function () {
155
187
toggleVisibility ( '#time_schedule_limit-enabled' , '#schedule-day-limits-wrapper' , true )
156
188
157
189
const vh = Math . max ( document . documentElement . clientHeight || 0 , window . innerHeight || 0 ) ;
158
- $ ( "#text-preview-inner" ) . css ( 'max-height' , ( vh - 300 ) + "px" ) ;
159
- $ ( "#text-preview-before-inner" ) . css ( 'max-height' , ( vh - 300 ) + "px" ) ;
190
+ $ ( "#text-preview-inner" ) . css ( 'max-height' , ( vh - 300 ) + "px" ) ;
191
+ $ ( "#text-preview-before-inner" ) . css ( 'max-height' , ( vh - 300 ) + "px" ) ;
160
192
161
193
$ ( "#activate-text-preview" ) . click ( function ( e ) {
162
194
$ ( 'body' ) . toggleClass ( 'preview-text-enabled' )
0 commit comments