summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUdo Walter2019-12-11 13:20:28 +0100
committerUdo Walter2019-12-11 13:20:28 +0100
commit5a814c388bfc5d933150eb519800206623b5aba4 (patch)
treefa3d4356dc68ac7d69d93b71753fdb1f7b99eeeb
parent[serversetup-bwlp-ipxe/minilinux] Add comments, fix minor logic bug (diff)
downloadslx-admin-5a814c388bfc5d933150eb519800206623b5aba4.tar.gz
slx-admin-5a814c388bfc5d933150eb519800206623b5aba4.tar.xz
slx-admin-5a814c388bfc5d933150eb519800206623b5aba4.zip
[locationinfo] fix calendar start date when using a custom start week day
-rwxr-xr-xmodules-available/locationinfo/templates/frontend-default.html26
1 files changed, 22 insertions, 4 deletions
diff --git a/modules-available/locationinfo/templates/frontend-default.html b/modules-available/locationinfo/templates/frontend-default.html
index 9bca1ccb..2388af42 100755
--- a/modules-available/locationinfo/templates/frontend-default.html
+++ b/modules-available/locationinfo/templates/frontend-default.html
@@ -747,14 +747,31 @@ optional:
}
/**
+ * Calculate the correct start date based on the number of days shown in the calendar
+ * @param startDay Start week day (0 = current day, 1 = Monday, 7 = Sunday)
+ * @param daysToShow Number of days to show in the calendar
+ * @return {Date} Start date
+ */
+ function getStartDate(startDay, daysToShow) {
+ var now = new Date();
+ var startDate = new Date(now.getTime());
+ if (startDay > 0) {
+ startDate.setDate(startDate.getDate() - startDate.getDay() + (startDay % 7));
+ if (startDate > now) startDate.setDate(startDate.getDate() - 7);
+ var endDayDate = new Date(startDate.getTime());
+ endDayDate.setDate(endDayDate.getDate() + daysToShow);
+ if (endDayDate <= now) startDate.setDate(startDate.getDate() + 7);
+ }
+ return startDate;
+ }
+
+ /**
* inilizes the Calendar for an room
* @param room Room Object
*/
function setUpCalendar(room) {
var daysToShow = room.config.daystoshow;
- var startDay = room.config.startday;
- var startDayDate = new Date();
- if (startDay > 0) startDayDate.setDate((startDayDate.getDate() - (startDayDate.getDay() + 6) % 7) + (startDay - 1));
+ var startDate = getStartDate(room.config.startday, daysToShow);
generateCalendarDiv(room);
room.$.calendar.weekCalendar({
timeslotsPerHour: 1,
@@ -782,7 +799,7 @@ optional:
$event.find(".time").css({"backgroundColor": "#25B002", "border": "1px solid #888"});
}
},
- date: startDayDate,
+ date: startDate,
dateFormat: "j.n",
timeFormat: "G:i",
scrollToHourMillis: 500,
@@ -1043,6 +1060,7 @@ optional:
result = Math.min(Math.max(Math.abs(result), 1), 7);
if (result !== $cal.weekCalendar("option", "daysToShow")) {
$cal.weekCalendar("option", "daysToShow", result);
+ $cal.weekCalendar("gotoDate", getStartDate(room.config.startday, result));
columnWidth = $cal.find(".wc-day-1").width();
}
}