Skip to content

Commit 1934c8b

Browse files
Scheduler — Replace underscore-prefixed: m_tooltip_strategy_base.ts (#32981)
1 parent e518f42 commit 1934c8b

7 files changed

Lines changed: 288 additions & 255 deletions

File tree

packages/devextreme/js/__internal/scheduler/tooltip_strategies/m_desktop_tooltip_strategy.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,49 +8,49 @@ const APPOINTMENT_TOOLTIP_WRAPPER_CLASS = 'dx-scheduler-appointment-tooltip-wrap
88
const MAX_TOOLTIP_HEIGHT = 200;
99

1010
export class DesktopTooltipStrategy extends TooltipStrategyBase {
11-
_prepareBeforeVisibleChanged(dataList) {
12-
this._tooltip.option('position', {
11+
protected override prepareBeforeVisibleChanged(dataList) {
12+
this.tooltip.option('position', {
1313
my: 'bottom',
1414
at: 'top',
15-
boundary: this._getBoundary(dataList),
16-
offset: this._extraOptions.offset,
15+
boundary: this.getBoundary(dataList),
16+
offset: this.extraOptions.offset,
1717
collision: 'fit flipfit',
1818
});
1919
}
2020

21-
_getBoundary(dataList) {
21+
private getBoundary(dataList) {
2222
return this._options.isAppointmentInAllDayPanel(dataList[0].appointment) ? this._options.container : this._options.getScrollableContainer();
2323
}
2424

25-
_onShown() {
26-
super._onShown();
27-
if (this._extraOptions.isButtonClick) {
28-
this._list.focus();
29-
this._list.option('focusedElement', null);
25+
protected override onShown() {
26+
super.onShown();
27+
if (this.extraOptions.isButtonClick) {
28+
this.list.focus();
29+
this.list.option('focusedElement', null);
3030
}
3131
}
3232

3333
// @ts-expect-error
34-
_createListOption(target, dataList) {
34+
protected override createListOption(target, dataList) {
3535
// @ts-expect-error
36-
const result: any = super._createListOption(target, dataList);
36+
const result: any = super.createListOption(target, dataList);
3737
// T724287 this condition is not covered by tests, because touch variable cannot be overridden.
3838
// In the future, it is necessary to cover the tests
3939
result.showScrollbar = supportUtils.touch ? 'always' : 'onHover';
4040
return result;
4141
}
4242

43-
_createTooltip(target, dataList) {
44-
const tooltipElement = this._createTooltipElement(APPOINTMENT_TOOLTIP_WRAPPER_CLASS);
43+
protected override createTooltip(target, dataList) {
44+
const tooltipElement = this.createTooltipElement(APPOINTMENT_TOOLTIP_WRAPPER_CLASS);
4545

4646
const tooltip = this._options.createComponent(tooltipElement, Tooltip, {
4747
target,
4848
maxHeight: MAX_TOOLTIP_HEIGHT,
49-
rtlEnabled: this._extraOptions.rtlEnabled,
50-
onShown: this._onShown.bind(this),
51-
contentTemplate: this._getContentTemplate(dataList),
49+
rtlEnabled: this.extraOptions.rtlEnabled,
50+
onShown: this.onShown.bind(this),
51+
contentTemplate: this.getContentTemplate(dataList),
5252
wrapperAttr: { class: APPOINTMENT_TOOLTIP_WRAPPER_CLASS },
53-
_loopFocus: this._extraOptions._loopFocus,
53+
_loopFocus: this.extraOptions._loopFocus,
5454
});
5555

5656
tooltip.setAria({
@@ -61,11 +61,11 @@ export class DesktopTooltipStrategy extends TooltipStrategyBase {
6161
return tooltip;
6262
}
6363

64-
_onListRender(e) {
65-
return this._extraOptions.dragBehavior && this._extraOptions.dragBehavior(e);
64+
protected override onListRender(e) {
65+
return this.extraOptions.dragBehavior && this.extraOptions.dragBehavior(e);
6666
}
6767

68-
_onListItemContextMenu(e) {
68+
protected override onListItemContextMenu(e) {
6969
const contextMenuEventArgs = this._options.createEventArgs(e);
7070
this._options.onItemContextMenu(contextMenuEventArgs);
7171
}

packages/devextreme/js/__internal/scheduler/tooltip_strategies/m_mobile_tooltip_strategy.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,23 +64,23 @@ const createTabletDeviceConfig = (listHeight) => {
6464
};
6565

6666
export class MobileTooltipStrategy extends TooltipStrategyBase {
67-
_shouldUseTarget() {
67+
protected override shouldUseTarget() {
6868
return false;
6969
}
7070

7171
private setTooltipConfig(): void {
7272
const isTabletWidth = getWidth(getWindow()) > 700;
7373

74-
const listHeight = getOuterHeight(this._list.$element().find(CLASS.scrollableContent));
75-
this._tooltip.option(
74+
const listHeight = getOuterHeight(this.list.$element().find(CLASS.scrollableContent));
75+
this.tooltip.option(
7676
isTabletWidth
7777
? createTabletDeviceConfig(listHeight)
7878
: createPhoneDeviceConfig(listHeight),
7979
);
8080
}
8181

82-
private async _onShowing(): Promise<void> {
83-
this._tooltip.option('height', MAX_HEIGHT.DEFAULT);
82+
private async onShowing(): Promise<void> {
83+
this.tooltip.option('height', MAX_HEIGHT.DEFAULT);
8484
/*
8585
NOTE: there are two setTooltipConfig calls to reduce blinking of overlay.
8686
The first one sets initial sizes, the second updates them after rendering async templates
@@ -91,17 +91,17 @@ export class MobileTooltipStrategy extends TooltipStrategyBase {
9191
this.setTooltipConfig();
9292
}
9393

94-
_createTooltip(target, dataList) {
95-
const element = this._createTooltipElement(CLASS.slidePanel);
94+
protected override createTooltip(target, dataList) {
95+
const element = this.createTooltipElement(CLASS.slidePanel);
9696

9797
return this._options.createComponent(element, Overlay, {
9898
target: getWindow(),
9999
hideOnOutsideClick: true,
100100
animation: animationConfig,
101101

102-
onShowing: () => this._onShowing(),
103-
onShown: this._onShown.bind(this),
104-
contentTemplate: this._getContentTemplate(dataList),
102+
onShowing: () => this.onShowing(),
103+
onShown: this.onShown.bind(this),
104+
contentTemplate: this.getContentTemplate(dataList),
105105
wrapperAttr: { class: CLASS.slidePanel },
106106
});
107107
}

packages/devextreme/js/__internal/scheduler/tooltip_strategies/m_tooltip_strategy_base.ts

Lines changed: 78 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -20,121 +20,145 @@ const APPOINTMENT_TOOLTIP_TEMPLATE = 'appointmentTooltipTemplate';
2020
export 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

Comments
 (0)