Skip to content

Commit 2c58149

Browse files
labmecanicatecJohnVillalovos
authored andcommitted
fix(schedule): centralize render completion and auto-scroll
Refactor schedule rendering to remove duplicated completion logic in both render branches. Introduce a single finishRender flow that: - initializes reservable interactions when enabled - hides the loading indicator - resets renderingEvents - triggers autoScrollToToday Close: #1409 Assisted-by: Copilot:GPT-4.1
1 parent cc9bcc6 commit 2c58149

1 file changed

Lines changed: 30 additions & 23 deletions

File tree

Web/scripts/schedule.js

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,31 @@ function Schedule(opts, resourceGroups) {
66
const groupDiv = $('#resourceGroups');
77
const multidateselect = $('#multidateselect');
88
let renderingEvents = false;
9+
let hasAutoScrolledToday = false;
910

1011
const ScheduleStandard = '0';
1112
const ScheduleWide = '1';
1213
const ScheduleTall = '2';
1314
const ScheduleCondensed = '3';
1415

16+
function autoScrollToToday() {
17+
if (!scheduleOpts.autoScrollToday || hasAutoScrolledToday) {
18+
return;
19+
}
20+
21+
const today = document.querySelector('#reservations tr.today');
22+
if (!today) {
23+
return;
24+
}
25+
26+
hasAutoScrolledToday = true;
27+
28+
today.scrollIntoView({
29+
behavior: 'smooth',
30+
block: 'start',
31+
});
32+
}
33+
1534
this.init = function () {
1635
this.initUserDefaultSchedule();
1736
this.initRotateSchedule();
@@ -21,18 +40,6 @@ function Schedule(opts, resourceGroups) {
2140
this.initNavigation();
2241
addNumericalIdsToRows();
2342

24-
if (scheduleOpts.autoScrollToday) {
25-
var today = $('.today');
26-
if (today && today.length > 0) {
27-
$('html, body').animate(
28-
{
29-
scrollTop: today.offset().top - 50,
30-
},
31-
500
32-
);
33-
}
34-
}
35-
3643
$(window).on(
3744
'resize',
3845
_.debounce(function () {
@@ -274,6 +281,15 @@ function Schedule(opts, resourceGroups) {
274281
}
275282

276283
ajaxPost($('#fetchReservationsForm'), options.reservationLoadUrl, null, function (reservationList) {
284+
function finishRender() {
285+
if (options.isReservable) {
286+
initReservable();
287+
}
288+
$('#loading-schedule').addClass('d-none');
289+
renderingEvents = false;
290+
autoScrollToToday();
291+
}
292+
277293
reservationList.sort((r1, r2) => {
278294
const resourceOrder = options.resourceOrder[r1.ResourceId] - options.resourceOrder[r2.ResourceId];
279295
if (resourceOrder === 0) {
@@ -352,11 +368,7 @@ function Schedule(opts, resourceGroups) {
352368
t.append(divs);
353369
});
354370

355-
if (options.isReservable) {
356-
initReservable();
357-
}
358-
$('#loading-schedule').addClass('d-none');
359-
renderingEvents = false;
371+
finishRender();
360372

361373
return;
362374
}
@@ -701,12 +713,7 @@ function Schedule(opts, resourceGroups) {
701713
});
702714
});
703715

704-
if (options.isReservable) {
705-
initReservable();
706-
}
707-
708-
$('#loading-schedule').addClass('d-none');
709-
renderingEvents = false;
716+
finishRender();
710717
});
711718
}
712719

0 commit comments

Comments
 (0)