@@ -20,121 +20,145 @@ const APPOINTMENT_TOOLTIP_TEMPLATE = 'appointmentTooltipTemplate';
2020export class TooltipStrategyBase {
2121 protected asyncTemplatePromises = new Set < Promise < void > > ( ) ;
2222
23- _tooltip : any ;
23+ protected tooltip : any ;
2424
25+ // TODO: make private once external usages in m_scheduler.ts are removed
2526 _options : any ;
2627
27- _extraOptions : any ;
28+ protected extraOptions : any ;
2829
29- _list : any ;
30+ protected list : any ;
3031
3132 constructor ( options ) {
32- this . _tooltip = null ;
33+ this . tooltip = null ;
3334 this . _options = options ;
34- this . _extraOptions = null ;
35+ this . extraOptions = null ;
3536 }
3637
3738 show ( target , dataList , extraOptions ) {
38- if ( this . _canShowTooltip ( dataList ) ) {
39+ if ( this . canShowTooltip ( dataList ) ) {
3940 this . hide ( ) ;
40- this . _extraOptions = extraOptions ;
41- this . _showCore ( target , dataList ) ;
41+ this . extraOptions = extraOptions ;
42+ this . showCore ( target , dataList ) ;
4243 }
4344 }
4445
45- _showCore ( target , dataList ) {
46+ private showCore ( target , dataList ) {
4647 const describedByValue = isRenderer ( target ) && target . attr ( 'aria-describedby' ) as string ;
4748
48- if ( ! this . _tooltip ) {
49- this . _tooltip = this . _createTooltip ( target , dataList ) ;
49+ if ( ! this . tooltip ) {
50+ this . tooltip = this . createTooltip ( target , dataList ) ;
5051 } else {
51- this . _shouldUseTarget ( ) && this . _tooltip . option ( 'target' , target ) ;
52- this . _list . option ( 'dataSource' , dataList ) ;
52+ this . shouldUseTarget ( ) && this . tooltip . option ( 'target' , target ) ;
53+ this . list . option ( 'dataSource' , dataList ) ;
5354 }
5455
55- this . _prepareBeforeVisibleChanged ( dataList ) ;
56- this . _tooltip . option ( 'visible' , true ) ;
56+ this . prepareBeforeVisibleChanged ( dataList ) ;
57+ this . tooltip . option ( 'visible' , true ) ;
5758
5859 describedByValue && target . attr ( 'aria-describedby' , describedByValue ) ;
5960 }
6061
6162 // eslint-disable-next-line @typescript-eslint/no-unused-vars
62- _prepareBeforeVisibleChanged ( dataList ) {
63+ protected prepareBeforeVisibleChanged ( dataList ) {
6364
6465 }
6566
66- _getContentTemplate ( dataList ) {
67+ private isDeletingAllowed ( appointment ) {
68+ const { editing } = this . extraOptions ;
69+ const disabled = this . _options . getAppointmentDisabled ( appointment ) ;
70+ const isDeletingAllowed = editing === true || editing ?. allowDeleting === true ;
71+ return ! disabled && isDeletingAllowed ;
72+ }
73+
74+ protected getContentTemplate ( dataList ) {
6775 return ( container ) => {
6876 const listElement = $ ( '<div>' ) ;
6977 $ ( container ) . append ( listElement ) ;
70- this . _list = this . _createList ( listElement , dataList ) ;
71- this . _list . registerKeyHandler ?.( 'escape' , ( ) => {
78+ this . list = this . createList ( listElement , dataList ) ;
79+ this . list . registerKeyHandler ?.( 'escape' , ( ) => {
7280 this . hide ( ) ;
73- this . _tooltip . option ( 'target' ) . focus ( ) ;
81+ this . tooltip . option ( 'target' ) . focus ( ) ;
82+ } ) ;
83+ this . list . registerKeyHandler ?.( 'del' , ( ) => {
84+ const { focusedElement } = this . list . option ( ) ;
85+ if ( ! focusedElement ) {
86+ return ;
87+ }
88+
89+ const { appointment, targetedAppointment } = this . list . _getItemData ( focusedElement ) ;
90+ if ( ! appointment ) {
91+ return ;
92+ }
93+
94+ if ( this . isDeletingAllowed ( appointment ) ) {
95+ this . hide ( ) ;
96+ this . _options . checkAndDeleteAppointment ( appointment , targetedAppointment ) ;
97+ }
7498 } ) ;
7599 } ;
76100 }
77101
78102 isAlreadyShown ( target ) {
79- if ( this . _tooltip && this . _tooltip . option ( 'visible' ) ) {
80- return this . _tooltip . option ( 'target' ) [ 0 ] === target [ 0 ] ;
103+ if ( this . tooltip && this . tooltip . option ( 'visible' ) ) {
104+ return this . tooltip . option ( 'target' ) [ 0 ] === target [ 0 ] ;
81105 }
82106 return undefined ;
83107 }
84108
85- _onShown ( ) {
86- this . _list . option ( 'focusStateEnabled' , this . _extraOptions . focusStateEnabled ) ;
109+ protected onShown ( ) {
110+ this . list . option ( 'focusStateEnabled' , this . extraOptions . focusStateEnabled ) ;
87111 }
88112
89113 dispose ( ) {
90114 }
91115
92116 hide ( ) {
93- if ( this . _tooltip ) {
94- this . _tooltip . option ( 'visible' , false ) ;
117+ if ( this . tooltip ) {
118+ this . tooltip . option ( 'visible' , false ) ;
95119 }
96120 }
97121
98- _shouldUseTarget ( ) {
122+ protected shouldUseTarget ( ) {
99123 return true ;
100124 }
101125
102126 // eslint-disable-next-line @typescript-eslint/no-unused-vars
103- _createTooltip ( target , dataList ) {
127+ protected createTooltip ( target , dataList ) {
104128 }
105129
106- _canShowTooltip ( dataList ) {
130+ private canShowTooltip ( dataList ) {
107131 if ( ! dataList . length ) {
108132 return false ;
109133 }
110134 return true ;
111135 }
112136
113- _createListOption ( dataList ) {
137+ protected createListOption ( dataList ) {
114138 return {
115139 dataSource : dataList ,
116- onContentReady : this . _onListRender . bind ( this ) ,
117- onItemClick : ( e ) => this . _onListItemClick ( e ) ,
118- onItemContextMenu : this . _onListItemContextMenu . bind ( this ) ,
119- itemTemplate : ( item , index ) => this . _renderTemplate ( item . appointment , item . targetedAppointment , index , item . color ) ,
140+ onContentReady : this . onListRender . bind ( this ) ,
141+ onItemClick : ( e ) => this . onListItemClick ( e ) ,
142+ onItemContextMenu : this . onListItemContextMenu . bind ( this ) ,
143+ itemTemplate : ( item , index ) => this . renderTemplate ( item . appointment , item . targetedAppointment , index , item . color ) ,
120144 _swipeEnabled : false ,
121145 pageLoadMode : 'scrollBottom' ,
122146 } ;
123147 }
124148
125149 // eslint-disable-next-line @typescript-eslint/no-unused-vars
126- _onListRender ( e ) { }
150+ protected onListRender ( e ) { }
127151
128- _createTooltipElement ( wrapperClass ) {
152+ protected createTooltipElement ( wrapperClass ) {
129153 return $ ( '<div>' ) . appendTo ( this . _options . container ) . addClass ( wrapperClass ) ;
130154 }
131155
132- _createList ( listElement , dataList ) {
133- return this . _options . createComponent ( listElement , List , this . _createListOption ( dataList ) ) ;
156+ private createList ( listElement , dataList ) {
157+ return this . _options . createComponent ( listElement , List , this . createListOption ( dataList ) ) ;
134158 }
135159
136- _renderTemplate ( appointment , targetedAppointment , index , color ) {
137- const itemListContent = this . _createItemListContent ( appointment , targetedAppointment , color ) ;
160+ private renderTemplate ( appointment , targetedAppointment , index , color ) {
161+ const itemListContent = this . createItemListContent ( appointment , targetedAppointment , color ) ;
138162 this . _options . addDefaultTemplates ( {
139163 // @ts -expect-error
140164 appointmentTooltip : new FunctionTemplate ( ( options ) => {
@@ -145,11 +169,11 @@ export class TooltipStrategyBase {
145169 } ) ;
146170
147171 const template = this . _options . getAppointmentTemplate ( APPOINTMENT_TOOLTIP_TEMPLATE ) ;
148- return this . _createFunctionTemplate ( template , appointment , targetedAppointment , index ) ;
172+ return this . createFunctionTemplate ( template , appointment , targetedAppointment , index ) ;
149173 }
150174
151- _createFunctionTemplate ( template , appointmentData , targetedAppointmentData , index ) {
152- const isButtonClicked = Boolean ( this . _extraOptions . isButtonClick ) ;
175+ private createFunctionTemplate ( template , appointmentData , targetedAppointmentData , index ) {
176+ const isButtonClicked = Boolean ( this . extraOptions . isButtonClick ) ;
153177
154178 // @ts -expect-error
155179 return new FunctionTemplate ( ( options ) => {
@@ -172,31 +196,28 @@ export class TooltipStrategyBase {
172196 } ) ;
173197 }
174198
175- _onListItemClick ( e ) {
199+ private onListItemClick ( e ) {
176200 this . hide ( ) ;
177- this . _extraOptions . clickEvent && this . _extraOptions . clickEvent ( e ) ;
201+ this . extraOptions . clickEvent && this . extraOptions . clickEvent ( e ) ;
178202 this . _options . showAppointmentPopup ( e . itemData . appointment , false , e . itemData . targetedAppointment ) ;
179203 }
180204
181205 // eslint-disable-next-line @typescript-eslint/no-unused-vars
182- _onListItemContextMenu ( e ) { }
206+ protected onListItemContextMenu ( e ) { }
183207
184- _createItemListContent ( appointment , targetedAppointment , color ) {
185- const { editing } = this . _extraOptions ;
208+ private createItemListContent ( appointment , targetedAppointment , color ) {
186209 const $itemElement = $ ( '<div>' ) . addClass ( TOOLTIP_APPOINTMENT_ITEM ) ;
187- $itemElement . append ( this . _createItemListMarker ( color ) ) ;
188- $itemElement . append ( this . _createItemListInfo ( this . _options . createFormattedDateText ( appointment , targetedAppointment ) ) ) ;
189-
190- const disabled = this . _options . getAppointmentDisabled ( appointment ) ;
210+ $itemElement . append ( this . createItemListMarker ( color ) ) ;
211+ $itemElement . append ( this . createItemListInfo ( this . _options . createFormattedDateText ( appointment , targetedAppointment ) ) ) ;
191212
192- if ( ! disabled && ( editing && editing . allowDeleting === true || editing === true ) ) {
193- $itemElement . append ( this . _createDeleteButton ( appointment , targetedAppointment ) ) ;
213+ if ( this . isDeletingAllowed ( appointment ) ) {
214+ $itemElement . append ( this . createDeleteButton ( appointment , targetedAppointment ) ) ;
194215 }
195216
196217 return $itemElement ;
197218 }
198219
199- _createItemListMarker ( color ) {
220+ private createItemListMarker ( color ) {
200221 const $marker = $ ( '<div>' ) . addClass ( TOOLTIP_APPOINTMENT_ITEM_MARKER ) ;
201222 const $markerBody = $ ( '<div>' ) . addClass ( TOOLTIP_APPOINTMENT_ITEM_MARKER_BODY ) ;
202223
@@ -210,15 +231,15 @@ export class TooltipStrategyBase {
210231 return $marker ;
211232 }
212233
213- _createItemListInfo ( object ) {
234+ private createItemListInfo ( object ) {
214235 const result = $ ( '<div>' ) . addClass ( TOOLTIP_APPOINTMENT_ITEM_CONTENT ) ;
215236 const $title = $ ( '<div>' ) . addClass ( TOOLTIP_APPOINTMENT_ITEM_CONTENT_SUBJECT ) . text ( object . text ) ;
216237 const $date = $ ( '<div>' ) . addClass ( TOOLTIP_APPOINTMENT_ITEM_CONTENT_DATE ) . text ( object . formatDate ) ;
217238
218239 return result . append ( $title ) . append ( $date ) ;
219240 }
220241
221- _createDeleteButton ( appointment , targetedAppointment ) {
242+ private createDeleteButton ( appointment , targetedAppointment ) {
222243 const $container = $ ( '<div>' ) . addClass ( TOOLTIP_APPOINTMENT_ITEM_DELETE_BUTTON_CONTAINER ) ;
223244 const $deleteButton = $ ( '<div>' ) . addClass ( TOOLTIP_APPOINTMENT_ITEM_DELETE_BUTTON ) ;
224245
0 commit comments