Files
redmine_qbo_calendar/assets/javascripts/calendar.js
T
rickyandClaude Opus 5.5 9a07c16731 No-new-work weeks on the calendar
A checkbox under each week number flags the week "no new work" and circles
it in red. New appointments in a flagged week (or ones moved or lengthened
into it) warn on the form and are stopped on save; users with "Override
no-new-work weeks" can tick "Schedule anyway". Flagging needs "Flag
no-new-work weeks". Call-outs aren't affected. Adds migration 005.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 10:16:10 -05:00

84 lines
3.0 KiB
JavaScript

document.addEventListener('DOMContentLoaded', function() {
document.addEventListener('click', function(e) {
const clickedBlock = e.target.closest('.appointment-block');
const clickedLink = e.target.closest('a');
// Allow standard links (like subject title or avatar links) to navigate normally
if (clickedLink) return;
// Clicks inside an open tooltip (e.g. selecting a phone number to copy) leave it open
if (e.target.closest('.appointment-block .tip')) return;
// Close any other open tooltips across the calendar
document.querySelectorAll('.appointment-block.open').forEach(function(block) {
if (block !== clickedBlock) {
block.classList.remove('open');
}
});
// Toggle the clicked appointment block's tooltip
if (clickedBlock) {
e.stopPropagation();
clickedBlock.classList.toggle('open');
}
});
});
(function() {
window.scrollToToday = function() {
const todayElement = document.getElementById('today');
if (todayElement) {
todayElement.scrollIntoView({ behavior: 'smooth', block: 'center' });
}
};
document.addEventListener('DOMContentLoaded', function() {
// Automatically scroll to today if present and no hash anchor is in the URL
if (!window.location.hash) {
window.scrollToToday();
}
});
// The toggles are kept in the session (CalendarsControllerPatch), so turning one off sends 0 rather
// than leaving it out
function setToggle(name, checked) {
const urlParams = new URLSearchParams(window.location.search);
urlParams.set(name, checked ? '1' : '0');
window.location.search = urlParams.toString();
}
window.toggleOnlyAppointments = function(checked) {
setToggle('only_appointments', checked);
};
window.toggleHidePastWeeks = function(checked) {
setToggle('hide_past_weeks', checked);
};
// The checkbox at the start of each week: flags it "no new work" (circled in red) without reloading
window.toggleNoWorkWeek = function(checkbox, week) {
const calendar = checkbox.closest('ul.cal');
const token = document.querySelector('meta[name="csrf-token"]');
const body = new URLSearchParams({ week: week, flagged: checkbox.checked ? '1' : '0' });
const cells = calendar.querySelectorAll('li[data-no-work-week="' + week + '"]');
checkbox.disabled = true;
fetch(calendar.dataset.noWorkWeeksUrl, {
method: 'POST',
headers: { 'Accept': 'application/json', 'X-CSRF-Token': token ? token.content : '' },
body: body,
credentials: 'same-origin'
}).then(function(response) {
if (!response.ok) throw new Error(response.status);
return response.json();
}).then(function(data) {
cells.forEach(function(cell) { cell.classList.toggle('no-work-week', data.flagged); });
}).catch(function() {
checkbox.checked = !checkbox.checked;
alert(calendar.dataset.noWorkWeekError || 'Could not save the week');
}).finally(function() {
checkbox.disabled = false;
});
};
})();