@@ -5,16 +5,22 @@ 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
13+ interface AppointmentsFocusControllerHandlers {
14+ onAppointmentEnterKeyDown : ( appointmentView : BaseAppointmentView , event : DxEvent ) => void ;
15+ }
16+
1117export class AppointmentsFocusController {
1218 private focusableSortedIndex = 0 ;
1319
1420 private needRestoreFocusIndex = - 1 ;
1521
16- private get sortedAppointments ( ) : SortedEntity [ ] {
17- return this . appointments . option ( ) . getSortedAppointments ( ) ;
22+ private get sortedItems ( ) : SortedEntity [ ] {
23+ return this . appointments . option ( ) . getSortedItems ( ) ;
1824 }
1925
2026 private get isVirtualScrolling ( ) : boolean {
@@ -25,7 +31,10 @@ export class AppointmentsFocusController {
2531 return this . appointments . option ( ) . tabIndex ;
2632 }
2733
28- constructor ( private readonly appointments : Appointments ) { }
34+ constructor (
35+ private readonly appointments : Appointments ,
36+ private readonly handlers : AppointmentsFocusControllerHandlers ,
37+ ) { }
2938
3039 public onViewItemClick ( viewItem : ViewItem ) : void {
3140 this . focusViewItem ( viewItem ) ;
@@ -50,8 +59,27 @@ export class AppointmentsFocusController {
5059 }
5160
5261 public onViewItemKeyDown ( viewItem : ViewItem , e : KeyboardKeyDownEvent ) : void {
53- if ( e . key === 'Tab' ) {
54- this . handleTabKeyDown ( e , viewItem . option ( ) . sortedIndex ) ;
62+ switch ( true ) {
63+ case e . key === 'Tab' :
64+ this . handleTabKeyDown ( e , viewItem . option ( ) . sortedIndex ) ;
65+ break ;
66+ case e . key === 'Delete' :
67+ this . handleDeleteKeyDown ( viewItem ) ;
68+ break ;
69+ case e . key === 'Home' :
70+ this . handleHomeKeyDown ( e ) ;
71+ break ;
72+ case e . key === 'End' :
73+ this . handleEndKeyDown ( e ) ;
74+ break ;
75+ case e . key === 'Enter' :
76+ this . handleEnterKeyDown ( viewItem , e ) ;
77+ break ;
78+ case e . key === ' ' :
79+ this . handleEnterKeyDown ( viewItem , e ) ;
80+ break ;
81+ default :
82+ break ;
5583 }
5684 }
5785
@@ -82,27 +110,69 @@ export class AppointmentsFocusController {
82110
83111 private handleTabKeyDown ( e : KeyboardKeyDownEvent , sortedIndex : number ) : void {
84112 const nextIndex = sortedIndex + ( e . shift ? - 1 : 1 ) ;
85- const nextItemData = this . sortedAppointments [ nextIndex ] ;
113+ const nextItemData = this . sortedItems [ nextIndex ] ;
86114
87115 if ( ! nextItemData ) {
88116 return ;
89117 }
90118
91119 e . originalEvent . preventDefault ( ) ;
92- this . focusByItemData ( nextItemData ) ;
120+ this . focusBySortedItem ( nextItemData ) ;
121+ }
122+
123+ private handleDeleteKeyDown ( viewItem : ViewItem ) : void {
124+ if ( viewItem instanceof AppointmentCollector ) { return ; }
125+
126+ const { allowDelete, onDeleteKeyPress } = this . appointments . option ( ) ;
127+ if ( ! allowDelete ) { return ; }
128+
129+ const appointmentViewItem = viewItem as BaseAppointmentView ;
130+ onDeleteKeyPress ( {
131+ appointmentData : appointmentViewItem . appointmentData ,
132+ targetedAppointmentData : appointmentViewItem . targetedAppointmentData ,
133+ } ) ;
134+ }
135+
136+ private handleHomeKeyDown ( e : KeyboardKeyDownEvent ) : void {
137+ const firstSortedItem = this . sortedItems [ 0 ] ;
138+ if ( firstSortedItem ) {
139+ e . originalEvent . preventDefault ( ) ;
140+ this . focusBySortedItem ( firstSortedItem ) ;
141+ }
142+ }
143+
144+ private handleEndKeyDown ( e : KeyboardKeyDownEvent ) : void {
145+ const lastSortedItem = this . sortedItems [ this . sortedItems . length - 1 ] ;
146+ if ( lastSortedItem ) {
147+ e . originalEvent . preventDefault ( ) ;
148+ this . focusBySortedItem ( lastSortedItem ) ;
149+ }
150+ }
151+
152+ private handleEnterKeyDown ( viewItem : ViewItem , e : KeyboardKeyDownEvent ) : void {
153+ e . originalEvent . preventDefault ( ) ;
154+
155+ if ( viewItem instanceof AppointmentCollector ) {
156+ return ;
157+ }
158+
159+ this . handlers . onAppointmentEnterKeyDown (
160+ viewItem as BaseAppointmentView ,
161+ e . originalEvent as DxEvent ,
162+ ) ;
93163 }
94164
95- private focusByItemData ( itemData : SortedEntity ) : void {
165+ private focusBySortedItem ( sortedItem : SortedEntity ) : void {
96166 if ( this . isVirtualScrolling ) {
97- this . scrollToItem ( itemData ) ;
167+ this . scrollToItem ( sortedItem ) ;
98168 }
99169
100- const viewItem = this . appointments . getViewItemBySortedIndex ( itemData . sortedIndex ) ;
170+ const viewItem = this . appointments . getViewItemBySortedIndex ( sortedItem . sortedIndex ) ;
101171
102172 if ( viewItem ) {
103173 this . focusViewItem ( viewItem ) ;
104174 } else if ( this . isVirtualScrolling ) {
105- this . needRestoreFocusIndex = itemData . sortedIndex ;
175+ this . needRestoreFocusIndex = sortedItem . sortedIndex ;
106176 }
107177 }
108178
@@ -111,19 +181,19 @@ export class AppointmentsFocusController {
111181 focus . trigger ( viewItem ?. $element ( ) ) ;
112182 }
113183
114- private scrollToItem ( itemData : SortedEntity ) : void {
184+ private scrollToItem ( sortedItem : SortedEntity ) : void {
115185 const { getStartViewDate, getResourceManager, scrollTo } = this . appointments . option ( ) ;
116186
117187 const date = new Date ( Math . max (
118188 getStartViewDate ( ) . getTime ( ) ,
119- itemData . source . startDate ,
189+ sortedItem . source . startDate ,
120190 ) ) ;
121191
122192 const group = getRawAppointmentGroupValues (
123- itemData . itemData ,
193+ sortedItem . itemData ,
124194 getResourceManager ( ) . resources ,
125195 ) ;
126196
127- scrollTo ( date , { group, allDay : itemData . allDay } ) ;
197+ scrollTo ( date , { group, allDay : sortedItem . allDay } ) ;
128198 }
129199}
0 commit comments