Skip to content
Snippets Groups Projects
Commit 0155e499 authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms Committed by Elmar Ludwig
Browse files

fix url handling in resources.js, fixes #998

Closes #998

Merge request studip/studip!576
parent 4e9fe604
No related branches found
No related tags found
No related merge requests found
...@@ -634,32 +634,19 @@ STUDIP.ready(function () { ...@@ -634,32 +634,19 @@ STUDIP.ready(function () {
} }
function updateViewURL(defaultView) { function updateViewURL(defaultView) {
var sURLVariables = window.location.href.split(/[?&]/); const url = new URL(window.location.href);
var changed = false; url.searchParams.set('defaultView', defaultView);
for (var i = 0; i < sURLVariables.length; i++) {
var sParameterName = sURLVariables[i].split('='); // Push current view url to history
if (sParameterName[0] == "defaultView") { history.pushState({}, null, url.toString());
sParameterName[1] = defaultView;
sURLVariables[i] = sParameterName.join('='); // Set links accordingly
changed = true; url.searchParams.delete('allday');
} $('.booking-plan-std_view').attr('href', url.toString());
}
if (!changed) { url.searchParams.set('allday', 1);
sURLVariables.push('defaultView=' + defaultView); $('.booking-plan-allday_view').attr('href', url.toString());
}
if (sURLVariables.length > 2) {
var newurl = sURLVariables[0] + '?' + sURLVariables[1] + '&';
sURLVariables.shift();
sURLVariables.shift();
newurl += sURLVariables.join('&');
} else {
var newurl = sURLVariables.join('?');
} }
history.pushState({}, null, newurl);
var std_day = newurl.replace(/&?allday=\d+/, '');
$('.booking-plan-std_view').attr('href', std_day);
$('.booking-plan-allday_view').attr('href', std_day + '&allday=1');
};
function submitDatePicker() { function submitDatePicker() {
var picked = $('#booking-plan-jmpdate').val(); var picked = $('#booking-plan-jmpdate').val();
...@@ -714,32 +701,23 @@ STUDIP.ready(function () { ...@@ -714,32 +701,23 @@ STUDIP.ready(function () {
// Now change the URL of the window. // Now change the URL of the window.
var changeddate = STUDIP.Fullcalendar.toRFC3339String(changedmoment).split('T')[0]; var changeddate = STUDIP.Fullcalendar.toRFC3339String(changedmoment).split('T')[0];
var sURLVariables = window.location.href.split(/[?&]/);
var changed = false; const url = new URL(window.location.href);
for (var i = 0; i < sURLVariables.length; i++) { url.searchParams.set('defaultDate', changeddate);
var sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] == "defaultDate") { // Update url in history
sParameterName[1] = changeddate; history.pushState({}, null, url.toString());
sURLVariables[i] = sParameterName.join('=');
changed = true; // Adjust links accordingly
} url.searchParams.delete('allday');
} $('.booking-plan-std_view').attr('href', url.toString());
if (!changed) {
sURLVariables.push('defaultDate=' + changeddate); url.searchParams.set('allday', 1);
} $('.booking-plan-allday_view').attr('href', url.toString());
if (sURLVariables.length > 2) {
var newurl = sURLVariables[0] + '?' + sURLVariables[1] + '&'; // Update sidebar value
sURLVariables.shift();
sURLVariables.shift();
newurl += sURLVariables.join('&');
} else {
var newurl = sURLVariables.join('?');
}
history.pushState({}, null, newurl);
var std_day = newurl.replace(/&?allday=\d+/, '');
$('.booking-plan-std_view').attr('href', std_day);
$('.booking-plan-allday_view').attr('href', std_day + '&allday=1');
$('#booking-plan-jmpdate').val(changedmoment.toLocaleDateString('de-DE')); $('#booking-plan-jmpdate').val(changedmoment.toLocaleDateString('de-DE'));
//Store the date in the sessionStorage: //Store the date in the sessionStorage:
sessionStorage.setItem('booking_plan_date', changeddate) sessionStorage.setItem('booking_plan_date', changeddate)
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment