Skip to content
Snippets Groups Projects
Commit 13c451c6 authored by Moritz Strohm's avatar Moritz Strohm
Browse files

set defaultDate on changed calendar dates in sidebar widgets, fixes #3924

Closes #3924

Merge request studip/studip!3046


(cherry picked from commit a0dd66e7)

ca4e1d16 set defaultDate on changed calendar dates in sidebar widgets
parent a421432d
No related branches found
No related tags found
No related merge requests found
......@@ -111,6 +111,8 @@ class Calendar_CalendarController extends AuthenticatedController
{
PageLayout::setTitle(_('Kalender'));
$default_date = \Studip\Calendar\Helper::getDefaultCalendarDate();
if (Request::isPost()) {
//In case the checkbox of the options widget is clicked, the resulting
//POST request must be catched here and result in a redirect.
......@@ -203,6 +205,7 @@ class Calendar_CalendarController extends AuthenticatedController
if ($calendar_owner && $calendar_owner->id === User::findCurrent()->id) {
//The user is viewing their own calendar.
$options = new OptionsWidget();
$options->addLayoutCSSClass('calendar-action');
$options->addCheckbox(
_('Abgelehnte Termine anzeigen'),
Request::bool('show_declined'),
......@@ -237,6 +240,7 @@ class Calendar_CalendarController extends AuthenticatedController
$this->url_for('calendar/calendar/index', ['view' => 'group']),
'group_id'
);
$group_select->addLayoutCSSClass('calendar-action');
$options = [
'' => _('(bitte wählen)')
];
......@@ -263,6 +267,7 @@ class Calendar_CalendarController extends AuthenticatedController
$this->url_for('calendar/calendar'),
'user_id'
);
$calendar_select->addLayoutCSSClass('calendar-action');
$select_options = [
'' => _('(bitte wählen)'),
User::findCurrent()->id => _('Eigener Kalender')
......@@ -335,7 +340,6 @@ class Calendar_CalendarController extends AuthenticatedController
$slot_durations = $this->getUserCalendarSlotSettings();
//Create the fullcalendar object:
$default_date = \Studip\Calendar\Helper::getDefaultCalendarDate();
$data_url_params = [];
if (Request::bool('show_declined')) {
......
......@@ -737,6 +737,25 @@ class Fullcalendar
url.searchParams.set('defaultDate', changed_date)
this.href = url.toString();
});
jQuery('.sidebar-widget.calendar-action').each(function() {
//Each sidebar widget is different. The placement of the defaultDate URL parameter
//has to reflect that.
jQuery(this).find('button[formaction]').each(function() {
//Modify the formaction attribute:
let url = new URL(jQuery(this).attr('formaction'));
url.searchParams.set('defaultDate', changed_date);
jQuery(this).attr('formaction', url.toString());
});
jQuery(this).find('form[action]').each(function() {
//Add a hidden input with the defaultDate:
let hidden_input = jQuery(this).find('input[name="defaultDate"]')[0];
if (!hidden_input) {
hidden_input = jQuery('<input type="hidden" name="defaultDate">');
jQuery(this).append(hidden_input);
}
jQuery(hidden_input).val(changed_date);
});
});
// Now change the URL of the window.
const url = new URL(window.location.href);
......
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