@@ -5,6 +5,8 @@ import { focus } from '@ts/events/m_short';
55
66import { getRawAppointmentGroupValues } from '../utils/resource_manager/appointment_groups_utils' ;
77import type { SortedEntity } from '../view_model/types' ;
8+ import type { BaseAppointmentView } from './appointment/base_appointment' ;
9+ import { AppointmentCollector } from './appointment_collector' ;
810import type { Appointments } from './appointments' ;
911import type { ViewItem } from './view_item' ;
1012
@@ -14,7 +16,7 @@ export class AppointmentsFocusController {
1416 private needRestoreFocusIndex = - 1 ;
1517
1618 private get sortedAppointments ( ) : SortedEntity [ ] {
17- return this . appointments . option ( ) . getSortedAppointments ( ) ;
19+ return this . appointments . option ( ) . getSortedItems ( ) ;
1820 }
1921
2022 private get isVirtualScrolling ( ) : boolean {
@@ -55,19 +57,19 @@ export class AppointmentsFocusController {
5557 this . handleTabKeyDown ( e , viewItem . option ( ) . sortedIndex ) ;
5658 break ;
5759 case e . key === 'Delete' :
58- this . handleDeleteKeyDown ( viewItem . option ( ) . sortedIndex ) ;
60+ this . handleDeleteKeyDown ( viewItem ) ;
5961 break ;
6062 case e . key === 'Home' :
61- this . handleHomeKeyDown ( ) ;
63+ this . handleHomeKeyDown ( e ) ;
6264 break ;
6365 case e . key === 'End' :
64- this . handleEndKeyDown ( ) ;
66+ this . handleEndKeyDown ( e ) ;
6567 break ;
6668 case e . key === 'Enter' :
67- this . handleEnterKeyDown ( viewItem . option ( ) . sortedIndex ) ;
69+ this . handleEnterKeyDown ( viewItem , e ) ;
6870 break ;
6971 case e . key === ' ' :
70- this . handleEnterKeyDown ( viewItem . option ( ) . sortedIndex ) ;
72+ this . handleEnterKeyDown ( viewItem , e ) ;
7173 break ;
7274 default :
7375 break ;
@@ -108,49 +110,64 @@ export class AppointmentsFocusController {
108110 }
109111
110112 e . originalEvent . preventDefault ( ) ;
111- this . focusByItemData ( nextItemData ) ;
113+ this . focusBySortedItem ( nextItemData ) ;
112114 }
113115
114- private handleDeleteKeyDown ( sortedIndex : number ) : void {
115- const { allowDelete, onDeleteKeyPress, getDataAccessor } = this . appointments . option ( ) ;
116- if ( ! allowDelete ) { return ; }
116+ private handleDeleteKeyDown ( viewItem : ViewItem ) : void {
117+ if ( viewItem instanceof AppointmentCollector ) { return ; }
117118
118- const entity = this . sortedAppointments [ sortedIndex ] ;
119- if ( ! entity ) { return ; }
119+ const { allowDelete , onDeleteKeyPress } = this . appointments . option ( ) ;
120+ if ( ! allowDelete ) { return ; }
120121
121- const occurrence = { ... entity . itemData } ;
122- getDataAccessor ( ) . set ( 'startDate' , occurrence , new Date ( entity . source . startDate ) ) ;
122+ const sortedItem = this . sortedAppointments [ viewItem . option ( ) . sortedIndex ] ;
123+ if ( ! sortedItem ) { return ; }
123124
124- onDeleteKeyPress ( { appointment : entity . itemData , occurrence } ) ;
125+ const appointmentViewItem = viewItem as BaseAppointmentView ;
126+ onDeleteKeyPress ( {
127+ appointmentData : sortedItem . itemData ,
128+ targetedAppointmentData : appointmentViewItem . targetedAppointmentData ,
129+ } ) ;
125130 }
126131
127- private handleHomeKeyDown ( ) : void {
128- const firstAppointment = this . sortedAppointments [ 0 ] ;
129- if ( firstAppointment ) { this . focusByItemData ( firstAppointment ) ; }
132+ private handleHomeKeyDown ( e : KeyboardKeyDownEvent ) : void {
133+ const firstSortedItem = this . sortedAppointments [ 0 ] ;
134+ if ( firstSortedItem ) {
135+ e . originalEvent . preventDefault ( ) ;
136+ this . focusBySortedItem ( firstSortedItem ) ;
137+ }
130138 }
131139
132- private handleEndKeyDown ( ) : void {
133- const lastAppointment = this . sortedAppointments [ this . sortedAppointments . length - 1 ] ;
134- if ( lastAppointment ) { this . focusByItemData ( lastAppointment ) ; }
140+ private handleEndKeyDown ( e : KeyboardKeyDownEvent ) : void {
141+ const lastSortedItem = this . sortedAppointments [ this . sortedAppointments . length - 1 ] ;
142+ if ( lastSortedItem ) {
143+ e . originalEvent . preventDefault ( ) ;
144+ this . focusBySortedItem ( lastSortedItem ) ;
145+ }
135146 }
136147
137- private handleEnterKeyDown ( sortedIndex : number ) : void {
148+ private handleEnterKeyDown ( viewItem : ViewItem , e : KeyboardKeyDownEvent ) : void {
138149 const { onItemActivate } = this . appointments . option ( ) ;
139- const entity = this . sortedAppointments [ sortedIndex ] ;
140- onItemActivate ( { data : entity ?. itemData , target : null } ) ;
150+ const sortedItem = this . sortedAppointments [ viewItem . option ( ) . sortedIndex ] ;
151+ if ( ! sortedItem ) { return ; }
152+ e . originalEvent . preventDefault ( ) ;
153+ const appointmentViewItem = viewItem as BaseAppointmentView ;
154+ onItemActivate ( {
155+ data : sortedItem . itemData ,
156+ targetedAppointmentData : appointmentViewItem . targetedAppointmentData ,
157+ } ) ;
141158 }
142159
143- private focusByItemData ( itemData : SortedEntity ) : void {
160+ private focusBySortedItem ( sortedItem : SortedEntity ) : void {
144161 if ( this . isVirtualScrolling ) {
145- this . scrollToItem ( itemData ) ;
162+ this . scrollToItem ( sortedItem ) ;
146163 }
147164
148- const viewItem = this . appointments . getViewItemBySortedIndex ( itemData . sortedIndex ) ;
165+ const viewItem = this . appointments . getViewItemBySortedIndex ( sortedItem . sortedIndex ) ;
149166
150167 if ( viewItem ) {
151168 this . focusViewItem ( viewItem ) ;
152169 } else if ( this . isVirtualScrolling ) {
153- this . needRestoreFocusIndex = itemData . sortedIndex ;
170+ this . needRestoreFocusIndex = sortedItem . sortedIndex ;
154171 }
155172 }
156173
@@ -159,19 +176,19 @@ export class AppointmentsFocusController {
159176 focus . trigger ( viewItem ?. $element ( ) ) ;
160177 }
161178
162- private scrollToItem ( itemData : SortedEntity ) : void {
179+ private scrollToItem ( sortedItem : SortedEntity ) : void {
163180 const { getStartViewDate, getResourceManager, scrollTo } = this . appointments . option ( ) ;
164181
165182 const date = new Date ( Math . max (
166183 getStartViewDate ( ) . getTime ( ) ,
167- itemData . source . startDate ,
184+ sortedItem . source . startDate ,
168185 ) ) ;
169186
170187 const group = getRawAppointmentGroupValues (
171- itemData . itemData ,
188+ sortedItem . itemData ,
172189 getResourceManager ( ) . resources ,
173190 ) ;
174191
175- scrollTo ( date , { group, allDay : itemData . allDay } ) ;
192+ scrollTo ( date , { group, allDay : sortedItem . allDay } ) ;
176193 }
177194}
0 commit comments