Skip to content
Snippets Groups Projects
Commit f73e2918 authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms
Browse files

allow setting different default view (regular and responsive), re #4421

Merge request studip/studip!3657
parent 73b3cdcc
No related branches found
No related tags found
No related merge requests found
......@@ -109,6 +109,7 @@ class Calendar_ScheduleController extends AuthenticatedController
$semester->id ?? '',
Request::bool('show_hidden', false)
);
$fullcalendar->setResponsiveDefaultView('timeGridDay');
$this->fullcalendar = $fullcalendar->render();
}
......
<?php
namespace Studip;
class Fullcalendar
{
protected $title;
......@@ -20,7 +17,6 @@ class Fullcalendar
*/
protected $attributes;
/**
* The name of the fullcalendar for the data attribute. This is set
* to "fullcalendar" by default, but custom fullcalendars may require
......@@ -29,7 +25,6 @@ class Fullcalendar
*/
protected $data_name;
public static function create(
$title = '',
$config = [],
......@@ -47,7 +42,6 @@ class Fullcalendar
return $instance->render();
}
public function __construct(
$title = '',
$config = [],
......@@ -61,6 +55,23 @@ class Fullcalendar
$this->data_name = $data_name;
}
public function setDefaultView(?string $view): void
{
if ($view === null) {
unset($this->config['defaultView']);
} else {
$this->config['defaultView'] = $view;
}
}
public function setResponsiveDefaultView(?string $view): void
{
if ($view === null) {
unset($this->config['responsiveDefaultView']);
} else {
$this->config['responsiveDefaultView'] = $view;
}
}
public function render()
{
......@@ -79,7 +90,6 @@ class Fullcalendar
);
}
/**
* Creates an array with data for a Fullcalendar instance
* from Stud.IP objects that implement the EventSource interface.
......
......@@ -15,6 +15,7 @@ import resourceTimelinePlugin from '@fullcalendar/resource-timeline';
import { jsPDF } from 'jspdf';
import html2canvas from 'html2canvas';
import Responsive from "./responsive";
Date.prototype.getWeekNumber = function () {
var d = new Date(Date.UTC(this.getFullYear(), this.getMonth(), this.getDate()));
......@@ -395,14 +396,20 @@ class Fullcalendar
return;
}
var config = $(node).data('config');
let config = $(node).data('config');
let defaultView = 'timeGridWeek';
if (Responsive.isResponsive() && config.responsiveDefaultView !== undefined) {
defaultView = config.responsiveDefaultView;
} else if (config.defaultView !== undefined) {
defaultView = config.defaultView;
}
//Make sure the default values are set, if they are not found
//in the additional_config object:
config = $.extend({
plugins: [ interactionPlugin, dayGridPlugin, timeGridPlugin, resourceCommonPlugin, resourceTimeGridPlugin, resourceTimelinePlugin ],
schedulerLicenseKey: 'GPL-My-Project-Is-Open-Source',
defaultView: 'timeGridWeek',
header: {
left: 'dayGridMonth,timeGridWeek,timeGridDay'
},
......@@ -696,6 +703,8 @@ class Fullcalendar
config = $.extend({}, config, additional_config);
config.defaultView = defaultView;
return this.init(node, config);
}
......
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