Skip to content

Commit 5ee32cb

Browse files
Scheduler - Add onSelectionEnd event
1 parent 8ca5272 commit 5ee32cb

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

packages/devextreme/js/__internal/scheduler/m_scheduler.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ class Scheduler extends SchedulerOptionsBaseWidget {
421421
case StoreEventNames.DELETED:
422422
case 'onAppointmentFormOpening':
423423
case 'onAppointmentTooltipShowing':
424+
case 'onSelectionEnd':
424425
this.actions[name] = this._createActionByOption(name);
425426
break;
426427
case 'onAppointmentRendered':
@@ -1007,6 +1008,7 @@ class Scheduler extends SchedulerOptionsBaseWidget {
10071008
onAppointmentDeleted: this._createActionByOption(StoreEventNames.DELETED),
10081009
onAppointmentFormOpening: this._createActionByOption('onAppointmentFormOpening'),
10091010
onAppointmentTooltipShowing: this._createActionByOption('onAppointmentTooltipShowing'),
1011+
onSelectionEnd: this._createActionByOption('onSelectionEnd'),
10101012
};
10111013
}
10121014

@@ -1468,6 +1470,13 @@ class Scheduler extends SchedulerOptionsBaseWidget {
14681470
onSelectionChanged: (args) => {
14691471
this.option('selectedCellData', args.selectedCellData);
14701472
},
1473+
onSelectionEnd: (args) => {
1474+
this.actions.onSelectionEnd({
1475+
component: this,
1476+
element: this.$element(),
1477+
selectedCellData: args.selectedCellData,
1478+
});
1479+
},
14711480
groupByDate: this.getViewOption('groupByDate'),
14721481
skippedDays: this.getViewOption('hiddenWeekDays') as number[],
14731482
scrolling,

packages/devextreme/js/__internal/scheduler/workspaces/m_work_space.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ const SCHEDULER_CELL_DXCLICK_EVENT_NAME = addNamespace(clickEventName, 'dxSchedu
171171

172172
const SCHEDULER_CELL_DXPOINTERDOWN_EVENT_NAME = addNamespace(pointerEvents.down, 'dxSchedulerDateTable');
173173
const SCHEDULER_CELL_DXPOINTERUP_EVENT_NAME = addNamespace(pointerEvents.up, 'dxSchedulerDateTable');
174+
const SCHEDULER_TABLE_DXPOINTERUP_EVENT_NAME = addNamespace(pointerEvents.up, 'dxSchedulerTable');
174175

175176
const SCHEDULER_CELL_DXPOINTERMOVE_EVENT_NAME = addNamespace(pointerEvents.move, 'dxSchedulerDateTable');
176177

@@ -221,6 +222,10 @@ class SchedulerWorkSpace extends Widget<WorkspaceOptionsInternal> {
221222

222223
private selectionChangedAction: any;
223224

225+
private selectionEndAction: any;
226+
227+
private isSelectionStartedOnCell = false;
228+
224229
private isCellClick: any;
225230

226231
private contextMenuHandled: any;
@@ -986,6 +991,7 @@ class SchedulerWorkSpace extends Widget<WorkspaceOptionsInternal> {
986991

987992
protected attachEvents() {
988993
this.createSelectionChangedAction();
994+
this.createSelectionEndAction();
989995
this.attachClickEvent();
990996
this.attachContextMenuEvent();
991997
}
@@ -1014,6 +1020,14 @@ class SchedulerWorkSpace extends Widget<WorkspaceOptionsInternal> {
10141020
const $cell = $(e.target);
10151021
that.cellClickAction({ event: e, cellElement: getPublicElement($cell), cellData: that.getCellData($cell) });
10161022
});
1023+
1024+
(eventsEngine.off as any)(domAdapter.getDocument(), SCHEDULER_TABLE_DXPOINTERUP_EVENT_NAME);
1025+
eventsEngine.on(domAdapter.getDocument(), SCHEDULER_TABLE_DXPOINTERUP_EVENT_NAME, () => {
1026+
if (this.isSelectionStartedOnCell) {
1027+
this.fireSelectionEndEvent();
1028+
this.isSelectionStartedOnCell = false;
1029+
}
1030+
});
10171031
}
10181032

10191033
private createCellClickAction() {
@@ -1026,10 +1040,15 @@ class SchedulerWorkSpace extends Widget<WorkspaceOptionsInternal> {
10261040
this.selectionChangedAction = this._createActionByOption('onSelectionChanged');
10271041
}
10281042

1043+
private createSelectionEndAction() {
1044+
this.selectionEndAction = this._createActionByOption('onSelectionEnd');
1045+
}
1046+
10291047
// eslint-disable-next-line @typescript-eslint/no-unused-vars
10301048
private cellClickHandler(argument?: any) {
10311049
if (this.showPopup) {
10321050
delete this.showPopup;
1051+
this.isSelectionStartedOnCell = false;
10331052
this.handleSelectedCellsClick();
10341053
}
10351054
}
@@ -1039,10 +1058,12 @@ class SchedulerWorkSpace extends Widget<WorkspaceOptionsInternal> {
10391058

10401059
if (!$target.hasClass(DATE_TABLE_CELL_CLASS) && !$target.hasClass(ALL_DAY_TABLE_CELL_CLASS)) {
10411060
this.isCellClick = false;
1061+
this.isSelectionStartedOnCell = false;
10421062
return;
10431063
}
10441064

10451065
this.isCellClick = true;
1066+
this.isSelectionStartedOnCell = true;
10461067
if ($target.hasClass(DATE_TABLE_FOCUSED_CELL_CLASS)) {
10471068
this.showPopup = true;
10481069
} else {
@@ -1932,6 +1953,13 @@ class SchedulerWorkSpace extends Widget<WorkspaceOptionsInternal> {
19321953
this.selectionChangedAction({ selectedCellData });
19331954
}
19341955

1956+
private fireSelectionEndEvent() {
1957+
const selectedCellData = this.option('selectedCellData') ?? [];
1958+
if (selectedCellData.length > 0 && this.selectionEndAction) {
1959+
this.selectionEndAction({ selectedCellData });
1960+
}
1961+
}
1962+
19351963
private getCellByData(cellData) {
19361964
const {
19371965
startDate, groupIndex, allDay, index,
@@ -2370,6 +2398,9 @@ class SchedulerWorkSpace extends Widget<WorkspaceOptionsInternal> {
23702398
case 'onSelectionChanged':
23712399
this.createSelectionChangedAction();
23722400
break;
2401+
case 'onSelectionEnd':
2402+
this.createSelectionEndAction();
2403+
break;
23732404
case 'onCellClick':
23742405
this.createCellClickAction();
23752406
break;

0 commit comments

Comments
 (0)