You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
104 lines
4.7 KiB
104 lines
4.7 KiB
4 weeks ago
|
function getTimeInTimezone(timezone) {
|
||
|
const now = new Date();
|
||
|
const options = {
|
||
|
timeZone: timezone,
|
||
|
weekday: 'long',
|
||
|
year: 'numeric',
|
||
|
hour12: false,
|
||
|
month: '2-digit',
|
||
|
day: '2-digit',
|
||
|
hour: '2-digit',
|
||
|
minute: '2-digit',
|
||
|
second: '2-digit',
|
||
|
};
|
||
|
|
||
|
const formatter = new Intl.DateTimeFormat('en-US', options);
|
||
|
return formatter.format(now);
|
||
|
}
|
||
|
|
||
|
$(document).ready(function () {
|
||
|
|
||
|
let exceedsLimit = false;
|
||
|
const warning_text = $("#timespan-warning")
|
||
|
const timezone_text_widget = $("input[id*='time_schedule_limit-timezone']")
|
||
|
|
||
|
toggleVisibility('#time_schedule_limit-enabled, #requests-time_schedule_limit-enabled', '#schedule-day-limits-wrapper', true)
|
||
|
|
||
|
$('#schedule-day-limits-wrapper').on('change click blur', 'input, checkbox, select', function() {
|
||
|
|
||
|
if (timezone_text_widget.val().length) {
|
||
|
document.getElementById('local-time-in-tz').textContent =
|
||
|
getTimeInTimezone(timezone_text_widget.val());
|
||
|
} else {
|
||
|
// So maybe use what is in the placeholder (which will be the default settings)
|
||
|
document.getElementById('local-time-in-tz').textContent =
|
||
|
getTimeInTimezone(timezone_text_widget.attr('placeholder'));
|
||
|
}
|
||
|
let allOk = true;
|
||
|
|
||
|
// Controls setting the warning that the time could overlap into the next day
|
||
|
$("li.day-schedule").each(function () {
|
||
|
const $schedule = $(this);
|
||
|
const $checkbox = $schedule.find("input[type='checkbox']");
|
||
|
|
||
|
if ($checkbox.is(":checked")) {
|
||
|
const timeValue = $schedule.find("input[type='time']").val();
|
||
|
const durationHours = parseInt($schedule.find("select[name*='-duration-hours']").val(), 10) || 0;
|
||
|
const durationMinutes = parseInt($schedule.find("select[name*='-duration-minutes']").val(), 10) || 0;
|
||
|
|
||
|
if (timeValue) {
|
||
|
const [startHours, startMinutes] = timeValue.split(":").map(Number);
|
||
|
const totalMinutes = (startHours * 60 + startMinutes) + (durationHours * 60 + durationMinutes);
|
||
|
|
||
|
exceedsLimit = totalMinutes > 1440
|
||
|
if (exceedsLimit) {
|
||
|
allOk = false
|
||
|
}
|
||
|
// Set the row/day-of-week highlight
|
||
|
$schedule.toggleClass("warning", exceedsLimit);
|
||
|
}
|
||
|
} else {
|
||
|
$schedule.toggleClass("warning", false);
|
||
|
}
|
||
|
});
|
||
|
|
||
|
warning_text.toggle(!allOk)
|
||
|
}, 500);
|
||
|
|
||
|
$('table[id*="time_schedule_limit-saturday"], table[id*="time_schedule_limit-sunday"]').addClass("weekend-day")
|
||
|
|
||
|
// Presets [weekend] [business hours] etc
|
||
|
$(document).on('click', '[data-template].set-schedule', function () {
|
||
|
// Get the value of the 'data-template' attribute
|
||
|
|
||
|
switch ($(this).attr('data-template')) {
|
||
|
case 'business-hours':
|
||
|
$('.day-schedule table:not(.weekend-day) input[type="time"]').val('09:00')
|
||
|
$('.day-schedule table:not(.weekend-day) select[id*="-duration-hours"]').val('8');
|
||
|
$('.day-schedule table:not(.weekend-day) select[id*="-duration-minutes"]').val('0');
|
||
|
$('.day-schedule input[id*="-enabled"]').prop('checked', true);
|
||
|
$('.day-schedule .weekend-day input[id*="-enabled"]').prop('checked', false);
|
||
|
break;
|
||
|
case 'weekend':
|
||
|
$('.day-schedule .weekend-day input[type="time"][id$="start-time"]').val('00:00')
|
||
|
$('.day-schedule .weekend-day select[id*="-duration-hours"]').val('24');
|
||
|
$('.day-schedule .weekend-day select[id*="-duration-minutes"]').val('0');
|
||
|
$('.day-schedule input[id*="-enabled"]').prop('checked', false);
|
||
|
$('.day-schedule .weekend-day input[id*="-enabled"]').prop('checked', true);
|
||
|
break;
|
||
|
case 'reset':
|
||
|
$('.day-schedule .day-schedule input[type="time"]').val('00:00')
|
||
|
$('.day-schedule .day-schedule select[id*="-duration-hours"]').val('24');
|
||
|
$('.day-schedule .day-schedule select[id*="-duration-minutes"]').val('0');
|
||
|
$('.day-schedule .day-schedule input[id*="-enabled"]').prop('checked', true);
|
||
|
break;
|
||
|
case 'once-per-day':
|
||
|
$('.day-schedule .day-schedule input[type="time"]').val('00:00')
|
||
|
$('.day-schedule .day-schedule select[id*="-duration-hours"]').val('24');
|
||
|
$('.day-schedule .day-schedule select[id*="-duration-minutes"]').val('0');
|
||
|
$('.day-schedule .day-schedule input[id*="-enabled"]').prop('checked', true);
|
||
|
break;
|
||
|
}
|
||
|
});
|
||
|
});
|