- <script>
- import axios from "axios";
- import Vue from "vue";
- import FullCalendar from '@fullcalendar/vue'
- import plLocale from "@fullcalendar/core/locales/pl";
- import bootstrapPlugin from "@fullcalendar/bootstrap";
- import interactionPlugin from "@fullcalendar/interaction";
- import dayGridPlugin from "@fullcalendar/daygrid";
- import timeGridPlugin from "@fullcalendar/timegrid";
- import Reservation from "./Reservation.vue";
- // Sets header for all POST requests to enable CSRF protection.
- axios.defaults.xsrfHeaderName = "X-CSRFTOKEN";
- axios.defaults.xsrfCookieName = "csrftoken";
- const event_status = {
- "pending": "0",
- "accepted": "1",
- "rejected": "2"
- };
- const event_type = {
- "exam": "0",
- "test": "1",
- "event": "2",
- "class": "3",
- "other": "4",
- "special_reservation": "5"
- };
- const event_color = {
- "new_event": "#ffc0cb",
- "invisible": "#d3bb5a",
- "user_is_author": "#8ed35a",
- "pending": "#ff0",
- "accepted": "#0f0",
- "rejected": "#f00",
- // Type colors are used to mark events
- "type_test": "#539CDB",
- "type_exam": "#0588FA",
- "type_event": "#0423B0",
- "type_special_reservation": "#223487",
- "type_class": "#121F59"
- };
- async function fetchEvents(fetchInfo) {
- let url = new URL("classrooms/terms/", window.location.origin);
- url.searchParams.set("start", fetchInfo.start.toISOString());
- url.searchParams.set("end", fetchInfo.end.toISOString());
- let room_id = $('#room_selector').val();
- if (room_id == "all")
- url.searchParams.delete('rooms');
- else
- url.searchParams.set("rooms", [room_id]);
- let title_author_input = $('#title_author_input').val();
- if (title_author_input)
- url.searchParams.set("title_author", title_author_input);
- var types = [];
- if ($('#exam_checkbox').is(':checked')) types.push(event_type.exam);
- if ($('#test_checkbox').is(':checked')) types.push(event_type.test);
- if ($('#event_checkbox').is(':checked')) types.push(event_type.event);
- if ($('#classes_checkbox').is(':checked')) types.push(event_type.class);
- if ($('#other_checkbox').is(':checked')) types.push(event_type.other);
- if ($('#special_reservation_checkbox').is(':checked')) types.push(event_type.special_reservation);
- if (types.length > 0)
- url.searchParams.set("types", types);
- else
- return [];
- var fetchedEvents = $.getJSON(url, function (data) {
- for (var i = 0; i < data.length; i++) {
- // Set colors for fetched events
- switch (data[i]['type']) {
- case event_type.exam: data[i]['color'] = event_color.type_exam; break;
- case event_type.test: data[i]['color'] = event_color.type_test; break;
- case event_type.event: data[i]['color'] = event_color.type_event; break;
- case event_type.class: data[i]['color'] = event_color.type_class; break;
- case event_type.other: data[i]['color'] = event_color.type_other; break;
- case event_type.special_reservation: data[i]['color'] = event_color.type_special_reservation; break;
- }
- if(data[i]['visible'] == false)
- data[i]['color'] = event_color.invisible;
- switch (data[i]['status']) {
- case event_status.pending: data[i]['borderColor'] = event_color.pending; break;
- case event_status.accepted: data[i]['borderColor'] = event_color.accepted; break;
- case event_status.rejected: data[i]['borderColor'] = event_color.rejected; break;
- }
- }
- });
- return fetchedEvents;
- }
- export default {
- components: {
- FullCalendar, // make the <FullCalendar> tag available
- Reservation
- },
- data() {
- return {
- modalShow: true,
- calendarOptions: {
- plugins: [ interactionPlugin, timeGridPlugin, dayGridPlugin, bootstrapPlugin ],
- // Default settings for FullCalendar
- themeSystem: "bootstrap",
- eventDisplay: 'block',
- initialView: "timeGridWeek",
- locale: plLocale,
- timeZone: "UTC",
- height: "auto",
- // Allow clicking in day and week names, determine time range displayed
- navLinks: true,
- allDaySlot: false,
- slotMinTime: "08:00:00",
- slotMaxTime: "22:00:00",
- nowIndicator: true,
- // Define which buttons should be displayed for navigation and calendar display types
- headerToolbar: {
- start: "prev,next today",
- center: "title",
- end: "timeGridDay,timeGridWeek,dayGridMonth",
- },
- // buttonText is a text displayed in "prev" and "next" keys, these are arrows empty inside
- buttonText: {
- prev: "\u25C1",
- next: "\u25B7",
- },
- // Display date in format day - full month name - year
- titleFormat: {
- day: "numeric",
- month: "long",
- year: "numeric"
- },
- // events are fetched from database using function fetchEvents (defined above)
- events: fetchEvents,
- // Allow for selecting hours in the calendar to create events, print the block
- // showing that event. 'select' and 'eventClick' are references to Vue app
- // 'reservation' functions for creating and editing/viewing events.
- selectable: true,
- selectMirror: true,
- select: this.showCreateModal,
- }
- }
- },
- methods: {
- showModal(){
- console.log("showModal");
- },
- showCreateModal(){
- this.$refs.childComponent.writeSth();
- },
- showEditModal(){
- //this.$broadcast('showEditModal');
- //console.log("showEditModal");
- },
- },
- }
- </script>
- <template>
- <div>
- <Reservation ref="childComponent"/>
- <FullCalendar :options="calendarOptions" />
- </div>
- </template>