function calendar(events = '', list) { if (window.dp) { window.dp.dispose(); } var type = "{{ $type }}"; window.dp = new DayPilot.Calendar("scheduleCalendar", { rtl: true, startDate: DayPilot.Date.today(), viewType: "Resources", columnWidthSpec: "Fixed", headerLevels: 2, heightSpec: "BusinessHoursNoScroll", height: 800, // columnWidth: 100, businessBeginsHour: 7, businessEndsHour: 17, timeHeaderCellDuration: 15, cellDuration: 15, events: events, columns: list.map(column => { return { name: `${column.name}`, id: column.id, children: column.children.map(child => ({ id: child.id, name: `
${child.first_name ?? '-'}
${child.family_name ?? '-'}
${child.profession ?? '-'}
${child.association ?? '-'}
` })), }; }), onBeforeTimeHeaderRender: function (args) { var hour = DayPilot.Date.today().addTime(args.header.time); args.header.html = hour.toString("HH:mm"); }, onTimeRangeSelected: async args => { if (type == 'view') { dp.clearSelection(); } else { if (args.resource == '' || args.resource == undefined || args.resource == null) { toastr.error("The chosen resource dosen't have any user"); return true; } const resource = args.resource.match(/^(\d+)([a-zA-Z]+)$/); Object.keys(eventData).forEach(key => delete eventData[key]); eventData.day = resource[2].charAt(0).toUpperCase() + resource[2].slice(1); eventData.resource = args.resource; eventData.startTime = args.start.value.split("T")[1].slice(0, 5); eventData.endTime = args.end.value.split("T")[1].slice(0, 5); eventData.therapistIds = [resource[1]]; eventData.mode = 'create'; $('#eventTypeModal').modal('toggle'); } }, onBeforeEventRender: function (args) { let title = ''; function eventName(fullNames) { return fullNames.split(", ").map(fullName => { const nameParts = fullName.trim().split(" "); const firstName = nameParts[0]; const lastNameInitial = nameParts.length > 1 ? nameParts[1][0] : ""; return `${firstName} ${lastNameInitial}`; }).join(", "); } let cellTitle = args.data.type.split('-').map((item, index) => item[0].toUpperCase() + '' + item.slice(1)).join(' '); switch (args.data.type) { case 'staff-meeting': title = 'Staff Meeting: ' + eventName(args.data.twoChildrenNames); break; case 'group': title = args.data.groupName + ': ' + eventName(args.data.twoChildrenNames); break; case 'individual': title = `

${eventName(args.data.twoChildrenNames)}

`; break; case 'parental-guidance': title = `

${eventName(args.data.twoChildrenNames)}

`; break; default: title = cellTitle; break; } function escapeJson(json) { return JSON.stringify(json).replace(/'/g, '''); } args.data.html = `
${args.data.start.toString("HH:mm")}
${title}
${type === 'create' ? `
   
` : ''}
`; args.data.bubbleHtml = `
`; }, headerHeightAutoFit: true, showCurrentTime: false }); dp.init(); const app = { elements: { export: document.getElementById("export"), exportButton: document.getElementById("export-button"), downloadButton: document.getElementById("download-button"), area: document.getElementById("area"), }, init: function (events) { this.elements.exportButton.addEventListener("click", (ev) => { ev.preventDefault(); const area = this.elements.area.value; const element = dp.exportAs("jpeg", { area: area, }).toElement(); app.elements.export.innerHTML = ''; app.elements.export.appendChild(element); }); this.elements.downloadButton.addEventListener("click", (ev) => { ev.preventDefault(); const area = this.elements.area.value; dp.exportAs("svg", { area: area, }).download(); }); this.loadEventData(events); }, loadEventData(events) { dp.update({ events }); } }; app.init(events); }