Skip to content

Commit 019186b

Browse files
committed
feat: partial refactoring 3
1 parent 3a0caf6 commit 019186b

5 files changed

Lines changed: 194 additions & 239 deletions

File tree

packages/devextreme/js/__internal/scheduler/appointment_popup/m_form.ts

Lines changed: 18 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -102,21 +102,6 @@ const createTimeZoneDataSource = (): DataSource => new DataSource({
102102

103103
const MAIN_GROUP_NAME = 'mainGroup';
104104

105-
/*
106-
MainForm
107-
- recurrenceExpr: 'FREQ=DAILY...'
108-
- Should update repeatEditors state (buttons and value) in these cases:
109-
1. repeat editor valueChanged
110-
2. repeat editor contentReady
111-
3. form.optionChange
112-
4. recurrence form saved
113-
- We don't update recurrenceExpr just when repeatEditor's value changed
114-
115-
RecurrenceForm
116-
- contains RecurrenceRule object
117-
- Should update formData.recurrenceExpr on MainForm when save is pressed
118-
*/
119-
120105
export class AppointmentForm {
121106
private readonly scheduler: any;
122107

@@ -142,9 +127,6 @@ export class AppointmentForm {
142127

143128
set formData(formData: Record<string, any>) {
144129
this.dxForm.option('formData', formData);
145-
146-
const repeatEditorValue = this.dxForm.getEditor(EDITOR_NAMES.repeat)?.option('value');
147-
this._recurrentForm.updateRecurrenceFormValues(repeatEditorValue, this.recurrenceRuleRaw);
148130
}
149131

150132
get startDate(): Date | null {
@@ -176,13 +158,11 @@ export class AppointmentForm {
176158
this.scheduler = scheduler;
177159
}
178160

179-
// TODO: remove this method
180-
reset(): void {
181-
if (this._dxForm) {
182-
const repeatEditor = this._dxForm.getEditor(EDITOR_NAMES.repeat);
183-
if (repeatEditor) {
184-
repeatEditor.option('value', 'never');
185-
}
161+
dispose(): void {
162+
this._dxForm?.dispose();
163+
this._dxForm = undefined;
164+
if (this._recurrentForm) {
165+
this._recurrentForm.dxForm = undefined;
186166
}
187167
}
188168

@@ -582,7 +562,7 @@ export class AppointmentForm {
582562
if (e.value === repeatNeverValue) {
583563
const { recurrenceRuleExpr } = this.scheduler.getDataAccessors().expr;
584564
this.dxForm.updateData(recurrenceRuleExpr, '');
585-
} else {
565+
} else if (e.event) {
586566
this.showRecurrenceGroup();
587567
}
588568
},
@@ -696,7 +676,6 @@ export class AppointmentForm {
696676
showRecurrenceGroup(): void {
697677
this._isRecurrenceFormVisible = true;
698678

699-
// TODO: it better to store these group elements in the class fields
700679
const $formElement = $(this.dxForm.element());
701680
const mainGroup = $formElement.find(`.${CLASSES.mainGroupClass}`);
702681
const recurrenceGroup = $formElement.find(`.${CLASSES.recurrenceGroup}`);
@@ -706,7 +685,11 @@ export class AppointmentForm {
706685

707686
const repeatEditorValue = this.dxForm.getEditor(EDITOR_NAMES.repeat)?.option('value');
708687

709-
this._recurrentForm.updateRecurrenceFormValues(repeatEditorValue, this.recurrenceRuleRaw);
688+
this._recurrentForm.updateRecurrenceFormValues(
689+
repeatEditorValue,
690+
this.recurrenceRuleRaw,
691+
this.startDate,
692+
);
710693

711694
this._popup.updateToolbarForRecurrenceGroup();
712695
}
@@ -724,30 +707,14 @@ export class AppointmentForm {
724707
this._isRecurrenceFormVisible = false;
725708

726709
if (saveRecurrenceValue) {
710+
const { recurrenceRule } = this._recurrentForm;
727711
const { recurrenceRuleExpr } = this.scheduler.getDataAccessors().expr;
712+
728713
this.dxForm.updateData(
729714
recurrenceRuleExpr,
730-
this._recurrentForm.recurrenceRule.getRecurrenceString() ?? undefined,
715+
recurrenceRule.toString() ?? undefined,
731716
);
732-
733-
// const repeatEditor = this.dxForm.getEditor(EDITOR_NAMES.repeat);
734-
735-
// if (repeatEditor) {
736-
// const { freq } = this._recurrenceRule.getRules();
737-
738-
// if (freq) {
739-
// const freqValue = freq.toLowerCase();
740-
// repeatEditor.option('value', freqValue);
741-
742-
// const buttons = this.getRepeatEditorButtons();
743-
// repeatEditor.option('buttons', buttons);
744-
// } else {
745-
// repeatEditor.option('value', 'never');
746-
// repeatEditor.option('buttons', this.getRepeatEditorButtons());
747-
// }
748-
// }
749-
// } else if (!saveChanges) {
750-
// this._recurrentForm.tempRecurrenceRule = undefined;
717+
this.dxForm.getEditor(EDITOR_NAMES.startDate)?.option('value', recurrenceRule.startDate);
751718
}
752719
}
753720

@@ -773,9 +740,9 @@ export class AppointmentForm {
773740
if (this.recurrenceRuleRaw === null) {
774741
repeatEditor.option('value', repeatNeverValue);
775742
} else {
776-
const recurrenceRule = new RecurrenceRule(this.recurrenceRuleRaw);
777-
const freq = recurrenceRule.getRule('freq');
778-
const value = freq ? (freq as string).toLowerCase() : repeatNeverValue;
743+
const recurrenceRule = new RecurrenceRule(this.recurrenceRuleRaw, this.startDate);
744+
const { frequency } = recurrenceRule;
745+
const value = frequency ?? repeatNeverValue;
779746

780747
repeatEditor.option('value', value);
781748
}

packages/devextreme/js/__internal/scheduler/appointment_popup/m_popup.ts

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Deferred, when } from '@js/core/utils/deferred';
77
import { getWidth } from '@js/core/utils/size';
88
import { getWindow } from '@js/core/utils/window';
99
import type { ToolbarItem } from '@js/ui/popup';
10+
import type dxPopup from '@js/ui/popup';
1011
import Popup from '@js/ui/popup/ui.popup';
1112
import { current, isFluent } from '@js/ui/themes';
1213

@@ -28,19 +29,31 @@ export const ACTION_TO_APPOINTMENT = {
2829
EXCLUDE_FROM_SERIES: 2,
2930
};
3031

32+
/*
33+
TODO:
34+
- add test that check that firstDayOfWeek is correct after opening popup and then scheduler option change
35+
- add test that recurrence form does not show when popup is open for recurrence appointment
36+
*/
3137
export class AppointmentPopup {
3238
scheduler: any;
3339

3440
form: AppointmentForm;
3541

36-
popup: any;
42+
private _popup?: dxPopup;
3743

3844
state: any;
3945

40-
constructor(scheduler, form) {
46+
get popup(): dxPopup {
47+
return this._popup as dxPopup;
48+
}
49+
50+
get visible(): boolean {
51+
return Boolean(this._popup?.option('visible'));
52+
}
53+
54+
constructor(scheduler: any, form: AppointmentForm) {
4155
this.scheduler = scheduler;
4256
this.form = form;
43-
this.popup = null;
4457

4558
this.state = {
4659
action: null,
@@ -52,35 +65,33 @@ export class AppointmentPopup {
5265
};
5366
}
5467

55-
get visible() {
56-
return this.popup ? this.popup.option('visible') : false;
57-
}
58-
5968
show(appointment, config) {
6069
this.state.appointment.data = appointment;
6170
this.state.action = config.action;
6271
this.state.allowSaving = config.allowSaving;
6372
this.state.excludeInfo = config.excludeInfo;
6473

65-
if (!this.popup) {
74+
if (!this._popup) {
6675
const popupConfig = this._createPopupConfig();
67-
this.popup = this._createPopup(popupConfig);
76+
this._popup = this._createPopup(popupConfig);
6877
}
6978

7079
this.updateToolbarForMainGroup();
7180

72-
this.popup.show();
81+
this._popup.show();
7382
}
7483

7584
hide() {
76-
this.popup.hide();
85+
this._popup?.hide();
7786
}
7887

7988
dispose() {
80-
this.popup?.$element().remove();
89+
this.form.dispose();
90+
this._popup?.dispose();
91+
this._popup = undefined;
8192
}
8293

83-
_createPopup(options) {
94+
_createPopup(options): dxPopup {
8495
const popupElement = $('<div>')
8596
.addClass(APPOINTMENT_POPUP_CLASS)
8697
.appendTo(this.scheduler.getElement());
@@ -98,7 +109,6 @@ export class AppointmentPopup {
98109
enableBodyScroll: false,
99110
_ignorePreventScrollEventsDeprecation: true,
100111
onHiding: (): void => {
101-
this.form.reset();
102112
this.scheduler.focus();
103113
},
104114
contentTemplate: (): dxElementWrapper => {
@@ -190,13 +200,11 @@ export class AppointmentPopup {
190200
}
191201

192202
triggerResize(): void {
193-
if (this.popup) {
194-
triggerResizeEvent(this.popup.$element());
195-
}
203+
triggerResizeEvent(this.popup.$element());
196204
}
197205

198206
updatePopupFullScreenMode(): void {
199-
if (this.form.dxForm && this.visible) {
207+
if (this.visible) {
200208
const isPopupFullScreenNeeded = () => {
201209
const window = getWindow();
202210
const width = window && getWidth(window);
@@ -299,7 +307,7 @@ export class AppointmentPopup {
299307
}
300308

301309
_showLoadPanel() {
302-
const container = this.popup.$overlayContent();
310+
const container = (this.popup as any).$overlayContent();
303311

304312
showLoading({
305313
container,

0 commit comments

Comments
 (0)