Skip to content

Commit f00b8e4

Browse files
committed
UI - Fixing scheduler options
1 parent 179ca17 commit f00b8e4

File tree

3 files changed

+33
-26
lines changed

3 files changed

+33
-26
lines changed

changedetectionio/static/js/global-settings.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ $(document).ready(function () {
3030
})
3131

3232
const timezoneInput = $('#application-timezone');
33-
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
34-
35-
if (!timezoneInput.val().trim()) {
36-
timezoneInput.val(timezone);
37-
timezoneInput.after('<div class="timezone-message">The timezone was set from your browser, <strong>be sure to press save!</strong></div>');
33+
if(timezoneInput.length) {
34+
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
35+
if (!timezoneInput.val().trim()) {
36+
timezoneInput.val(timezone);
37+
timezoneInput.after('<div class="timezone-message">The timezone was set from your browser, <strong>be sure to press save!</strong></div>');
38+
}
3839
}
3940

4041
});

changedetectionio/static/js/scheduler.js

+26-20
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,28 @@ $(document).ready(function () {
2424

2525
toggleVisibility('#time_schedule_limit-enabled, #requests-time_schedule_limit-enabled', '#schedule-day-limits-wrapper', true)
2626

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+
2747
$('#schedule-day-limits-wrapper').on('change click blur', 'input, checkbox, select', function() {
2848

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-
}
3749
let allOk = true;
3850

3951
// Controls setting the warning that the time could overlap into the next day
@@ -63,14 +75,13 @@ $(document).ready(function () {
6375
});
6476

6577
warning_text.toggle(!allOk)
66-
}, 500);
78+
});
6779

6880
$('table[id*="time_schedule_limit-saturday"], table[id*="time_schedule_limit-sunday"]').addClass("weekend-day")
6981

7082
// Presets [weekend] [business hours] etc
7183
$(document).on('click', '[data-template].set-schedule', function () {
7284
// Get the value of the 'data-template' attribute
73-
7485
switch ($(this).attr('data-template')) {
7586
case 'business-hours':
7687
$('.day-schedule table:not(.weekend-day) input[type="time"]').val('09:00')
@@ -87,16 +98,11 @@ $(document).ready(function () {
8798
$('.day-schedule .weekend-day input[id*="-enabled"]').prop('checked', true);
8899
break;
89100
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);
100106
break;
101107
}
102108
});

changedetectionio/templates/_helpers.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
padding-left: 0.5rem;
8080
padding-right: 0.5rem;
8181
}
82-
#timespan-warning {
82+
#timespan-warning, input[id*='time_schedule_limit-timezone'].error {
8383
color: #ff0000;
8484
}
8585
.day-schedule.warning table {

0 commit comments

Comments
 (0)