Commit 9df14fd6 authored by Michael Koch's avatar Michael Koch
Browse files

Simplify _validateDate calls, also check for valid prep times before adding...

Simplify _validateDate calls, also check for valid prep times before adding preparation events to cal
parent 6a29d080
...@@ -103,7 +103,7 @@ async function setupLandingCalendar() { ...@@ -103,7 +103,7 @@ async function setupLandingCalendar() {
"<br /><br /><b>Zeitraum " + (info.event._def.extendedProps.room.room_type === 1 ? "Lernsprint" : (info.event._def.extendedProps.room.room_type === 5 ? "StudySpace" : "Veranstaltung")) + ":</b><br />" + "<br /><br /><b>Zeitraum " + (info.event._def.extendedProps.room.room_type === 1 ? "Lernsprint" : (info.event._def.extendedProps.room.room_type === 5 ? "StudySpace" : "Veranstaltung")) + ":</b><br />" +
_getLocalDateTimeShort(info.event._def.extendedProps.reservation.event.from) + " bis<br />" + _getLocalDateTimeShort(info.event._def.extendedProps.reservation.event.from) + " bis<br />" +
_getLocalDateTimeShort(info.event._def.extendedProps.reservation.event.to) + _getLocalDateTimeShort(info.event._def.extendedProps.reservation.event.to) +
(info.view.type !== "timeGridWeek" && _validateDate(info.event._def.extendedProps.reservation.preparation.from, 'YYYY-MM-DD HH:mm') ? (info.view.type !== "timeGridWeek" && _validateDate(info.event._def.extendedProps.reservation.preparation.from) ?
"<br /><br /><b>Zeitraum inkl. Auf- und Abbau:</b><br />" + "<br /><br /><b>Zeitraum inkl. Auf- und Abbau:</b><br />" +
_getLocalDateTimeShort(info.event._def.extendedProps.reservation.preparation.from) + " bis<br />" + _getLocalDateTimeShort(info.event._def.extendedProps.reservation.preparation.from) + " bis<br />" +
_getLocalDateTimeShort(info.event._def.extendedProps.reservation.preparation.to) _getLocalDateTimeShort(info.event._def.extendedProps.reservation.preparation.to)
...@@ -174,7 +174,7 @@ async function setupFrontendCalendar() { ...@@ -174,7 +174,7 @@ async function setupFrontendCalendar() {
content: "<b>Buchung Nr. " + info.event._def.extendedProps.reservation.id + "</b><br />" + info.event._def.extendedProps.room.longname + " (" + info.event._def.extendedProps.room.location + ")" + content: "<b>Buchung Nr. " + info.event._def.extendedProps.reservation.id + "</b><br />" + info.event._def.extendedProps.room.longname + " (" + info.event._def.extendedProps.room.location + ")" +
(info.event._def.extendedProps.reservation.confirmed === 1 ? '<br /><br /><b>BEST&Auml;TIGT</b>' : '') + (info.event._def.extendedProps.reservation.confirmed === 1 ? '<br /><br /><b>BEST&Auml;TIGT</b>' : '') +
(info.event._def.extendedProps.reservation.denied === 1 ? '<br /><br /><b>ABGELEHNT</b>' : '') + (info.event._def.extendedProps.reservation.denied === 1 ? '<br /><br /><b>ABGELEHNT</b>' : '') +
(info.view.type === "dayGridMonth" && _validateDate(info.event._def.extendedProps.reservation.preparation.from, 'YYYY-MM-DD HH:mm') ? "<br /><br /><b>Zeitraum inkl. Auf- und Abbau:</b><br />" + (info.view.type === "dayGridMonth" && _validateDate(info.event._def.extendedProps.reservation.preparation.from) ? "<br /><br /><b>Zeitraum inkl. Auf- und Abbau:</b><br />" +
_getLocalDateTimeShort(info.event._def.extendedProps.reservation.preparation.from) + " bis<br />" + _getLocalDateTimeShort(info.event._def.extendedProps.reservation.preparation.from) + " bis<br />" +
_getLocalDateTimeShort(info.event._def.extendedProps.reservation.preparation.to) : "") + _getLocalDateTimeShort(info.event._def.extendedProps.reservation.preparation.to) : "") +
"<br /><br /><b>Zeitraum " + (info.event._def.extendedProps.room.room_type === 1 ? "Lernsprint" : (info.event._def.extendedProps.room.room_type === 5 ? "StudySpace" : "Veranstaltung")) + ":</b><br />" + "<br /><br /><b>Zeitraum " + (info.event._def.extendedProps.room.room_type === 1 ? "Lernsprint" : (info.event._def.extendedProps.room.room_type === 5 ? "StudySpace" : "Veranstaltung")) + ":</b><br />" +
...@@ -249,7 +249,7 @@ function fillLandingCalendar() { ...@@ -249,7 +249,7 @@ function fillLandingCalendar() {
_calendars.landing.batchRendering(() => { _calendars.landing.batchRendering(() => {
$.each(_events.unconfirmed, (i, e) => { $.each(_events.unconfirmed, (i, e) => {
_calendars.landing.addEvent({ _calendars.landing.addEvent({
title: e.room.shortname.substring(0,3).toUpperCase() + " - " + e.subject + " (" + e.contact.name + ")", title: e.room.room_type === 5 ? 'StudySpace - ' + e.contact.name : e.room.shortname.substring(0,3).toUpperCase() + " - " + e.subject + " (" + e.contact.name + ")",
start: dayjs(e.event.from).$d, start: dayjs(e.event.from).$d,
end: dayjs(e.event.to).$d, end: dayjs(e.event.to).$d,
color: e.room.calendar_color, color: e.room.calendar_color,
...@@ -261,20 +261,22 @@ function fillLandingCalendar() { ...@@ -261,20 +261,22 @@ function fillLandingCalendar() {
reservation: e reservation: e
} }
}); });
_calendars.landing.addEvent({ if (_validateDate(e.preparation.from)) {
title: '', _calendars.landing.addEvent({
start: dayjs(e.preparation.from).$d, title: '',
end: dayjs(e.preparation.to).$d, start: dayjs(e.preparation.from).$d,
color: e.room.calendar_color, end: dayjs(e.preparation.to).$d,
textColor: _isColorLight(e.room.calendar_color) ? '#000000' : '#ffffff', color: e.room.calendar_color,
rendering: 'background', textColor: _isColorLight(e.room.calendar_color) ? '#000000' : '#ffffff',
extendedProps: { rendering: 'background',
confirmed: false, extendedProps: {
timeslot: 'preparation', confirmed: false,
room: e.room, timeslot: 'preparation',
reservation: e room: e.room,
} reservation: e
}); }
});
}
}); });
}); });
...@@ -408,20 +410,22 @@ function fillFrontendCalendar() { ...@@ -408,20 +410,22 @@ function fillFrontendCalendar() {
reservation: e reservation: e
} }
}); });
_calendars.frontend.addEvent({ if (_validateDate(e.preparation.from)) {
title: '', _calendars.frontend.addEvent({
start: dayjs(e.preparation.from).$d, title: '',
end: dayjs(e.preparation.to).$d, start: dayjs(e.preparation.from).$d,
color: e.room.calendar_color, end: dayjs(e.preparation.to).$d,
textColor: _isColorLight(e.room.calendar_color) ? '#000000' : '#ffffff', color: e.room.calendar_color,
rendering: 'background', textColor: _isColorLight(e.room.calendar_color) ? '#000000' : '#ffffff',
extendedProps: { rendering: 'background',
confirmed: false, extendedProps: {
timeslot: 'preparation', confirmed: false,
room: e.room, timeslot: 'preparation',
reservation: e room: e.room,
} reservation: e
}); }
});
}
}); });
asyncs_done++; asyncs_done++;
......
...@@ -133,12 +133,12 @@ function detectRoomSelection() { ...@@ -133,12 +133,12 @@ function detectRoomSelection() {
$("#new_reservation_to_event").show(); $("#new_reservation_to_event").show();
$("#new_reservation_to_event").datetimepicker({ minDate: _getFormattedDate(_addDays(new Date(), 7)), timepicker: false, defaultTime: '22:00', disabledWeekDays: [] }); $("#new_reservation_to_event").datetimepicker({ minDate: _getFormattedDate(_addDays(new Date(), 7)), timepicker: false, defaultTime: '22:00', disabledWeekDays: [] });
} }
if (_validateDate($("#new_reservation_from_event").val(), 'YYYY-MM-DD HH:mm')) { if (_validateDate($("#new_reservation_from_event").val())) {
let minD = _getFormattedDate($("#new_reservation_from_event").val()); let minD = _getFormattedDate($("#new_reservation_from_event").val());
let maxD = _getFormattedDate(_addDays($("#new_reservation_from_event").val(), 7)); let maxD = _getFormattedDate(_addDays($("#new_reservation_from_event").val(), 7));
$("#new_reservation_to_event").datetimepicker({ minDate: minD, maxDate: maxD }); $("#new_reservation_to_event").datetimepicker({ minDate: minD, maxDate: maxD });
} }
if (_validateDate($("#new_reservation_to_event").val(), 'YYYY-MM-DD HH:mm')) { if (_validateDate($("#new_reservation_to_event").val())) {
let minD = _getFormattedDate(_.max([_addDays($("#new_reservation_to_event").val(), -7), _addDays(new Date(), 1)])); let minD = _getFormattedDate(_.max([_addDays($("#new_reservation_to_event").val(), -7), _addDays(new Date(), 1)]));
let maxD = _getFormattedDate($("#new_reservation_to_event").val()); let maxD = _getFormattedDate($("#new_reservation_to_event").val());
$("#new_reservation_from_event").datetimepicker({ minDate: minD, maxDate: maxD }); $("#new_reservation_from_event").datetimepicker({ minDate: minD, maxDate: maxD });
...@@ -161,20 +161,20 @@ function detectRoomSelection() { ...@@ -161,20 +161,20 @@ function detectRoomSelection() {
$("#new_reservation_to_event").datetimepicker(_defaults_datetimepicker); $("#new_reservation_to_event").datetimepicker(_defaults_datetimepicker);
$("#new_reservation_from_event").datetimepicker({ timepicker: true }); $("#new_reservation_from_event").datetimepicker({ timepicker: true });
$("#new_reservation_to_event").datetimepicker({ timepicker: true }); $("#new_reservation_to_event").datetimepicker({ timepicker: true });
if (_validateDate($("#new_reservation_from_preparation").val(), 'YYYY-MM-DD HH:mm')) { if (_validateDate($("#new_reservation_from_preparation").val())) {
$("#new_reservation_from_event").datetimepicker({ useCurrent: false, minDate: _getFormattedDate($("#new_reservation_from_preparation").val()) }); $("#new_reservation_from_event").datetimepicker({ useCurrent: false, minDate: _getFormattedDate($("#new_reservation_from_preparation").val()) });
$("#new_reservation_to_preparation").datetimepicker({ useCurrent: false, minDate: _getFormattedDate($("#new_reservation_from_preparation").val()) }); $("#new_reservation_to_preparation").datetimepicker({ useCurrent: false, minDate: _getFormattedDate($("#new_reservation_from_preparation").val()) });
} }
if (_validateDate($("#new_reservation_to_preparation").val(), 'YYYY-MM-DD HH:mm')) { if (_validateDate($("#new_reservation_to_preparation").val())) {
$("#new_reservation_from_preparation").datetimepicker({ useCurrent: false, maxDate: _getFormattedDate($("#new_reservation_to_preparation").val()) }); $("#new_reservation_from_preparation").datetimepicker({ useCurrent: false, maxDate: _getFormattedDate($("#new_reservation_to_preparation").val()) });
$("#new_reservation_from_event").datetimepicker({ useCurrent: false, maxDate: _getFormattedDate($("#new_reservation_to_preparation").val()) }); $("#new_reservation_from_event").datetimepicker({ useCurrent: false, maxDate: _getFormattedDate($("#new_reservation_to_preparation").val()) });
$("#new_reservation_to_event").datetimepicker({ useCurrent: false, maxDate: _getFormattedDate($("#new_reservation_to_preparation").val()) }); $("#new_reservation_to_event").datetimepicker({ useCurrent: false, maxDate: _getFormattedDate($("#new_reservation_to_preparation").val()) });
} }
if (_validateDate($("#new_reservation_from_event").val(), 'YYYY-MM-DD HH:mm')) { if (_validateDate($("#new_reservation_from_event").val())) {
$("#new_reservation_from_preparation").datetimepicker({ useCurrent: false, maxDate: _getFormattedDate($("#new_reservation_from_event").val()) }); $("#new_reservation_from_preparation").datetimepicker({ useCurrent: false, maxDate: _getFormattedDate($("#new_reservation_from_event").val()) });
$("#new_reservation_to_event").datetimepicker({ useCurrent: false, minDate: _getFormattedDate($("#new_reservation_from_event").val()) }); $("#new_reservation_to_event").datetimepicker({ useCurrent: false, minDate: _getFormattedDate($("#new_reservation_from_event").val()) });
} }
if (_validateDate($("#new_reservation_to_event").val(), 'YYYY-MM-DD HH:mm')) { if (_validateDate($("#new_reservation_to_event").val())) {
$("#new_reservation_to_preparation").datetimepicker({ useCurrent: false, minDate: _getFormattedDate($("#new_reservation_to_event").val()) }); $("#new_reservation_to_preparation").datetimepicker({ useCurrent: false, minDate: _getFormattedDate($("#new_reservation_to_event").val()) });
$("#new_reservation_from_event").datetimepicker({ useCurrent: false, maxDate: _getFormattedDate($("#new_reservation_to_event").val()) }); $("#new_reservation_from_event").datetimepicker({ useCurrent: false, maxDate: _getFormattedDate($("#new_reservation_to_event").val()) });
} }
...@@ -218,7 +218,7 @@ function checkNewReservationForm() { ...@@ -218,7 +218,7 @@ function checkNewReservationForm() {
}; };
} }
if (! _validateDate($("#new_reservation_from_event").val(), 'YYYY-MM-DD HH:mm')) { if (! _validateDate($("#new_reservation_from_event").val())) {
return { return {
'success': false, 'success': false,
'reason': 'from_event_invalid' 'reason': 'from_event_invalid'
...@@ -261,7 +261,7 @@ function checkNewReservationForm() { ...@@ -261,7 +261,7 @@ function checkNewReservationForm() {
} }
if (r[0].room_type !== 1 && r[0].room_type !== 5) { if (r[0].room_type !== 1 && r[0].room_type !== 5) {
if (! _validateDate($("#new_reservation_to_event").val(), 'YYYY-MM-DD HH:mm')) { if (! _validateDate($("#new_reservation_to_event").val())) {
return { return {
'success': false, 'success': false,
'reason': 'to_event_invalid' 'reason': 'to_event_invalid'
...@@ -282,14 +282,14 @@ function checkNewReservationForm() { ...@@ -282,14 +282,14 @@ function checkNewReservationForm() {
}; };
} }
if (! _validateDate($("#new_reservation_from_preparation").val(), 'YYYY-MM-DD HH:mm')) { if (! _validateDate($("#new_reservation_from_preparation").val())) {
return { return {
'success': false, 'success': false,
'reason': 'from_preparation_invalid' 'reason': 'from_preparation_invalid'
}; };
} }
if (! _validateDate($("#new_reservation_to_preparation").val(), 'YYYY-MM-DD HH:mm')) { if (! _validateDate($("#new_reservation_to_preparation").val())) {
return { return {
'success': false, 'success': false,
'reason': 'to_preparation_invalid' 'reason': 'to_preparation_invalid'
...@@ -360,7 +360,7 @@ function limitFrontendDatetimePicker() { ...@@ -360,7 +360,7 @@ function limitFrontendDatetimePicker() {
let te_max = false; let te_max = false;
// from preparation // from preparation
if (_validateDate(fp.val(), 'YYYY-MM-DD HH:mm')) { if (_validateDate(fp.val())) {
let fp_cur = dayjs(fp.val()); let fp_cur = dayjs(fp.val());
tp_min = fp_cur; tp_min = fp_cur;
...@@ -372,7 +372,7 @@ function limitFrontendDatetimePicker() { ...@@ -372,7 +372,7 @@ function limitFrontendDatetimePicker() {
} }
// to preparation // to preparation
if (_validateDate(tp.val(), 'YYYY-MM-DD HH:mm')) { if (_validateDate(tp.val())) {
let tp_cur = dayjs(tp.val()); let tp_cur = dayjs(tp.val());
fp_min = _.max([_addDays(tp_cur, -7), tomorrow, fp_min]); fp_min = _.max([_addDays(tp_cur, -7), tomorrow, fp_min]);
...@@ -384,7 +384,7 @@ function limitFrontendDatetimePicker() { ...@@ -384,7 +384,7 @@ function limitFrontendDatetimePicker() {
} }
// from event // from event
if (_validateDate(fe.val(), 'YYYY-MM-DD HH:mm')) { if (_validateDate(fe.val())) {
let fe_cur = dayjs(fe.val()); let fe_cur = dayjs(fe.val());
te_min = _.max([fe_cur, te_min]); te_min = _.max([fe_cur, te_min]);
...@@ -395,7 +395,7 @@ function limitFrontendDatetimePicker() { ...@@ -395,7 +395,7 @@ function limitFrontendDatetimePicker() {
} }
// to event // to event
if (_validateDate(te.val(), 'YYYY-MM-DD HH:mm')) { if (_validateDate(te.val())) {
let te_cur = dayjs(te.val()); let te_cur = dayjs(te.val());
fe_min = _.max([_addDays(te_cur, -7), tomorrow, fe_min]); fe_min = _.max([_addDays(te_cur, -7), tomorrow, fe_min]);
......
...@@ -150,8 +150,8 @@ function refreshReservations() { ...@@ -150,8 +150,8 @@ function refreshReservations() {
if (r.result === "success") { if (r.result === "success") {
if (! _.isEqual(r.content, _reservations) || forceReload) { if (! _.isEqual(r.content, _reservations) || forceReload) {
if (r.content) { if (r.content) {
let fromtime = (resv) => dayjs(_validateDate(resv.preparation.from, 'YYYY-MM-DD HH:mm') ? resv.preparation.from : resv.event.from); let fromtime = (resv) => dayjs(_validateDate(resv.preparation.from) ? resv.preparation.from : resv.event.from);
let totime = (resv) => dayjs(_validateDate(resv.preparation.to, 'YYYY-MM-DD HH:mm') ? resv.preparation.to : resv.event.to); let totime = (resv) => dayjs(_validateDate(resv.preparation.to) ? resv.preparation.to : resv.event.to);
_reservations.all = r.content; _reservations.all = r.content;
_reservations.open.upcoming = $.grep(_reservations.all, (resv, i) => resv.confirmed === 0 && resv.denied === 0 && totime(resv) >= now); _reservations.open.upcoming = $.grep(_reservations.all, (resv, i) => resv.confirmed === 0 && resv.denied === 0 && totime(resv) >= now);
......
...@@ -145,11 +145,11 @@ function _validateEmail(email) { ...@@ -145,11 +145,11 @@ function _validateEmail(email) {
* Validates a given string as a Date * Validates a given string as a Date
* *
* @param {String} datestring - Date string to be validated * @param {String} datestring - Date string to be validated
* @param {number} [format='YYYY-MM-DD HH:mm:ss'] - Date format to validate against * @param {number} [format='YYYY-MM-DD HH:mm'] - Date format to validate against
* @returns {boolean} - Whether the provided string is a valid date * @returns {boolean} - Whether the provided string is a valid date
*/ */
function _validateDate(datestring) { function _validateDate(datestring) {
const format = arguments.length > 1 && arguments[1] !== undefined && typeof arguments[1] === "string" ? arguments[1] : 'YYYY-MM-DD HH:mm:ss'; const format = arguments.length > 1 && arguments[1] !== undefined && typeof arguments[1] === "string" ? arguments[1] : 'YYYY-MM-DD HH:mm';
return dayjs(datestring, format, true).isValid(); return dayjs(datestring, format, true).isValid();
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment