2024-08-11 14:18:36 +02:00
|
|
|
import {Controller} from "@hotwired/stimulus"
|
|
|
|
|
// Connects to data-controller="main-calendar"
|
|
|
|
|
|
|
|
|
|
export default class extends Controller {
|
|
|
|
|
connect() {
|
2024-08-24 07:06:09 +02:00
|
|
|
const calendar = new tui.Calendar(document.getElementById('main-calendar'), {
|
2024-08-11 14:18:36 +02:00
|
|
|
defaultView: 'week',
|
|
|
|
|
usageStatistics: false,
|
|
|
|
|
week: {
|
|
|
|
|
taskView: false,
|
2024-08-24 07:06:09 +02:00
|
|
|
scheduleView: false,
|
|
|
|
|
eventView: ['time'],
|
|
|
|
|
hourStart: 4,
|
|
|
|
|
hourEnd: 21,
|
|
|
|
|
},
|
|
|
|
|
template: {
|
|
|
|
|
timegridDisplayPrimaryTime({time}) {
|
|
|
|
|
return `${time.getHours()} sati`;
|
|
|
|
|
}
|
2024-08-11 14:18:36 +02:00
|
|
|
},
|
|
|
|
|
calendars: [
|
|
|
|
|
{
|
|
|
|
|
id: 'cal1',
|
|
|
|
|
name: 'Work',
|
|
|
|
|
backgroundColor: '#00a9ff',
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
});
|
|
|
|
|
|
2024-09-08 14:00:15 +02:00
|
|
|
window.calendar = calendar;
|
2024-08-24 07:06:09 +02:00
|
|
|
this.getCalendardata();
|
2024-08-11 14:18:36 +02:00
|
|
|
calendar.render();
|
|
|
|
|
}
|
2024-08-24 07:06:09 +02:00
|
|
|
|
|
|
|
|
getCalendardata() {
|
|
|
|
|
var reservations = JSON.parse(document.querySelector("#main-calendar").dataset.reservations);
|
|
|
|
|
window.reservations = reservations;
|
|
|
|
|
reservations.forEach(reservation => {
|
2024-09-08 14:00:15 +02:00
|
|
|
window.calendar.createEvents([
|
2024-08-24 07:06:09 +02:00
|
|
|
{
|
|
|
|
|
id: reservation.id,
|
|
|
|
|
calendarId: 'cal1',
|
2024-09-08 14:00:15 +02:00
|
|
|
title: reservation.customer.name,
|
2024-08-24 07:06:09 +02:00
|
|
|
category: 'time',
|
|
|
|
|
dueDateClass: reservation.dueDateClass,
|
|
|
|
|
location: reservation.team.name,
|
|
|
|
|
start: reservation.start_time,
|
|
|
|
|
end: reservation.end_time
|
|
|
|
|
}
|
|
|
|
|
])
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-08-11 14:18:36 +02:00
|
|
|
}
|