Add support for avoiding shifts on specific dates with reasons
This commit is contained in:
@@ -259,6 +259,52 @@ function generateExtra() {
|
||||
|
||||
$(table).before(summary_button);
|
||||
|
||||
// Add per-table avoid-toggle button (near the summary button)
|
||||
avoid_button = $("<button class='auto-generated'>Toggle Avoids</button>").click((evt) => {
|
||||
// ensure style exists once
|
||||
if ($('#avoid-shift-style').length === 0) {
|
||||
$('head').append(`
|
||||
<style id='avoid-shift-style'>
|
||||
td.rota-day.avoid-shift.avoid-highlight { border: 2px solid rgba(255,140,0,0.9) !important; box-shadow: 0 0 6px rgba(255,140,0,0.25); }
|
||||
</style>
|
||||
`);
|
||||
}
|
||||
|
||||
let $btn = $(evt.target);
|
||||
let enabled = $btn.data('enabled') || false;
|
||||
enabled = !enabled;
|
||||
$btn.data('enabled', enabled);
|
||||
|
||||
let $table = $(table);
|
||||
$table.find("td.rota-day.avoid-shift").each((i, el) => {
|
||||
let $el = $(el);
|
||||
if (enabled) {
|
||||
$el.addClass('avoid-highlight');
|
||||
// preserve original title
|
||||
if (!$el.data('orig-title')) $el.data('orig-title', $el.attr('title') || '');
|
||||
let avoid_shifts = $el.attr('data-avoid-shifts') || '';
|
||||
let avoid_reason = $el.attr('data-avoid-reason') || '';
|
||||
let suffix = [];
|
||||
// make the constraint type explicit in the tooltip
|
||||
suffix.push(`constraint: avoid_shifts_by_worker_dates`);
|
||||
if (avoid_shifts) suffix.push(`shifts: ${avoid_shifts}`);
|
||||
if (avoid_reason) suffix.push(`reason: ${avoid_reason}`);
|
||||
if (suffix.length) {
|
||||
let newTitle = $el.data('orig-title') + ' [' + suffix.join('; ') + ']';
|
||||
$el.attr('title', newTitle);
|
||||
}
|
||||
} else {
|
||||
$el.removeClass('avoid-highlight');
|
||||
// restore original title
|
||||
if ($el.data('orig-title') !== undefined) $el.attr('title', $el.data('orig-title'));
|
||||
}
|
||||
});
|
||||
|
||||
$btn.text(enabled ? 'Hide Avoids' : 'Toggle Avoids');
|
||||
});
|
||||
|
||||
$(table).before(avoid_button);
|
||||
|
||||
|
||||
|
||||
});
|
||||
@@ -281,6 +327,8 @@ $("#toggle-prior-adjust").on("click", (evt) => {
|
||||
$("table.tsummary").find(`td.prior-adjust, th.prior-adjust-col`).toggle();
|
||||
});
|
||||
|
||||
// Note: per-table avoid-toggle buttons are added next to each table's summary button inside generateExtra().
|
||||
|
||||
$("table.tsummary").append("<tr class='header'></tr>");
|
||||
h = $("table.tsummary tr.header");
|
||||
h.append(`<th>Worker</th>`);
|
||||
|
||||
Reference in New Issue
Block a user