Skip to content
Snippets Groups Projects
Commit eed21fa5 authored by Moritz Strohm's avatar Moritz Strohm Committed by Peter Thienel
Browse files

calendar date form: move end date or time when moving the begin date or time, fixes #3862

Closes #3862

Merge request studip/studip!2726
parent f3709add
No related branches found
No related tags found
No related merge requests found
STUDIP.ready(function() {
jQuery(document).on('change', 'form.new-calendar-date-form input[name=begin]', function(event) {
let begin_value = jQuery(event.target).val();
let begin = STUDIP.Calendar.parseDateFromString(begin_value);
if (!begin) {
return;
}
let end_value = jQuery('form.new-calendar-date-form input[name=end]').val();
let end = STUDIP.Calendar.parseDateFromString(end_value);
if (end) {
//Check if the date and time in end_value is past the date in begin_value.
//If so, set the date or the time or both to a value after begin_value.
if (end.getTime() <= begin.getTime()) {
//Get the distance of the time (hours and minutes only) between begin and end:
let diff = Math.abs(end.getHours() - begin.getHours()) * 3600
+ Math.abs(end.getMinutes() - begin.getMinutes()) * 60;
end = begin;
end.setTime(end.getTime() + diff * 1000);
}
} else {
//Clone begin and add one hour to end:
end = begin;
end.setTime(end.getTime() + 3600000);
}
//Display the new end:
let end_string = STUDIP.DateTime.pad(end.getDate()) + '.' + STUDIP.DateTime.pad(end.getMonth() + 1) + '.' + end.getFullYear()
+ ' ' + STUDIP.DateTime.pad(end.getHours()) + ':' + STUDIP.DateTime.pad(end.getMinutes());
jQuery('form.new-calendar-date-form input[name=end]').val(end_string);
});
});
...@@ -38,6 +38,7 @@ import "./bootstrap/i18n_input.js" ...@@ -38,6 +38,7 @@ import "./bootstrap/i18n_input.js"
import "./bootstrap/forms.js" import "./bootstrap/forms.js"
import "./bootstrap/drag_and_drop_upload.js" import "./bootstrap/drag_and_drop_upload.js"
import "./bootstrap/admin_sem_classes.js" import "./bootstrap/admin_sem_classes.js"
import "./bootstrap/calendar.js"
import "./bootstrap/cronjobs.js" import "./bootstrap/cronjobs.js"
import "./bootstrap/contentbox.js" import "./bootstrap/contentbox.js"
import "./bootstrap/dates.js" import "./bootstrap/dates.js"
......
...@@ -124,6 +124,38 @@ const Calendar = { ...@@ -124,6 +124,38 @@ const Calendar = {
} }
return true; return true;
},
parseDateFromString: function(date_string) {
if (!date_string) {
//Nothing that can be done.
return null;
}
let string_parts = date_string.split(' ');
if (string_parts.length !== 2) {
//Invalid format.
return null;
}
let date_parts = string_parts[0].split('.');
if (date_parts.length !== 3) {
//Invalid format.
return null;
}
let time_parts = string_parts[1].split(':');
if (time_parts.length !== 2) {
//Invalid format.
return null;
}
let date = new Date(
parseInt(date_parts[2]),
parseInt(date_parts[1]) - 1,
parseInt(date_parts[0])
);
date.setHours(parseInt(time_parts[0]));
date.setMinutes(parseInt(time_parts[1]));
date.setSeconds(0);
return date;
} }
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment