11import { inheritHtmlElement , registerComponent } from "#core:utils/web-components" ;
22import {
33 Calendar ,
4+ type DateSelectArg ,
45 type EventDropArg ,
56 type EventSourceFuncArg ,
67} from "@fullcalendar/core" ;
@@ -18,6 +19,7 @@ import {
1819import { paginated } from "#core:utils/api" ;
1920import interactionPlugin from "@fullcalendar/interaction" ;
2021import resourceTimelinePlugin from "@fullcalendar/resource-timeline" ;
22+ import type { SlotSelectedEventArg } from "#reservation:reservation/types" ;
2123
2224@registerComponent ( "room-scheduler" )
2325export class RoomScheduler extends inheritHtmlElement ( "div" ) {
@@ -26,6 +28,7 @@ export class RoomScheduler extends inheritHtmlElement("div") {
2628 private locale = "en" ;
2729 private canEditSlot = false ;
2830 private canBookSlot = false ;
31+ private canDeleteSlot = false ;
2932
3033 attributeChangedCallback ( name : string , _oldValue ?: string , newValue ?: string ) {
3134 if ( name === "locale" ) {
@@ -37,6 +40,9 @@ export class RoomScheduler extends inheritHtmlElement("div") {
3740 if ( name === "can_create_slot" ) {
3841 this . canBookSlot = newValue . toLowerCase ( ) === "true" ;
3942 }
43+ if ( name === "can_delete_slot" ) {
44+ this . canDeleteSlot = newValue . toLowerCase ( ) === "true" ;
45+ }
4046 }
4147
4248 /**
@@ -84,6 +90,18 @@ export class RoomScheduler extends inheritHtmlElement("div") {
8490 }
8591 }
8692
93+ selectFreeSlot ( infos : DateSelectArg ) {
94+ document . dispatchEvent (
95+ new CustomEvent < SlotSelectedEventArg > ( "timeSlotSelected" , {
96+ detail : {
97+ ressource : Number . parseInt ( infos . resource . id ) ,
98+ start : infos . startStr ,
99+ end : infos . endStr ,
100+ } ,
101+ } ) ,
102+ ) ;
103+ }
104+
87105 connectedCallback ( ) {
88106 super . connectedCallback ( ) ;
89107 this . scheduler = new Calendar ( this . node , {
@@ -109,6 +127,7 @@ export class RoomScheduler extends inheritHtmlElement("div") {
109127 resourceAreaWidth : "20%" ,
110128 resources : this . fetchResources ,
111129 events : this . fetchEvents ,
130+ select : this . selectFreeSlot ,
112131 selectOverlap : false ,
113132 selectable : this . canBookSlot ,
114133 selectConstraint : { start : new Date ( ) } ,
0 commit comments